首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >shell五分钟系列第二节tcpdump

shell五分钟系列第二节tcpdump

作者头像
早起的鸟儿有虫吃
发布于 2023-03-28 01:11:28
发布于 2023-03-28 01:11:28
36500
代码可运行
举报
文章被收录于专栏:算法之美算法之美
运行总次数: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 删除。

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

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
tcpdump / wireshark 抓包及分析
本文将展示如何使用 tcpdump 抓包,以及如何用 tcpdump 和 wireshark 分析网络流量。文中的例子比较简单,适合作为入门参考。
杰哥的IT之旅
2020/06/18
2.5K0
tcpdump / wireshark 抓包及分析
tcp protocol
11:53:56.748105 IP 40.100.29.194.https > 10.79.98.55.62947: Flags P., seq 5758:5814, ack 6948, win 2052, length 56
用户8418197
2021/06/13
7760
理解TCP序列号Seq和确认号Ack
在我们开始之前,确保在Wireshark中打开示例(请到作者原文中下载)并亲自实践一下
曲水流觞
2020/07/15
3.6K0
理解TCP序列号Seq和确认号Ack
TCP三次握手四次分手抓包理解
TCP建立连接需要三次握手,分手需要四次握手,平时在网上看到很多次,但是还没有很理解。为什么分手要多一次?可能是刚开始追求女生的时候比较容易,到分手的时候就比较麻烦了吧。。。了解某个东西要从它的基础开始,我们先看看TCP的报文是怎么回事。
zhanyd
2022/05/16
3740
TCP三次握手四次分手抓包理解
how to use tcpdump
Tcpdump command is a famous network packet analyzing tool that is used to display TCP IP & other network packets being transmitted over the network attached to the system on which tcpdump has been installed. Tcpdump uses libpcap library to capture the network packets & is available on almost all Linux/Unix flavors.
用户8418197
2021/03/20
1.4K0
TCP的三次握手与四次分手
TCP的位置 TCP工作在网络OSI的七层模型中的第四层——Transport层,IP在第三层——Network层,ARP在第二层——Data Link层; 在第二层上的数据,我们把它叫Frame,在
老七Linux
2018/05/31
7710
tcpdump命令使用简介
tcpdump 是一款强大的网络抓包工具,运行在 linux 平台上。熟悉 tcpdump 的使用能够帮助你分析、调试网络数据。
吴易娃
2024/01/12
6900
tcpdump简明教程
本文将会持续修正和更新,最新内容请参考我的 GITHUB 上的 程序猿成长计划 项目,欢迎 Star,更多精彩内容请 follow me。
用户2131907
2019/02/27
2.1K0
TCP Flags
TCP flags are various types of flag bits present in the TCP header. Each of them has its own significance. They initiate connections, carry data, and tear down connections. The commonly used TCP flags are syn, ack, rst, fin, urg, psh.
用户8418197
2021/04/07
7300
Python-对Pcap文件进行处理,获
        通过对TCP/IP协议的学习,本人写了一个可以实现对PCAP文件中的IPV4下的TCP流提取,以及提取指定的TCP流,鉴于为了学习,没有采用第三方包解析pcap,而是对bytes流进行解析,其核心思想为:若想要提取TCP Content,需在下层的IPV4协议中判断Protocol是否为TCP,然后判断下层的以太网协议的Type是否为IPV4协议(此处的IPV4判断,只针对本人所写项目);对于指定流需要获取Client以及Server的[IP,PORT]。
py3study
2020/01/19
4.2K0
Python-对Pcap文件进行处理,获
http 1.0和1.1 究竟有什么区别呢?一次性能压测引发的深究
loadrunner几尽为国内测试人员的专用压测工具,他的高度灵活性,数据分析功能,图表展示,用户行为模拟等功能非常强大,专业压测还是以loadrunner为准
运维部落
2020/04/08
1.7K0
http 1.0和1.1 究竟有什么区别呢?一次性能压测引发的深究
TCP三次握手与四次分手傻傻分不清?看大神图解五分钟讲明白
引言 TCP三次握手和四次挥手不管是在开发还是面试中都是一个非常重要的知识点,它是我们优化web程序性能的基础。但是大部分教材都对这部分解释的比较抽象,本文我们就利用wireshark来抓包以真正体会整个流程的细节。 三次握手 根据下面这幅图我们来看一下TCP三次握手。p.s: 每个箭头代表一次握手。 tcp三次握手 第一次握手 client发送一个SYN(J)包给server,然后等待server的ACK回复,进入SYN-SENT状态。p.s: SYN为synchronize的缩写,ACK为ac
小小科
2018/05/02
1.4K0
TCP三次握手与四次分手傻傻分不清?看大神图解五分钟讲明白
TCP协议学习笔记、报文分析
TCP(Transmission Control Protocol传输控制协议)协议是基于IP协议,面向连接的、可靠的、基于字节流的传输层通信协议。
DannyHoo
2021/12/06
1.7K0
TCP协议学习笔记、报文分析
TCP细节分析
昨天阅读一篇讲tcpdump使用技巧的文章,里面简单提到了TCP握手挥手的流程,还附了一片图片。 tcp_state_machine.jpg 虽然TCP握手挥手大学里学到,但很惭愧竟忘得差不多了。今天
jeremyxu
2018/05/10
1K0
linux抓包命令到文件,Linux下抓包命令tcpdump详解「建议收藏」
tcpdump是一个命令行实用程序,可用于捕获和检查进出系统的网络流量。 它是网络管理员中用于排除网络问题和安全测试的最常用工具。
全栈程序员站长
2022/09/24
7.3K0
linux抓包命令到文件,Linux下抓包命令tcpdump详解「建议收藏」
抓包神器TCPDUMP的分析总结-涵盖各大使用场景、高级用法
网络故障排查中,经常要抓包,windows有wireshark,linux最常用的是tcpdump,其中被问得最多的一个问题:"iptables限制后,tcpdump还能抓到包吗?",首先看下数据包进入OS及出去的顺序:
RokasYang
2021/08/10
13.3K1
抓包神器TCPDUMP的分析总结-涵盖各大使用场景、高级用法
Stanford CS144 Lab2.TCP Reciever
在实践中,一个分组的序号承载在分组首部的一个固定长度的字段中。如果分组序号字段的比特数是k,则该序号范围是[0,2^k]。 在一个有限的序号范围内,所有涉及序号的运算必须使用模2^k运算。(即序号空间可被看作是一个长度为2^k 的环,其中序号2^k-1紧挨着0)。上面论述的序号是相对序号(相对序号的开始值是isn),还有一种不模2^k的运算就是绝对序号.
用户7267083
2022/12/08
3150
Stanford CS144 Lab2.TCP Reciever
代码实现TCP三次握手:程序实现
本节我们通过代码来实现TCP协议连接时的三次握手过程。首先我们需要再次重温一下TCP数据包的相关结构:
望月从良
2019/08/20
1K0
代码实现TCP三次握手:程序实现
tcpdump命令讲解
老高的建议:把流量比作水源,工具tcpdump就是一个过滤器,能够过滤出我们需要的纯净水,而水源有很多技术特征能够为我所用。
老高的技术博客
2022/12/28
7730
tcpdump命令讲解
Stanford CS144 Lab
在实验资料中给出的是这么一段话,这句话的意思就是所有的应用层协议都是由底层支撑的,这个底层可以理解成可靠的二进制比特流的传输,一方应用程序会产生比特流投入到传输通道中,另一方的应用程序会从传输通道中获取到比特流信息.这个传输通道就是Socket,套接字.
用户7267083
2023/03/20
8160
Stanford CS144 Lab
相关推荐
tcpdump / wireshark 抓包及分析
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档