我试图在透明模式下使用MITMproxy。我有两台机器:
我现在只关注IPv4和HTTP,以保持简单。不是TLS或IPv6。
在Linux上运行MITMProxy
mitmproxy --mode transparent --showhost
在Android上我运行了
adb shell sysctl -w net.ipv4.ip_forward=1
adb shell sysctl -w net.ip4.conf.all.send_redirects=0
adb shell iptables -t nat -A OUTPUT -p tcp --dport 80 -j DNAT --to-destination $IP_LINUX:8080为了将到达端口80的所有通信量重定向到端口8080上的Linux机器,mitmproxy默认侦听。
adb shell iptables -t nat -L --line-numbers
Chain PREROUTING (policy ACCEPT)
num target prot opt source destination
1 oem_nat_pre all -- anywhere anywhere
Chain INPUT (policy ACCEPT)
num target prot opt source destination
Chain OUTPUT (policy ACCEPT)
num target prot opt source destination
1 DNAT tcp -- anywhere anywhere tcp dpt:http to:192.168.2.123:8080
Chain POSTROUTING (policy ACCEPT)
num target prot opt source destination
1 tetherctrl_nat_POSTROUTING all -- anywhere anywhere
Chain oem_nat_pre (1 references)
num target prot opt source destination
Chain tetherctrl_nat_POSTROUTING (1 references)
num target prot opt source destination 然后,我尝试用http://www.cs.sjsu.edu和安卓浏览器连接80端口上的IPv4 (我在IPv4上找到了一个在线主机)。
我可以在Android和Linux上看到tcpdump的数据包被重定向,但是我没有在MITProxy中看到任何东西,连接到这个网站仍然失败。
ping www.cs.sjsu.edu
PING cos-cwebwebster.sjsu.edu (130.65.255.57) 56(84) bytes of data.
--- cos-cwebwebster.sjsu.edu ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms
adb shell nc 130.65.255.57 80使用tcpdump,我可以看到重定向的数据包。
安卓系统
adb shell tcpdump -l -nn dst $IP_LINUX and dst port 8080
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on wlan0, link-type EN10MB (Ethernet), capture size 262144 bytes
10:30:17.513892 IP 192.168.2.101.47970 > 192.168.2.123.8080: Flags [S], seq 1827135764, win 65535, options [mss 1460,sackOK,TS val 368320 ecr 0,nop,wscale 9], length 0
10:30:17.514078 IP 192.168.2.101.47968 > 192.168.2.123.8080: Flags [S], seq 2479685048, win 65535, options [mss 1460,sackOK,TS val 368320 ecr 0,nop,wscale 9], length 0
10:30:17.514296 IP 192.168.2.101.47966 > 192.168.2.123.8080: Flags [S], seq 1020904415, win 65535, options [mss 1460,sackOK,TS val 368320 ecr 0,nop,wscale 9], length 0在Linux上
sudo tcpdump -i any -l -nn src $IP_ANDROID and dst port 8080
tcpdump: data link type LINUX_SLL2
dropped privs to tcpdump
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on any, link-type LINUX_SLL2 (Linux cooked v2), snapshot length 262144 bytes
10:30:17.577226 wlp65s0 In IP 192.168.2.101.47970 > 192.168.2.123.8080: Flags [S], seq 1827135764, win 65535, options [mss 1460,sackOK,TS val 368320 ecr 0,nop,wscale 9], length 0
10:30:17.578696 wlp65s0 In IP 192.168.2.101.47968 > 192.168.2.123.8080: Flags [S], seq 2479685048, win 65535, options [mss 1460,sackOK,TS val 368320 ecr 0,nop,wscale 9], length 0但是在MITMProxy上什么也没有出现,连接也失败了。
我遗漏了什么?谢谢!
发布于 2022-11-06 10:26:10
您希望在流量到达linux网络进程之前对其进行nat处理。您的nat状态在输出链上,这是后面的。
https://docs.mitmproxy.org/stable/howto-transparent/
iptables -t nat -A PREROUTING -i eth0 -p tcp -dport 80 -j重定向到端口8080
您还可以在android主机IP上执行tcpdump,而不是src/and端口。然后,您也可以监视返回流量。(tcpdump -l -nn主机1.2.3.4)
https://serverfault.com/questions/1114948
复制相似问题