今天突然说要转一个补丁版本,将get请求改成post请求,紧急上线,要半小时搞定。
所以,需要验证3个点:
虽然身为一个后端测开,但是我也是个小白牙,不怕笑话,我就没用过命令行tcpdump去抓包。
开始google之旅,分三个阶段哈:
问题定位:抓取tcp请求,可以定位两个服务器之间到底有没有成功建立连接哦
示例:
tcp抓包 :端口和网卡根据实际情况配置 (容器,idc机器都可以用)
tcpdump -i eth0 tcp and port 13011 -vvvv
显示结果包含 源IP:端口和目标IP:端口
问题定位:抓取tcp请求,可以看到请求包含的详细信息
示例:
tcp抓包 :端口和网卡根据实际情况配置 (容器,idc机器都可以用) -X是展示详细数据
tcpdump -i eth0 tcp and port 13011 -vvvv -X
捕捉接收到的http请求并展示post的请求方式和body
示例:
tcpdump -s 0 -i eth1 -A 'tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x504F5354'
注: eth1 是网卡(根据实际情况选择)
仅仅捕捉指定端口443接收到的http post请求
示例:
tcpdump -i enp0s8 -s 0 -A 'tcp dst port 443 and tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x504F5354'
tcpdump抓包工具 仅捕捉指定端口80/443接收到的指定来源192.168.10.1的http get/post 请求
示例:
tcpdump -i enp0s8 -s 0 -A 'tcp dst port 80 or tcp dst port 443 and tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x47455420 or tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x504F5354' and host 192.168.10.1
捕捉接收到的所有http get请求
示例:
tcpdump -i enp0s8 -s 0 -A 'tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x47455420'
仅仅捕捉指定端口443接收到的http get请求
示例:
tcpdump -i enp0s8 -s 0 -A 'tcp dst port 80 and tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x47455420'
仅捕捉接收到的所有http get或post请求的url
示例:
tcpdump -i enp0s8 -s 0 -v -n -l | egrep -i "POST /|GET /|Host:"
仅捕捉接收到的所有http get或post请求的里的密码
示例:
tcpdump -i enp0s8 -s 0 -A -n -l | egrep -i "POST /|pwd=|passwd=|password=|Host:"
捕捉接收到的指定端口的完整http 请求数据(get&post)
示例:
tcpdump -i enp0s8 -s 0 -A 'tcp dst port 18001 and tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x47455420 or tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x504F5354 or tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x48545450 or tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x3C21444F and host 192.168.60.1'
示例如下:
Request from 192.168.60.1 using curl -v
aksarav@middlewareinventory:~$ curl -v "-H X-Forwarded-By: middlewareinventory" -X POST http://192.168.60.4:18001/TestWebService/
* Trying 192.168.60.4...
* TCP_NODELAY set
* Connected to 192.168.60.4 (192.168.60.4) port 18001 (#0)
> POST /TestWebService/ HTTP/1.1
> Host: 192.168.60.4:18001
> User-Agent: curl/7.54.0
> Accept: */*
> X-Forwarded-By: middlewareinventory
>
< HTTP/1.1 200 OK
< Date: Sat, 28 Jul 2018 06:21:42 GMT
< Accept-Ranges: bytes
< Content-Length: 475
< Content-Type: text/html
< Last-Modified: Sat, 28 Jul 2018 15:41:10 GMT
<
Sample WebService Application
This is Sample WebService Application
* Connection #0 to host 192.168.60.4 left intact
Response:
[root@mwiapp01 ~]# tcpdump -i enp0s8 -s 0 -A 'tcp dst port 18001 and tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x47455420 or tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x504F5354 or tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x48545450 or tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x3C21444F and host 192.168.60.1'
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on enp0s8, link-type EN10MB (Ethernet), capture size 65535 bytes
02:49:12.424425 IP 192.168.60.1.60442 > mwiapp01.18001: Flags [P.], seq 558796881:558797017, ack 3750122298, win 4117, options [nop,nop,TS val 317440918 ecr 4685369], length 136
E...Z.@.@.....<...<...FQ!N.Q..S:...........
.....G~9POST /TestWebService/ HTTP/1.1
Host: 192.168.60.4:18001
User-Agent: curl/7.54.0
Accept: */*
X-Forwarded-By: middlewareinventory
02:49:12.426378 IP mwiapp01.18001 > 192.168.60.1.60442: Flags [P.], seq 1:171, ack 136, win 235, options [nop,nop,TS val 4685370 ecr 317440918], length 170
E...-.@.@.....<...<.FQ....S:!N.......&.....
.G~:....HTTP/1.1 200 OK
Date: Sun, 29 Jul 2018 06:49:12 GMT
Accept-Ranges: bytes
Content-Length: 475
Content-Type: text/html
Last-Modified: Sat, 28 Jul 2018 15:41:10 GMT
02:49:12.426683 IP mwiapp01.18001 > 192.168.60.1.60442: Flags [P.], seq 171:646, ack 136, win 235, options [nop,nop,TS val 4685371 ecr 317440920], length 475
E...-.@.@.....<...<.FQ....S.!N.......W.....
.G~;....
Sample WebService Application
This is Sample WebService Application