文档库 最新最全的文档下载
当前位置:文档库 › tcpreplay使用手册

tcpreplay使用手册

tcpreplay使用手册
tcpreplay使用手册

Tcpreplay的使用手册(结合实例)

一.简介

Tcpreplay是一系列工具的总称,包括tcpreplay、tcprewrite和tcpprep等工具,这也是Tcpreplay的第一个字母大写的原因。它用来在Unix系统或类Unix系统上重放网络包。这些包是由tcpdump、ethereal和wireshark等软件抓取到的,即pcap格式的数据包。

正因为Tcpreplay有重放数据包的功能,所以它常被用来模拟IDS攻击等测试环境,被广泛地用来测试防火墙和IDS工具的安全性。

二.安装方法

1.文件下载

官方网站下载https://www.wendangku.net/doc/383715056.html,/tcpreplay/tcpreplay-3.3.2.tar.gz?download

2.安装

解压文件.[Nsos5 work]# tar -xf tcpreplay-3.3.2.tar.gz

进入文件夹.[Nsos5 work]# cd tcpreplay-3.3.2

依次键入:./congfigure

make

make install

安装完成后便会多出三个工具,可以依次健入:tcpreplay –V

tcpprep –V

tcprewrite -V

查看相关版本信息.

三.工具集介绍

1.tcpprep

tcpprep用于将pcap数据包分解为客户端和服务器端.

Tcpprep所支持的模式:

?Auto/Bridge

?Auto/Router

?Auto/Client

?Auto/Server

?IPv4 matching CIDR

?IPv4 matching Regex

?TCP/UDP Port

?MAC address

在auto/bridge模式下,tcpprep根据clinet和server的行为分析数据包.

client行为如下定义:

?发送一个TCP Syn 包到另外一台主机

?发送一个DNS 请求

?收到一个ICMP 端口不可达

Server行为如下定义:

?发送一个TCP Syn/Ack 包到另外一台主机

?发送一个DNS 应答

?发关一个ICMP 端口不可达

例: tcpprep --auto=bridge --pcap=input.pcap --cachefile=input.cache

如果数据包中有任何一个包无法分类.tcpprep将报错.在分类完后,服务器端到客户端的数据包率将被设置为此数据包的数据率,客户端到服务器端的数据率将会是它的两倍.不然.你也可以用ratio参数修改它.ratio对每一种模式都是有效的.例如:

tcpprep --auto=bridge --pcap=input.pcap --cachefile=input.cache --ratio=3.5

在auto/router模式下,首先是按auto/bridger模式的方法标记出client和server.对于存在那些未标记的主机.通过分析其与其它主机的数据包,将其划分到相同的子网,并标记为与其子网内其它主机相同的标记.例:

tcpprep --auto=router --pcap=input.pcap --cachefile=input.cache

在auto/client模式下,其分类标准与auto/birdge相同,只不过对于那些被标记为client的IP.其只对ip 的第一个行为做判断,而不是每一次都做判断.例:

tcpprep --auto=client --pcap=input.pcap --cachefile=input.cache

auto/server与auto/client相似.不同在于它是对被标记为server的ip做处理.

在Cidr模式下.用户手动给出server所在的网段.而不像在auto模式下由tcpprep来区分.例: Tcpprep --cidr=10.0.0.0/8,172.16.0.0/12 --pcap=input.pcap

--cachefile=input.cache

在Regex模式下.用户给出能匹配server的正则表达式.例:

tcpprep --regex="(10|20)\..*" --pcap=input.pcap --cachefile=input.cache

在port模式下,用端口号来区分server 和client.默认情况下,0—1024端口为server端所有.1024以外为client所有.当然.你也可以在自己/etc/services中划分服务器端口. tcpprep --port --services=/etc/services --pcap=input.pcap --cachefile=input.cache 在mac模式下.由用户指定那些mac为服务端mac.例:

Tcpprep --mac=00:21:00:55:23:AF,00:45:90:E0:CF:A2 --pcap=input.pcap --cachefile=input.cache

参数include的使用:

在include下.可以指定所要处理的数据包.

Tcpprep --auto=bridge --include=S:10.0.0.0/8,192.168.0.0/16 --pcap=input.pcap --cachefile=input.cache

//只处理源IP在10.0.0.0/8,192.168.0.0/16网段的数据包

tcpprep --include=D:10.0.0.0/8,192.168.0.0/16 --pcap=input.pcap

--cachefile=input.cache

//只处理目的IP在10.0.0.0/8,192.168.0.0/16网段的数据包.

Tcpprep --auto=bridge --include=B:10.0.0.0/8,192.168.0.0/16 --pcap=input.pcap --cachefile=input.cache

//只处理目的IP和源IP都在10.0.0.0/8,192.168.0.0/16网段的数据包.

Tcpprep --auto=bridge --include=E:10.0.0.0/8,192.168.0.0/16 --pcap=input.pcap --cachefile=input.cache

//处理只要源IP或者目的IP在10.0.0.0/8,192.168.0.0/16网段的数据包.

Tcpprep --auto=bridge --include=P:1-5,9,15,72- --pcap=input.pcap --cachefile=input.cache

//处理指定编号1到5,9,15,72到结尾处的这些数据包.

Tcpprep --auto=bridge --include=F:"tcp port 22" --pcap=input.pcap --cachefile=input.cache

//只处理协议为tcp的端口号为22的据包.

参数Exclude的使用:

Exclude和include使用相似,功能相反..只举一例.其它类推.例如:

Tcpprep --auto=bridge --exclude=S:10.0.0.0/8,192.168.0.0/16 --pcap=input.pcap --cachefile=input.cache

//只处理源IP不在10.0.0.0/8,192.168.0.0/16网段内的数据包.

在使用tcpprep工具时,我们还可以给所得的cache文件加一些注释.例:

tcpprep --auto=bridge --pcap=input.pcap --cachefile=input.cache --comment="This is our evil packet pcap"

使用如下命令查看注释.

tcpprep --print-comment=input.cache

查看每个数据包的状态.

tcpprep --print-stats=input.cache

查看每个数据包的数据.

tcpprep --print-info=input.cache

更多详细信息.请查看:https://www.wendangku.net/doc/383715056.html,/trac/wiki/tcpprep

2.tcpreplay

指定一个网口.将数据包全部重放到指定网口上.例:

tcpreplay --intf1=eth0 sample.pcap

tcpreplay支持以不同速度发送数据包.可用如下命令:

tcpreplay --topspeed --intf1=eth0 sample.pcap

//以最快的速度发送数据包

tcpreplay --mbps=10.0 --intf1=eth0 sample.pcap

//以10M每秒的速度发送数据包

tcpreplay --multiplier=7.3 --intf1=eth0 sample.pcap

//以原有速度的7.3倍速发送数据包

tcpreplay --multiplier=0.5 --intf1=eth0 sample.pcap

//以原有速度的半速发送数据包

tcpreplay --pps=25 --intf1=eth0 sample.pcap

//以每秒25个包的速度发送数据包

tcpreplay --oneatatime --verbose --intf1=eth0 sample.pcap

//以一次一个包的速度发送数据包(debug时很有用)

Tcpreplay支循环重放数据包.命令如下.

tcpreplay --loop=10 --intf1=eth0 sample.pcap

//得放10次

tcpreplay --loop=0 --intf1=eth0 sample.pcap

//无限循环重放,直到Ctrl+C结束.

Tcpreplay支持在两个网口之间重放数据包.命令:

tcpreplay --cachefile=sample.prep --intf1=eth0 --intf2=eth1 sample.pcap

//cachefile为由tcpprep生成.

更多详细信息.请查看:https://www.wendangku.net/doc/383715056.html,/trac/wiki/tcpreplay

3.tcprewrite

Tcprewrite至少需要两个参数.infile指定需要编辑的pcap文件,outfile,指定输出的pcap文件名.例: tcprewrite --infile=input.pcap --outfile=output.pcap

Tcprewrite支持的输入文件的网络类型:

?Ethernet

?Cisco HDLC

?Linux SLL

?BSD Loopback

?BSD Null

?Raw IP

Tcprewrite支持的输出文件的网络类型:

?Ethernet (enet)

?Cisco HDLC (hdlc)

?User defined Layer 2 (user)

修改目的主机MAC和源主机MAC:

tcprewrite --enet-dmac=00:55:22:AF:C6:37 --enet-smac=00:44:66:FC:29:AF --infile=input.pcap --outfile=output.pcap

修改由tcpprep分析server和client端数据包的源mac目的mac,例:

tcprewrite --enet-dmac=00:44:66:FC:29:AF,00:55:22:AF:C6:37 --enet-smac=00:66:AA:D1:32:C2,00:22:55:AC:DE:AC --cachefile=input.cache --infile=input.pcap --outfile=output.pcap

//第一个目的MAC和源MAC为server端,第二个为client端.

删除和添加802.1q VLAN tag信息:

tcprewrite --enet-vlan=del --infile=input.pcap --outfile=output.pcap//删除cprewrite --enet-vlan=add --enet-vlan-tag=40 --enet-vlan-cfi=1 --enet-vlan-pri=4 --infile=input.pcap --outfile=output.pcap//添加

修改IP地址:

tcprewrite --endpoints=10.10.1.1:10.10.1.2 --cachefile=input.cache --infile=input.pcap --outfile=output.pcap –skipbroadcast

//将源IP替换为10.0.0.1,将目的IP替换为10.0.0.2, –skipbroadcast忽略广播包.

修改网段IP地址:

tcprewrite --pnat=10.0.0.0/8:172.16.0.0/12,192.168.0.0/16:172.16.0.0/12 --infile=input.pcap --outfile=output.pcap –skipbroadcast

//将10.0.0.0/8网段的IP替换与172.16.0.0/12.将192.168.0.0/16网段的IP替换为172.168.0.0/12.

随机生成源IP:

tcprewrite --seed=423 --infile=input.pcap --outfile=output.pcap

修改端口号:

tcprewrite --portmap=80:8080,22:8022 --infile=input.pcap --outfile=output.pcap //将端口80修改为8080,将端口22修改为8022.

更多详细信息.请查看:https://www.wendangku.net/doc/383715056.html,/trac/wiki/tcprewrite

相关文档