tcpreplay使用手册

tcpreplay使用手册

2023年7月10日发(作者:)

tcpreplay使用手册

tcpreplay使用手册

2013年4月27日星期六

陈海敏简介

Tcpreplay是一系列工具的总称,包括tcpreplay、tcprewrite和tcpprep 等工具,这也是Tcpreplay的第一个字母大写的原因。它用来在Unix系统或类Unix系统上重放网络包。这些包是由tcpdump、ethereal和wireshark等软件抓取到的,即pcap格式的数据包。正因为Tcpreplay有重放数据包的功能,所以它常被用来模拟IDS攻击等测试环境,被广泛地用来测试防火墙和IDS工具的安全性。

一、tcpreplay使用方法

1 基本用法

将抓取到的pcap包通过eth0网口进行回放,当存在多网卡时,可以选择通过哪个口进行发送,一般一台机子只有一个网卡eth0

#tcpreplay --intf1=eth0

或者缩写

#tcpreplay -i eth0

关于缩写,一般都是全称的首字母,不再给出特别说明,自己可以通过tcpreplay–h 命令进行查看,附录部分也给出了部分常用的,可以参考。

2 以不同的速度回放

1)以尽可能大的速度回放

#tcpreplay --topspeed --intf1=eth0

2)以10Mbps速率回放

#tcpreplay --mbps=10.0 --intf1=eth0

3)以原速度的7.3倍速率回放

#tcpreplay --multiplier=7.3 --intf1=eth0

4)以原速度的0.5倍速率回放

#tcpreplay --multiplier=0.5 --intf1=eth0 5)以每秒回放25个包的速率回放

#tcpreplay --pps=25 --intf1=eth0

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

#tcpreplay

3 循环播放数据包

1)重放10次

#tcpreplay --loop=10 --intf1=eth0

2)无限循环重放,直到Ctrl+C结束

#tcpreplay --loop=0 --intf1=eth0

4 两个网口之间重放数据包

1)可以利用tcpprep将数据包通信双方区分为客户端和服务器端,这样在eth0和eth1之间通信就相当于是客户端和服务器。

#tcpreplay --cachefile= --intf1=eth0 --intf2=eth1

说明:cachefile为由tcpprep生成,会在下面的tcpgrep部分介绍具体用法

2)如果已经将数据包分成两个文件,那么tcpreplay就可以用如下的命令在两个网口之间进行数据的重放。

#tcpreplay --dualfile --intf1=eth0 --intf2=eth1

更ay

二、tcpprep使用方法

1 基本用法

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

tcpprep所支持的模式:

Auto/Bridge

Auto/Router

多详细信息.请查看:/doc/,/trac/wiki/tcprepl--oneatatime --verbose --intf1=eth0 Auto/Client

Auto/Server

IPv4 matching CIDR

IPv4 matching Regex

TCP/UDP Port

MAC address

1.1 auto/bridge模式

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

client行为如下定义:

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

发送一个DNS 请求

收到一个ICMP 端口不可达

Server行为如下定义:

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

发送一个DNS 应答

发关一个ICMP 端口不可达

例: tcpprep --auto=bridge --pcap=

--cachefile=

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

tcpprep --auto=bridge --pcap=

--cachefile= --ratio=3.5

1.2 auto/router模式

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

--cachefile=

1.3 auto/client模式

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

tcpprep --auto=client --pcap= --cachefile=

1.4 auto/server模式

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

1.5 Cidr模式

在Cidr模式下.用户手动给出server所在的网段.而不像在auto模式下由tcpprep来区分.例:

Tcpprep --cidr=10.0.0.0/8,172.16.0.0/12 --pcap= --cachefile=

1.6 Regex模式

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

tcpprep --regex="(10|20)..*" --pcap=

--cachefile=

1.7 port模式

在port模式下,用端口号来区分server 和client.默认情况下,0—1024端口为server端所有.1024以外为client所有.当然.你也可以在自己

/etc/services中划分服务器端口.

tcpprep --port --services=/etc/services --pcap=

--cachefile=

1.8 mac模式

在mac模式下.由用户指定那些mac为服务端mac.例:

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

2 跳过数据包

2.1 参数include

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

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

Tcpprep

cachefile=

2)只处理目的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= --cachefile=

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

Tcpprep

cachefile=

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

5)Tcpprep --auto=bridge

--include=E:10.0.0.0/8,192.168.0.0/16 --pcap=

--cachefile=

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

Tcpprep --auto=bridge --include=P:1-5,9,15,72-

--pcap= --cachefile=

7)只处理协议为tcp的端口号为22的据包

Tcpprep --auto=bridge --include=F:"tcp port 22"

--pcap= --cachefile=

2.2 参数Exclude

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

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

--auto=bridge

--pcap=

----include=B:10.0.0.0/8,192.168.0.0/16

--auto=bridge

--pcap=

----include=S:10.0.0.0/8,192.168.0.0/16 Tcpprep

exclude=S:10.0.0.0/8,192.168.0.0/16

cachefile=

2.3其他

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

--cachefile= --comment="This is our evil packet

pcap"

使用如下命令查看注释.

tcpprep --print-comment=

查看每个数据包的状态.

tcpprep --print-stats=

查看每个数据包的数据.

tcpprep --print-info=

更多详细信息.请查看:

/doc/,/trac/wiki/tcpprep

三、tcprewrite使用方法

1.基本用法

Tcprewrite至少需要两个参数.infile指定需要编辑的pcap文件,outfile,指定输出的pcap文件名.

例:$ tcprewrite --infile= --outfile=

为原数据包,为被修改后的数据包,此处并没有对数据包内容进行任何修改,具体参数,下面介绍。

2 具体用法说明

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

Ethernet

Cisco HDLC

Linux SLL

BSD Loopback

BSD Null Raw IP

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

Ethernet (enet)

Cisco HD LC (hdlc)

User defined Layer 2 (user)

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

1)直接修改原始包

tcprewrite --enet-dmac=00:55:22:AF:C6:37

--enet-smac=00:44:66:FC:29:AF --infile=

--outfile=

2)修改由tcpprep分析server和client端数据包的源mac目的mac tcprewrite --enet---enet---dmac=00:44:66:FC:29:AF,00:55:22:AF:C6:37

smac=00:66:AA:D1:32:C2,00:22:55:AC:DE:AC

--cachefile=

outfile=

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

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

删除:tcprewrite --enet-vlan=del --infile=

--outfile=

添加:cprewrite --enet-vlan=add --enet-vlan-tag=40

--enet-vlan-cfi=1 --enet-vlan-pri=4 --infile=

--outfile=

2.2 修改IP地址

将源IP替换为10.0.0.1,将目的IP替换为10.0.0.2, –skipbroadcast

忽略广播包

tcprewrite --endpoints=10.10.1.1:10.10.1.2

--cachefile=

outfile=

–skipbroadcast

--infile= ----infile= 2.3修改网段IP地址

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

tcprewrite

--pnat=10.0.0.0/8:172.16.0.0/12,192.168.0.0/16:172.16.0.0/12

--infile= --outfile= –skipbroadcast

2.4随机生成源IP

tcprewrite

2.4 修改端口号

将端口80修改为8080,将端口22修改为8022

tcprewrite --portmap=80:8080,22:8022 --infile=

--outfile=

更rite

四、用法举例

将源数据包改为192.168.48.95和192.168.48.193发包

95mac地址:a4:1f:72:4e:42:ac

193mac地址:00:25:90:0a:08:8e

p生成cache:tcpprep -p --pcap=

--cachefile=

说明,tcpprep部分也有说明,-p,表示根据端口号来区分客户端和服务器端,一般而言0-1024为服务器所使用的端口

te修改mac:tcprewrite

--enet-smac="a4:1f:72:4e:42:ac"

--enet-dmac=="00:25:90:0a:08:8e" --infile=

--outfile=

te修改ip:tcprewrite --cachefile=

多详细信息.请查看:/doc/,/trac/wiki/tcprew--seed=423 --infile= --outfile= --endpoints="192.168.48.193:192.168.48.95"

infile=

--outfile=

2,3两步可以合并:tcprewrite --cachefile=

--enet-smac="a4:1f:72:4e:42:ac"

--enet-dmac="00:25:90:0a:08:8e"

-outfile= 这样就不用生成中间文件了

----endpoints="192.168.48.193:192.168.48.95" --infile= -说明:对于这部分两个ip地址,我的理解是第一个193作为服务器,95是客户端。如果tcpprep区分不了客户端和服务器的话,可能就会导致,所有的数据包都是从95发往193。这只是我自己在发包测试的时候总结的规律,还有待考证。所以大家在修改完包后,查看一下修改后的ip和mac地址,看看对应关系是否正确。

lay发包:-l参数是说循环多少次,注意这个次数是对一个trace而言的,-p参数是说每秒发多少个包,-i是说从那个网卡发

tcpreplay -l5 -p10 -i eth0

每秒发送10个,循环5次,假设源trace有50个数据包,那么整个发完应该是一共发送了250个数据包,大概25秒发完

附录:tcpreplay参数说明

此部分也可以直接参看tcpreplay–h,此处只列出本人认为实用性比较强的。

-i, --intf1=str服务器/初始数据输出口

-I, --intf2=str客户端/第二个数据流输出口

-L, --limit=num限制发包数目

-l, --loop=num定义trace循环次数

-x, --multiplier=str修改发包速度,str为原速度的倍数

-M, --mbps=str以给定的Mbps速度发包

-t, --topspeed尽快的速度发包

-o, --oneatatime一次发送一个包

-p,--pps-multi=num每秒发送的数据包数

发布者:admin,转转请注明出处:http://www.yc00.com/xiaochengxu/1688984486a191565.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信