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 模組: