tcpcopy 流量复制

依赖 libpcap

 

线上服务器安装

https://github.com/session-replay-tools/tcpcopy.git

下载后解压

#--pcap-capture 默认raw socket方式抓包,添加这个参数后改为pcap方式抓包,默认抓包方式不用加-F

#--pcap-send 测试端获取不到流量,iptables的问题,线上服务器又不允许修改时添加

./configure --prefix=/usr/local/tcpcopy --pcap-capture

make && make install

 

辅助服务器安装

https://github.com/session-replay-tools/intercept.git

下载后解压

./configure --prefix=/usr/local/intercept

make && make install

 

 

1.同网段环境

192.168.1.2 线上服务器

192.168.1.3 测试服务器(可以将辅助服务安装到测试服务上面)

192.168.1.4 辅助服务器

#启动http服务

192.168.1.2 192.168.1.3

python -m SimpleHTTPServer 8055

#启动辅助服务

192.168.1.4

/usr/local/intercept/sbin/intercept -i eth0 -F  'tcp and src port 8055' -d

192.168.1.2

#复制流量-c修改访问的ip

/usr/local/tcpcopy/sbin/tcpcopy -F 'tcp and dst port 8055' -x 8055-192.168.1.3:8055 -s 192.168.1.4 -c 172.16.55.x -d

192.168.1.3

#静态路由,将172.16.55的包全部转到辅助服务器

route add -net 172.16.55.0 netmask 255.255.255.0 gw 192.168.1.4

 

 

2.跨网段

192.168.1.2 线上服务器

192.168.2.2 测试服务器(可以将辅助服务安装到测试服务上面)

#启动http服务

192.168.1.2 192.168.2.2

python -m SimpleHTTPServer 8055

#启动辅助服务

192.168.2.2

/usr/local/intercept/sbin/intercept -i eth0 -F  'tcp and src port 8055' -d

192.168.1.2

#复制流量-c 包装为tcpcopy服务器上的网段ip,不能是和192.168.2.2通讯的ip,所以这里包装为192.168.1.3

/usr/local/tcpcopy/sbin/tcpcopy -F 'tcp and dst port 8055' -x 8055-192.168.2.2:8055 -s 192.168.2.2 -c 192.168.1.3 -d

 

 

3.iptables问题又无法修改,或者tcpcopy丢包、效率低

#注意这里安装时添加了--pcap-send

./configure --prefix=/usr/local/tcpcopy --pcap-capture --pcap-send #测试端获取不到流量,iptables的问题,线上服务器又不允许修改时添加

make && make install

192.168.1.2 线上服务器

192.168.2.2 测试服务器(可以将辅助服务安装到测试服务上面)

#启动http服务

192.168.1.2 192.168.2.2

python -m SimpleHTTPServer 8055

#启动辅助服务

192.168.2.2

/usr/local/intercept/sbin/intercept -i eth0 -F  'tcp and src port 8055' -d

192.168.1.2

#复制流量-c 包装为tcpcopy服务器上的网段ip,不能是和192.168.2.2通讯的ip,所以这里包装为192.168.1.3

#/usr/local/tcpcopy/sbin/tcpcopy -x 线上服务器端口@线上服务器MAC-测试服务器IP:测试服务器端口@线上服务器到测试服务器的下一跳MAC(同网段则是测试服务器MAC,不同网段则是线上服务器下一跳MAC) -o 与测试服务器通讯的接口 -c 包装的IP -s 辅助服务器IP -d

/usr/local/tcpcopy/sbin/tcpcopy -F 'tcp and dst port 8055' -x 8055@00:A3:81:CC:88:BD-192.168.2.2:8055@00:B3:A1:AC:C8:BA -o eth0 -c 192.168.1.3  -s 192.168.2.2 -d

 

dst是destination的缩写,表目的
src是source的缩写,表源

tcpcopy与intercept的-F写法与tcpdump的过滤方式一样

 

 

#参考#https://www.cnblogs.com/phennry/p/6382755.html?utm_source=itdadao&utm_medium=referral
#https://github.com/session-replay-tools/tcpcopy/issues/173
#https://blog.csdn.net/wangbin579/article/details/10148247

 

posted @ 2018-04-19 12:36  IT菜鸟园  阅读(1214)  评论(0编辑  收藏  举报