使用tcpdump监控http流量

使用tcpdump监控http流量,具体内容包括:http request,http response,http headers以及http message body.

监控本机http流量

tcpdump -A -s 0 'tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)'

监控指定源地址的http流量

tcpdump -A -s 0 'tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)'

监控本地至本地的http流量

tcpdump -A -s 0 'tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)' -i lo

仅监控http request

将上述执行语句中的'tcp port 80修改为tcp dst port 80即可。

捕获本地至本地的所有流量

tcpdump -i lo

上述代码均是监控80端口的http流量,如果需要监控指定端口,将80替换为指定端口即可实现相应功能。

原文地址:https://www.cnblogs.com/jason1990/p/11394757.html