tcpproxy
1.0.0
该工具打开一个侦听套接字,接收数据,然后通过代理模块链运行该数据。模块完成后,将结果数据发送到目标服务器。接收响应并再次运行一系列模块,然后将最终数据发送回客户端。要拦截数据,您必须成为网关或进行某种中间人攻击。设置 iptables,以便 PREROUTING 链将修改目的地并将其发送到代理进程。然后,代理会将数据发送到指定的任何目标。
该工具的灵感来自并部分基于 Justin Seitz 的书“Black Hat Python”中使用的 TCP 代理示例,作者为 no star press。
$ ./tcpproxy.py -h
usage: tcpproxy.py [-h] [-ti TARGET_IP] [-tp TARGET_PORT] [-li LISTEN_IP]
[-lp LISTEN_PORT] [-pi PROXY_IP] [-pp PROXY_PORT]
[-pt {SOCKS4,SOCKS5,HTTP}] [-om OUT_MODULES]
[-im IN_MODULES] [-v] [-n] [-l LOGFILE] [--list]
[-lo HELP_MODULES] [-s] [-sc SERVER_CERTIFICATE]
[-sk SERVER_KEY] [-cc CLIENT_CERTIFICATE] [-ck CLIENT_KEY]
Simple TCP proxy for data interception and modification. Select modules to
handle the intercepted traffic.
optional arguments:
-h, --help show this help message and exit
-ti TARGET_IP, --targetip TARGET_IP
remote target IP or host name
-tp TARGET_PORT, --targetport TARGET_PORT
remote target port
-li LISTEN_IP, --listenip LISTEN_IP
IP address/host name to listen for incoming data
-lp LISTEN_PORT, --listenport LISTEN_PORT
port to listen on
-pi PROXY_IP, --proxy-ip PROXY_IP
IP address/host name of proxy
-pp PROXY_PORT, --proxy-port PROXY_PORT
proxy port
-pt {SOCKS4,SOCKS5,HTTP}, --proxy-type {SOCKS4,SOCKS5,HTTP}
proxy type. Options are SOCKS5 (default), SOCKS4, HTTP
-om OUT_MODULES, --outmodules OUT_MODULES
comma-separated list of modules to modify data before
sending to remote target.
-im IN_MODULES, --inmodules IN_MODULES
comma-separated list of modules to modify data
received from the remote target.
-v, --verbose More verbose output of status information
-n, --no-chain Don't send output from one module to the next one
-l LOGFILE, --log LOGFILE
Log all data to a file before modules are run.
--list list available modules
-lo HELP_MODULES, --list-options HELP_MODULES
Print help of selected module
-s, --ssl detect SSL/TLS as well as STARTTLS
-sc SERVER_CERTIFICATE, --server-certificate SERVER_CERTIFICATE
server certificate in PEM format (default: mitm.pem)
-sk SERVER_KEY, --server-key SERVER_KEY
server key in PEM format (default: mitm.pem)
-cc CLIENT_CERTIFICATE, --client-certificate CLIENT_CERTIFICATE
client certificate in PEM format in case client
authentication is required by the target
-ck CLIENT_KEY, --client-key CLIENT_KEY
client key in PEM format in case client authentication
is required by the target
您必须提供 TARGET_IP 和 TARGET_PORT,默认监听设置为 0.0.0.0:8080。为了使该程序真正有用,您必须决定要在传出(客户端到服务器)和传入(服务器到客户端)流量上使用哪些模块。您可以为每个方向使用不同的模块。以逗号分隔的列表形式传递模块列表,例如 -im mod1,mod4,mod2。数据将传递到第一个模块,返回的数据将传递到第二个模块,依此类推,除非您使用 -n/--no/chain 开关。在这种情况下,每个模块都会收到原始数据。您还可以将选项传递给每个模块:-im mod1:key1=val1,mod4,mod2:key1=val1:key2=val2。要了解可以传递给模块的选项,请使用 -lo/--list-options,如下所示:-lo mod1,mod2,mod4
$ ./tcpproxy.py --list
digestdowngrade - Find HTTP Digest Authentication and replace it with a Basic Auth
hexdump - Print a hexdump of the received data
http_ok - Prepend HTTP response header
http_post - Prepend HTTP header
http_strip - Remove HTTP header from data
log - Log data in the module chain. Use in addition to general logging (-l/--log).
removegzip - Replace gzip in the list of accepted encodings in a HTTP request with booo.
replace - Replace text on the fly by using regular expressions in a file or as module parameters
hexreplace - Replace hex data in tcp packets
size - Print the size of the data passed to the module
size404 - Change HTTP responses of a certain size to 404.
textdump - Simply print the received data as text
tcpproxy.py 使用模块来查看或修改截获的数据。要查看模块的最简单实现,请查看 proxymodules 目录中的 textdump.py 模块: