Duplicate TCP traffic with a proxy

自作多情 提交于 2019-11-28 04:58:32
chrislusf

I have created a proxy just for this purpose.

https://github.com/chrislusf/teeproxy

Usage

./teeProxy -l :8888 -a localhost:9000 -b localhost:9001

tee-proxy is a reverse proxy. For each incoming request, it clones the request into 2 and then forwards them to 2 servers. The results from server a is returned as usual, but the results from server b is ignored.

tee-proxy handles both GET, POST, and other HTTP methods.

How about the iptables experimental ROUTE target? It has a "tee" option for mirroring traffic:

http://www.netfilter.org/projects/patch-o-matic/pom-external.html#pom-external-ROUTE

Which would let you mirror traffic with something like:

iptables -A PREROUTING -t mangle -p tcp --dport 80 -j ROUTE --gw 1.2.3.4 --tee
iptables -A POSTROUTING -t mangle -p tcp --sport 80 -j ROUTE --gw 1.2.3.4 --tee

The second machine would need to be on the same subnet and would either need to listen on the target IP address (and not reply to arps) or listen promiscuously.

Try https://github.com/agnoster/duplicator.

I tried teeproxy but got strange results with some requests other than GET's.

I have also written a reverse proxy / load balancer for a similar purpose with Node.js (it is just for fun, not production ready at the moment).

https://github.com/losnir/ampel

It is very opinionated, and currently supports:

  • GET Using round-robin selection (1:1)
  • POST Using request splitting. There is no concept of "master" and "shadow" -- the first backend that responds is the one that will serve the client request, and then all of the other responses will be discarded.

If someone finds it useful then I can improve it to be more flexible.

I needed something that could tee the TCP traffic as well, but being not intrusive, thus not being able to put something in-between as a reverse proxy for example.

What I did is basically did is use the tcpdump/wireshark logic (packet sniffing) wrap it in a Go process that you can configure to do some things.

For whom it may be helpful the code can be found here: https://github.com/RobinUS2/teecp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!