抓包指北
抓包命令
tcpdump -i eth1 -vvv -w test.pcap# -i 指定网口# -vvv 在shell中显示抓到的包# -w 将抓到的包写入文件
-
指定主机名
tcpdump -i eth1 host www.baidu.com -
指定ip
tcpdump -i eth1 host 192.168.1.12 -
指定端口
tcpdump -i eth1 port 80 # 指定源端口 tcpdump -i eth1 src port 80 # 指定目的端口 tcpdump -i eth1 dst port 80 -
指定协议
# 对于传输层之上的协议需加port tcpdump -i eth1 port http -
指定icmp
# ping打包 ping -s 4800 ip # 抓取ping包 # 传输层及传输层之下的协议直接跟协议名 tcpdump -i eth1 icmp
合并包
Mergecap 从名字上 可以看出该命令的功能是合并多个报文为一个报文。
C:\Program Files\Wireshark>mergecap -hMergecap (Wireshark) 3.4.2 (v3.4.2-0-ga889cf1b1bf9)Merge two or more capture files into one.See https://www.wireshark.org for more information.Usage: mergecap [options] -w <outfile>|- <infile> [<infile> ...]Output: -a concatenate rather than merge files. default is to merge based on frame timestamps. -s <snaplen> truncate packets to <snaplen> bytes of data. -w <outfile>|- set the output filename to <outfile> or '-' for stdout. -F <capture type> set the output file type; default is pcapng. an empty "-F" option will list the file types. -I <IDB merge mode> set the merge mode for Interface Description Blocks; default is 'all'. an empty "-I" option will list the merge modes.Miscellaneous: -h display this help and exit. -v verbose output.
mergecap -v -a -F pcap -w test.pcapmergecap -v -a userip-1.pcap userip-2.pcap -F pcap -w merge_out.pcap -v参数表示打印每一片报文的编号,报文较多的话会打屏。 -a参数表示的是按照文件中顺序将报文进行合并,默认情况是按照时间戳的顺序进行合并。由于每一片报文头部都是由有时间戳信息的,不明白的可以查看这里。 -F表示文件的存储格式,例如pcap,pcapng等等。在-F后面参数为空的情况下,会列出该命令支持的所有文件格式,对照选择即可。 -w即文件输出的
合并一定比例的包
--------
使用python脚本构造固定比例的包,如1:1024等。
import osbase_file = "5gc.pcap"arp_file = "arp_request.pcap"ratio = 0dst_file = ""pwd = os.curdirfor num in range(2,20): ratio = pow(2,num) copy_file = "5gc_copy_" + str(num) + ".pcap" os.system('copy %s %s' % (base_file, copy_file)) dst_file = "5gc_" + str(ratio) + ".pcap" os.system("mergecap.exe -v -a %s %s -F pcap -w %s" % (base_file, copy_file, dst_file)) base_file = dst_file dst_arp_file = "5gc_arp_1_" + str(ratio) + ".pcap" os.system("mergecap.exe -v -a %s %s -F pcap -w %s" % (base_file, arp_file, dst_arp_file))
reference
=========
> 本文使用 [文章同步助手](https://juejin.cn/post/6940875049587097631) 同步