代码:https://github.com/wangbin579/tcpcopy/tree/master 参考:http://blog.csdn.net/wangbin579/article/deta
代码:https://github.com/wangbin579/tcpcopy/tree/master
参考:http://blog.csdn.net/wangbin579/article/details/8950282
当前(2017-03-24)最新版本为1.0版
TCPCopy 历史上有三种架构,本文只包含后两种,详情见http://blog.csdn.net/wangbin579/article/details/8949315
tcpcopy一般使用于同一子网内
第二种架构:
tcpcopy从IP层截获tcp包将其发往test机器,test机器设置iptable规则将对应端口返回的数据包发到queue中,intercept从queue中取出数据,将tcp响应头信息发往tcpcopy
优点:使用服务器少
缺点:intercept占用测试机的硬件资源
第三种架构:
tcpcopy截获数据包,转发给target服务器,target服务器设置路由策略,将返回的信息发送给辅助服务器,辅助服务器运行intercept程序
优点:测试机保持了纯净的环境
缺点:所需服务器较多
下载
git clone git://github.com/session-replay-tools/tcpcopy.git
git clone git://github.com/session-replay-tools/intercept.git
编译intercept(建议在一台机器上编译好,拷贝到相应机器上使用,注意拷贝相应动态库,注意编译时相关的路径要创建,相关的文件要创建)
第二种架构
apt-get install libnetfilter-queue-dev
cd intercept
./configure --traditional #参数很重要
make
make install
默认安装到/usr/local/intercept/
第三种架构
apt-get install libpcap-dev
cd intercept
./configure
make
make install
默认安装到/usr/local/intercept/
编译tcpcopy(两种架构相同)
cd tcpcopy
./configure
make
make install
默认安装到/usr/local/tcpcopy/
使用:
第二种架构
目标机:(后边IP是ssh控制端IP访问不过滤)
(kernel < 3.5) iptables -I OUTPUT -p tcp --sport <port> ! -d 203.100.82.142 -j QUEUE ----> <port>为测试机应用的端口,IP是我们登录设备的IP,防止登录不了设备了
(kernel >= 3.5) iptables -I OUTPUT -p tcp --sport <port> ! -d 203.100.82.142 -j NFQUEUE
/usr/local/intercept/sbin/intercept -d ---> 关闭时使用kill
附:查看删除iptables规则
iptables -nvL --line-number
iptables -D OUTPUT <nu>
源主机:
/usr/local/tcpcopy/tcpcopy -x localServerPort-targetServerIP:targetServerPort -s targetServerIP -d
例如:将发往80端口的数据发送到61.179.50.171的80端口,目标机器为61.179.50.171,后台运行。
/usr/local/tcpcopy/tcpcopy -x 80-61.179.50.171:80 -s 61.179.50.171 -d
第三种架构
目标机:添加路由规则,将某个网段的数据发往指定的网关(辅助机)
route add -net 111.111.111.0 netmask 255.255.255.0 gw 61.179.50.163
辅助机:将目标机80端口发来的数据过滤出来处理
/usr/local/intercept/sbin/intercept -i eth0 -F 'tcp and src port 80' -d
源主机:将本机80端口收到的数据修改源IP到 111.111.111.0/24网段,发往61.179.50.171的80端口,连接intercept主机为61.179.50.163
/tcpcopy -x 80-61.179.50.171:80 -s 61.179.50.163 -c 111.111.111.x