前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >shell五分钟系列第二节tcpdump

shell五分钟系列第二节tcpdump

作者头像
早起的鸟儿有虫吃
发布于 2023-03-28 01:11:28
发布于 2023-03-28 01:11:28
33900
代码可运行
举报
文章被收录于专栏:算法之美算法之美
运行总次数:0
代码可运行

第二节:tcpdump

1 来源一个真实的对话

2 tcpdump 就是证据

tcpdump - dump traffic on a network

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
tcpdump -i eth0 '(tcp port 80)' -v  -w dump.pcap 
//(服务器nginx 80端口 模拟一次请求)

sz dump.pcap //下载

请在

https://github.com/wangcy6/shell_five_minute/tree/master/03_tcpdump下载pcap文件

Wireshark 查看

网络层负责ip数据报的产生以及ip数据包在逻辑网络上的路由转发( 选择哪个路径) 传输层提供端到端通信服务层次,提供可靠及非可靠连接(保证路径上传输可靠 tcp

  • TCP序列号(Sequence Number)和确认号(Acknowledgment Number)

TCP之所以可靠,是因为它保证了传送数据包的顺序 Next sequence number:=Sequence number+len(data) Sequence number=Next sequence number Acknowledgment number: Sequence number

为了更好的理解在整个TCP会话期间,TCP序列号和确认号是如何工作的,我们可以使用Wireshark内置的绘制流功能,选择菜单栏中的 Statistics ->Flow Graph…->TCP flow ->OK

  • 这个是老版本的(Wireshark 1.2.7 新版本不是这个图片)

3 细节是魔鬼

understanding-tcp-sequence-acknowledgment-numbers

在TCP通讯中主要有连接的建立、数据的传输、连接的关闭三个过程!

每个过程完成不同的工作,而且序列号和确认号在每个过程中的变化都是不同的。

数据传输

看序列号完整行

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Packet #4
This is the first packet in the stream which carries an actual payload (specifically, the client's HTTP request). The sequence number is left at 1, since no data has been transmitted since the last packet in this stream. The acknowledgement number is also left at 1, since no data has been received from the server, either.Note that this packet's payload is 725 bytes in length.Packet #5
This packet is sent by the server solely to acknowledge the data sent by the client in packet #4 while upper layers process the HTTP request. Notice that the acknowledgement number has increased by 725 (the length of the payload in packet #4) to 726; e.g., "I have received 726 bytes so far." The server's sequence number remains at 1.Packet #6
This packet marks the beginning of the server's HTTP response. Its sequence number is still 1, since none of its packets prior to this one have carried a payload. This packet carries a payload of 1448 bytes.Packet #7
The sequence number of the client has been increased to 726 because of the last packet it sent. Having received 1448 bytes of data from the server, the client increases its acknowledgement number from 1 to 1449.For the majority of the capture, we will see this cycle repeat. The client's sequence number will remain steady at 726, because it has no data to transmit beyond the initial 725 byte request. The server's sequence number, in contrast, continues to grow as it sends more segments of the HTTP response.

连接

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Packet #1
Each side of a TCP session starts out with a (relative) sequence number of zero. Likewise, the acknowledgement number is also zero, as there is not yet a complementary side of the conversation to acknowledge.(Note: The version of Wireshark used for this demonstration, 1.2.7, shows the acknowledgement number as an apparently random number. This believed to be a software bug; the initial acknowledgement number of a session should always be zero, as you can see from inspecting the hex dump of the packet.)Packet #2
The server responds to the client with a sequence number of zero, as this is its first packet in this TCP session, and a relative acknowledgement number of 1. The acknowledgement number is set to 1 to indicate the receipt of the client's SYN flag in packet #1.Notice that the acknowledgement number has been increased by 1 although no payload data has yet been sent by the client. This is because the presence of the SYN or FIN flag in a received packet triggers an increase of 1 in the sequence. (This does not interfere with the accounting of payload data, because packets with the SYN or FIN flag set do not carry a payload.)Packet #3
Like in packet #2, the client responds to the server's sequence number of zero with an acknowledgement number of 1. The client includes its own sequence number of 1 (incremented from zero because of the SYN).At this point, the sequence number for both hosts is 1. This initial increment of 1 on both hosts' sequence numbers occurs during the establishment of all TCP sessions.

三次握手 syn数据长度为1

释放

四次握手 fin数据长度为1

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Packet #38
After acknowledging the last segment of data from the server, the client processes the HTTP response as a whole and decides no further communication is needed. Packet #38 is sent by the client with the FIN flag set. Its acknowledgement number remains the same as in the prior packet (#37).Packet #39
The server acknowledges the client's desire to terminate the connection by increasing the acknowledgement number by one (similar to what was done in packet #2 to acknowledge the SYN flag) and setting the FIN flag as well.Packet #40
The client sends its final sequence number of 727, and acknowledges the server's FIN packet by incrementing the acknowledgement number by 1 to 22952.

参考

  1. https://danielmiessler.com/study/tcpdump/
  2. Understanding TCP Sequence and Acknowledgment Numberss 【最原始的例子,其他都是翻译该文章】
  3. https://www.youtube.com/watch?v=AX2D_n1yZko
  4. How TCP Works - The Handshake https://www.youtube.com/watch?v=HCHFX5O1IaQ
  5. https://blog.csdn.net/a19881029/article/details/38091243
  6. https://ask.wireshark.org/question/3498/what-is-the-difference-between-tcp-payload-and-tcp-segment-data/?answer=3512#post-id-3512
  7. https://blog.csdn.net/donghanhang/article/details/51222309【中文翻译】
  8. https://blog.csdn.net/doitsjz/article/details/73457447 关于抓包出现TCP DUP ACK问题
  9. http://blog.51cto.com/lihongweibj/1690518 关于wireshark抓包的那点事儿

目前的理解:

Next sequence number:=Sequence number+len(data) 保证数据顺序传输,并且没有丢失

小白提问:

tcp不是请求不是1:1的吗?怎么会持续连续发送的情况?

4 扩展阅读

strace - trace system calls and signals
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
strace -o output.txt -T -tt -e trace=all -p 6107(nginx)
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
[10:16:34.228468 -tt 在输出中的每一行前加上时间信息,微秒级]
[writev(3, [{"HTTP/1.1 304 Not Modified\r\nServe"..., 180}], 1) = 180 -e trace=all
只跟踪指定的系统 调用.例如:-e trace=open,close,rean,write表示只跟踪这四个系统调用.
默认的为set=all.
-e trace=file
只跟踪有关文件操作的系统调用.
-e trace=process
只跟踪有关进程控制的系统调用.
-e trace=network
跟踪与网络有关的所有系统调用.
-e strace=signal
跟踪所有与系统信号有关的 系统调用]  
[ <0.000041> -T 显示每一调用所耗的时间. ]
Fiddler

【未完待续】

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2019-01-09,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 Offer多多 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
备份同步神器 Rclone 使用教程
Rclone 是一个命令行程序,用于管理云存储上的文件。它是云供应商的网络存储接口的一个功能丰富的替代品。超过 40 种云存储产品支持 rclone,包括 S3 对象存储、企业和消费者文件存储服务以及标准传输协议。
Lcry
2022/12/13
25K0
5分钟教你轻松搭建FastDFS分布式文件系统
操作系统:Ubuntu 16.04 前提:开启root权限;如果没有,则在操作的时候需要使用sudo去获取一些执行权限。 版本(保证匹配): (1)libfastcommon 1.0.50,是基础库(网络封装、线程封装等)。 (2)fastdfs 6.0.7,包含tracker、storage、client等的实现。
Lion 莱恩呀
2024/12/23
1970
5分钟教你轻松搭建FastDFS分布式文件系统
使用Picgo并魔改Picgo-plugin-rclone插件实现OneDrive(Sharepoint)+OneManager图床功能
之后使用了B站图床 到最后还是想到了老办法 Microsoft E5套餐里面免费大碗的Onedrive(当然也可以用Sharepoint)
Wlog
2022/12/05
2K0
使用Picgo并魔改Picgo-plugin-rclone插件实现OneDrive(Sharepoint)+OneManager图床功能
Rclone中文文档
rclone是一个命令行程序,用于同步文件和目录,并支持网盘同步,可同步网盘包括如下:
Erwin
2020/12/22
21.2K1
初试 Ceph 存储之块设备、文件系统、对象存储
哎_小羊
2018/01/02
6.6K0
初试 Ceph 存储之块设备、文件系统、对象存储
使用rclone挂载onedrive扩容服务器空间
在 rclone 官网https://rclone.org/downloads/下载适用于 Windows 的最新版客户端,解压到磁盘当中,将文件夹重命名为rc(方便以下操作。。)。按住键盘上win+R输入powershell打开命令行,执行以下命令。
用户1316967
2022/01/18
9.9K0
混沌工具之ChaosMesh编译安装
在k8s里面安装ChaosMesh比较简单,请参考《混沌工程之ChaosMesh使用之一模拟CPU使用率》。
高楼Zee
2021/07/14
6950
使用rclone迁移FTP数据到COS
与ftp配置一样,同样可以通过rclone config来配置cos,但我们也可以通过直接修改配置文件的方式来配置cos:
ictfox
2019/10/31
2.5K0
Django实战-番外篇-FastDFS文件存储
FastDFS 是一个轻量级的开源分布式文件系统;FastDFS 主要解决了大容量的文件存储和高并发访问的问题,文件存取时实现均衡负载;FastDFS 实现了软件方式的 RAID,可以使用廉价的 IDE 硬盘进行存储;支持存储服务器在线扩容;支持相同内容的文件只保存一份,节约磁盘空间;FastDFS 特别适合大中型网站使用,用来存储资源文件(如:图片、文档、音频、视频等等);FastDFS 是一个开源的轻量级分布式文件系统,由跟踪服务器、存储服务器和客户端三个部分组成,主要解决了海量数据存储问题,特别适合以中小文件(建议范围:4KB < file_size < 500MB)为载体的在线服务。
小团子
2019/07/18
1.3K0
Django实战-番外篇-FastDFS文件存储
rclone,云存储备份和迁移的瑞士军刀,千字常文解析,附下载链接和安装操作步骤
rclone是一个命令行程序,全称:rsync for cloud storage。是用于将文件和目录同步到云存储提供商的工具。因其支持多种云存储服务的备份,如Google Drive、Amazon S3、Dropbox、Backblaze B2、One Drive、Swift、Wasabi、Google Cloud Storage、Azure Blob、Azure Files、NAS、对象存储(OOS/S3)等,所以常常称rclone为云存储备份的瑞士军刀。因其备份的特性,现在很多迁移厂商也用其来做存储数据迁移的场景。
ICT系统集成阿祥
2025/01/13
1.3K0
rclone,云存储备份和迁移的瑞士军刀,千字常文解析,附下载链接和安装操作步骤
POSIX 真的不适合对象存储吗?
最近,留意到 MinIO 官方博客的一篇题为“在对象存储上实现 POSIX 访问接口是坏主意”的文章,作者以 S3FS-FUSE 为例分享了通过 POSIX 方式访问 MinIO 中的数据时碰到了性能方面的困难,性能远不如直接访问 MinIO。在对结果进行分析时,作者认为是 POSIX 本身存在的缺陷导致的性能问题。这个结论与我们既有经验有一定出入。
Juicedata
2023/10/26
5460
POSIX 真的不适合对象存储吗?
长安“战疫”2022 部分WriteUp (第四名)
本次比赛取得第四名!拿到一个一血,密码方向由NonupleBroken全部解出,2022年首战告捷!
Timeline Sec
2022/02/11
1.2K0
长安“战疫”2022 部分WriteUp (第四名)
ceph-对象存储
作为文件系统的磁盘,操作系统不能直接访问对象存储。相反,它只能通过应用程序级别的API访问。ceph是一种分布式对象存储系统,通过ceph对象网关提供对象存储接口,也称为RADOS网关(RGW)接口,它构建在ceph RADOS层之上。RGW使用librgw(RADOS Gateway library)和librados,允许应用程序与ceph对象存储建立连接。RGW为应用程序提供了一个RESTful S3/swift兼容的接口,用于在ceph集群中以对象的形式存储数据。ceph还支持多租户对象存储,可以通过RESTful API访问。此外,RGW还支持ceph管理API,可以使用本机API调用来管理ceph存储集群。
yuezhimi
2020/09/30
4K0
对象存储,了解一下
对象存储,通常指 S3 (Simple Storage Service) 服务,由AWS提供公有云服务,而 Ceph 也可以提供兼容 S3 协议的对象存储服务,使用起来跟 AWS 的 S3 体验几乎一样。 环境介绍 访问域名: tstack-s3.oa.com 后端物理环境: [ 64G/8Core/11TB*4/10GE*2 ] * 5台 Ceph 版本: Jewel 10.2.7 RGW 网关: 1个/台,共5个,HAProxy+KeepAlived 实现负载均衡。 测试秘钥: access_k
腾讯云TStack
2018/10/12
4K0
对象存储,了解一下
数据备份到对象存储(cos)
之前我,写过利用bypy+crontab 实现定时数据备份到百度网盘, ,大家也知道百度网盘的一个缺点就是下载速度太慢,当然如果你是会员就当我没说,下面给你们介绍如何把数据备份到腾讯的cos中,腾讯的数据存储新用户会有6个月的50G标准存储容量。 环境:Java和腾讯云的迁移工具
云计算小黑
2022/12/28
2K0
数据备份到对象存储(cos)
006.Ceph对象存储基础使用
Ceph 对象网关是一个构建在 librados 之上的对象存储接口,它为应用程序访问Ceph 存储集群提供了一个 RESTful 风格的网关 。
木二
2019/07/01
2.2K0
centos服务器安装rclone自动挂载无限容量谷歌相册Google photo为磁盘
经常听说有人撸到无限容量的谷歌网络硬盘,或者是 5T 容量的,都是利用学生认证实现的,现在淘宝上也有一大堆,但是感觉这种都不一定稳,随时可能翻车,我自己是用的 google drive 个人版的免费 15G 空间,其实也够用了,可以挂载到服务器上,当一个普通的本地磁盘样操作,多 15G 随便放点什么都好,还稳定,不怕翻车,挂载主要通过 RCLONE 这个软件实现,需要服务器或者至少 KVM 架构的 VPS,因为需要用到 FUSE,而一般 OPENVZ 架构是不开启这个功能的,教程如下:
王图思睿
2021/06/15
3.3K0
rclone挂载Google Drive
元旦在土区成功购买Google one 2T之后,就着手开始用rclone挂载Google Drive
行 者
2023/10/20
9710
Kubernetes 集群基于 Rook 的 Ceph 存储之块设备、文件系统、对象存储
要使用基于 Rook 的 Ceph 存储中的块设备、文件系统以及对象存储,必须保证已通过 Rook 完成 Ceph 存储集群的搭建,并且保证 Ceph 存储集群处于 active + clean 状态。这里搭建过程可以参考上一篇 Kubernetes 集群基于 Rook 搭建 Ceph 分布式存储系统 文章,讲解的很详细。Kubernetes 集群搭建亦可参照上一篇文章,版本为 1.12.1,这里均忽略搭建过程,下边通过示例分别演示下如何使用这块设备、文件系统、对象存储方案。
哎_小羊
2019/05/25
4.8K1
云原生 | 从零开始,Minio 高性能分布式对象存储快速入手指南
描述: 对象存储(Object Storage)是一种存储数据的计算机体系结构,它以对象的形式存储和管理数据。与传统的文件系统和块存储不同,对象存储将数据作为对象存储在分布式的存储集群中,每个对象都有一个唯一的标识符(通常是一个URL),并且可以通过这个标识符来访问和检索数据。
全栈工程师修炼指南
2023/10/31
9.3K1
云原生 | 从零开始,Minio 高性能分布式对象存储快速入手指南
推荐阅读
相关推荐
备份同步神器 Rclone 使用教程
更多 >
LV.0
这个人很懒,什么都没有留下~
目录
  • 第二节:tcpdump
    • 1 来源一个真实的对话
    • 3 细节是魔鬼
    • understanding-tcp-sequence-acknowledgment-numbers
      • 小白提问:
      • tcp不是请求不是1:1的吗?怎么会持续连续发送的情况?
    • 4 扩展阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档