当前位置:网站首页>技术分享 | 抓包分析 TCP 协议
技术分享 | 抓包分析 TCP 协议
2022-07-06 12:57:00 【Hogwarts_测试】
本文节选自霍格沃兹测试开发学社内部教材
TCP 协议是在传输层中,一种面向连接的、可靠的、基于字节流的传输层通信协议。
环境准备
对接口测试工具进行分类,可以如下几类:
- 网络嗅探工具:tcpdump,wireshark
- 代理工具:fiddler,charles,anyproxyburpsuite,mitmproxy
- 分析工具:curl,postman,chrome Devtool
抓包分析TCP协议
tcpdump
tcpdump 是一款将网络中传送的数据包的“头”完全截获下来提供分析的工具。它支持针对网络层、协议、主机、网络或端口的过滤,并提供 and、or、not 等逻辑语句去掉无用的信息。
让 tcpdump 时刻监听 443 端口,如果有异样就输入到 log 文件中
sudo tcpdump port 443 -v -w /tmp/tcp.log利用这条命令,会把得到的报告放到目录 /tmp/tcp.log 中。
常用参数 | 含义 |
|---|---|
port 443 | 监听 443 端口 |
-v | 输出更加详细的信息 |
-w | 把数据写到 log 中 |
wireshark
wireshark 也是一款网络嗅探工具,它除了拥有 tcpdump 功能,还有更多扩展功能,比如分析工具,但是在接口测试中,抓包过程往往都是在服务器进行,服务器一般不提供 UI 界面,所以 wireshark 无法在服务器工作,只能利用 tcpdump 抓包生成 log,然后将 log 导入 wireshark 使用,在有 UI 界面的客户端上进行分析。
抓包分析 TCP 协议
抓取一个 http 的 get 请求:
- 在百度上搜 mp3
http://www.baidu.com/s?wd=mp3 - 用 tcpdump 截获这个 get 请求,并生成 log
- 用 wireshark 打开 tcpdump 生成的 log
使用 wireshark 查看 log:
log 的前几段信息是三次握手。因为信道是不可靠的,在发送数据前,就必须确保信道稳定,而三次握手就像是下面这些操作:
- 第一次握手:建立连接时,客户端发送 syn 包(syn=j)到服务器,并进入 SYN_SENT 状态,等待服务器确认。
- 第二次握手:服务器收到 syn 包,必须确认客户的 SYN(ack=j+1),同时自己也发送一个 SYN 包(seq=k),即 SYN+ACK 包,此时服务器进入 SYN_RECV 状态;
- 第三次握手:客户端收到服务器的 SYN+ACK 包,向服务器发送确认包 ACK(ack=k+1),此包发送完毕,客户端和服务器进入 ESTABLISHED(TCP 连接成功)状态,完成三次握手。
经过三次握手,就可以进一步交流,就像下面这样:
结束交流时,也需要进行四次挥手:
- 第一次挥手:客户端向服务器端发送一个 FIN,请求关闭数据传输。
- 第二次挥手:服务器接收到客户端的 FIN,向客户端发送一个 ACK,其中 ack 的值等于 FIN+SEQ。
- 第三次挥手:服务器向客户端发送一个 FIN,告诉客户端应用程序关闭。
- 第四次挥手:客户端收到服务器端的 FIN,回复一个 ACK 给服务器端。其中 ack 的值等于 FIN+SEQ。
注意: 一个请求可能分为多个包,一个数据也是这样,于是在 wireshark 会看到很多包。
边栏推荐
- Aiko ai Frontier promotion (7.6)
- 【OpenCV 例程200篇】220.对图像进行马赛克处理
- Manifest of SAP ui5 framework json
- Laravel notes - add the function of locking accounts after 5 login failures in user-defined login (improve system security)
- R語言可視化兩個以上的分類(類別)變量之間的關系、使用vcd包中的Mosaic函數創建馬賽克圖( Mosaic plots)、分別可視化兩個、三個、四個分類變量的關系的馬賽克圖
- HMS core machine learning service creates a new "sound" state of simultaneous interpreting translation, and AI makes international exchanges smoother
- New database, multidimensional table platform inventory note, flowus, airtable, seatable, Vig table Vika, Feishu multidimensional table, heipayun, Zhixin information, YuQue
- [200 opencv routines] 220 Mosaic the image
- After working for 5 years, this experience is left when you reach P7. You have helped your friends get 10 offers
- [MySQL] trigger
猜你喜欢

2022菲尔兹奖揭晓!首位韩裔许埈珥上榜,四位80后得奖,乌克兰女数学家成史上唯二获奖女性

全网最全的知识库管理工具综合评测和推荐:FlowUs、Baklib、简道云、ONES Wiki 、PingCode、Seed、MeBox、亿方云、智米云、搜阅云、天翎
![[in depth learning] pytorch 1.12 was released, officially supporting Apple M1 chip GPU acceleration and repairing many bugs](/img/66/4d94ae24e99599891636013ed734c5.png)
[in depth learning] pytorch 1.12 was released, officially supporting Apple M1 chip GPU acceleration and repairing many bugs

KDD 2022 | realize unified conversational recommendation through knowledge enhanced prompt learning

SAP Fiori应用索引大全工具和 SAP Fiori Tools 的使用介绍

【OpenCV 例程200篇】220.对图像进行马赛克处理

966 minimum path sum

Aike AI frontier promotion (7.6)

15million employees are easy to manage, and the cloud native database gaussdb makes HR office more efficient

愛可可AI前沿推介(7.6)
随机推荐
@GetMapping、@PostMapping 和 @RequestMapping详细区别附实战代码(全)
##无yum源安装spug监控
R語言可視化兩個以上的分類(類別)變量之間的關系、使用vcd包中的Mosaic函數創建馬賽克圖( Mosaic plots)、分別可視化兩個、三個、四個分類變量的關系的馬賽克圖
Le langage r visualise les relations entre plus de deux variables de classification (catégories), crée des plots Mosaiques en utilisant la fonction Mosaic dans le paquet VCD, et visualise les relation
R language visualizes the relationship between more than two classification (category) variables, uses mosaic function in VCD package to create mosaic plots, and visualizes the relationship between tw
Thinking about agile development
[MySQL] trigger
Pat 1078 hashing (25 points) ⼆ times ⽅ exploration method
Forward maximum matching method
ICML 2022 | Flowformer: 任务通用的线性复杂度Transformer
Web开发小妙招:巧用ThreadLocal规避层层传值
Chris LATTNER, the father of llvm: why should we rebuild AI infrastructure software
El table table - sortable sorting & disordered sorting when decimal and% appear
Math symbols in lists
Pinduoduo lost the lawsuit, and the case of bargain price difference of 0.9% was sentenced; Wechat internal test, the same mobile phone number can register two account functions; 2022 fields Awards an
MLP (multilayer perceptron neural network) is a multilayer fully connected neural network model.
@PathVariable
In JS, string and array are converted to each other (I) -- the method of converting string into array
15million employees are easy to manage, and the cloud native database gaussdb makes HR office more efficient
Simple continuous viewing PTA