tcpreplay(常用的测试流量 播放工具)

时间:2022-07-26 19:47:29

类似的播放的性质,将已经录好的pcap或tcpdump包,按照自己的定制方法(如播放次数、播放速度、指定端口等信息)播放流量


下载链接地址(可以官网下载,这里提供自己的网盘):http://pan.baidu.com/s/1vb8Ts

                                                           操作说明文档PDF  :http://pan.baidu.com/s/1pBSZp


tcpreplay解析:

tcpreplay: Command line arguments required
tcpreplay (tcpreplay) - Replay network traffic stored in pcap files
USAGE:  tcpreplay [ -<flag> [<val>] | --<name>[{=| }<val>] ]... <pcap_file(s)>

   -q, --quiet                Quiet mode
   -T, --timer=str            Select packet timing mode: select, ioport, rdtsc, gtod, nano, abstime
       --sleep-accel=num      Reduce the amount of time to sleep by specified usec
       --rdtsc-clicks=num     Specify the RDTSC clicks/usec
   -v, --verbose              Print decoded packets via tcpdump to STDOUT
   -A, --decode=str           Arguments passed to tcpdump decoder
   -K, --enable-file-cache    Enable caching of packets to internal memory
       --preload-pcap         Preloads packets into RAM before sending
   -c, --cachefile=str        Split traffic via a tcpprep cache file
   -i, --intf1=str            Server/primary traffic output interface
   -I, --intf2=str            Client/secondary traffic output interface
       --listnics             List available network interfaces and exit
   -l, --loop=num             Loop through the capture file X times
       --pktlen               Override the snaplen and use the actual packet len
   -L, --limit=num            Limit the number of packets to send
   -x, --multiplier=str       Modify replay speed to a given multiple
   -p, --pps=num              Replay packets at a given packets/sec
   -M, --mbps=str             Replay packets at a given Mbps
   -t, --topspeed             Replay packets as fast as possible
   -o, --oneatatime           Replay one packet at a time for each user input
       --pps-multi=num        Number of packets to send for each time interval
   -P, --pid                  Print the PID of tcpreplay at startup
       --stats=num            Print statistics every X seconds
   -V, --version              Print version information
   -h, --less-help            Display less usage information and exit
   -H, --help                 Display usage information and exit
   -!, --more-help            Extended usage information passed thru pager
       --save-opts[=arg]      Save the option state to a config file
       --load-opts=str        Load options from a config file

Options are specified by doubled hyphens and their name
or by a single hyphen and the flag character.

tcpreplay is a tool for replaying network traffic from files saved with
tcpdump or other tools which write pcap(3) files.


一般使用步骤:

方法一:(摘自pdf文档)

                   需要指定cache、pcap位置,可以构造新的报文替换到里面的ip地址和mac地址使得播放出新数据包源地址为本机IP地址

     

                   测试第一步:预处理生成Cache,命令为

                              tcpprep -a client -i test.tcpdump -o test.cache

                              这条命令将PCAP文件分成客户端和服务端,默认为客户端。发送时packet将分别从客户端和服务端发出。

                   测试第二步:重写IP地址和MAC地址,命令为

                                tcprewrite -e 192.85.1.2:192.85.2.2 --enet-dmac=00:15:17:2b:ca:14,00:15:17:2b:ca:15 --enet-smac=00:10:f3:19:79:86,00:10:f3:19:79:87 -c test.cache -i test.tcpdump -o 1.pcap

                                   这条命令将eth0设为服务端接口,eth1设为客户端接口,重写了IP和MAC,可通过wireshark等工具打开1.pcap,查看修改是否成功。

                   测试第三步:重放packet,首先为了获取更高的发送速度,可以把文件放到/dev/shm目录下,最高速度有1倍左右的加速。重放命令为:

                                tcpreplay -i eth0 -I eth1 -l 1000 -t -c /dev/shm/test.cache /dev/shm/1.pcap                 

                      

方法二:(播放测试流量最常使用的方法)

            直接播放 可以解析的pcap报文,播放的源ip地址仍为录制的pcap文件中的源ip地址

                                  (下面的测试包使用snort数据包记录器模式,记录生成。也可以使用wireshark,sniffer等抓包工具捕获)

                         tcpreplay -i eth1 -l 1000 -t /root/snort.log.1381554309