【发布时间】:2017-02-07 11:20:54
【问题描述】:
假设我设法处于客户端和服务器之间的通信中间(假设我打开了一个热点并导致客户端仅通过我的机器连接到服务器)。
如何在不中断我自己与其他服务的通信的情况下更改我的客户端发送和接收的数据包?必须有一种方法可以通过我的脚本路由客户端发送和即将接收的所有数据包(在转发给他之前)。
我认为实现这一目标的正确方向是使用iptables,但不确定究竟哪些参数适合使这项工作。我已经有了以下简单的脚本:
hotspotd start #a script that runs dnsmasq as both a DNS and DHCP server, configures and starts a hotspot
iptables -P FORWARD ACCEPT
iptables --append FORWARD --in-interface wlan0 -j ACCEPT
iptables --table nat --append POSTROUTING --out-interface eth0 -j MASQUERADE
#wlan0 is the interface on which the hotspot is.
#eth0 is the interface that is connected to the internet
现在,这非常适用于被动 MITM - 我可以看到客户端发送和接收的所有内容。但现在我想加强并重定向他通过我发送和接收的每条消息。
我的最终目的是达到可以执行以下脚本的水平:
from scapy.all import *
from scapy_http.http import *
def callback(pkt):
#Process the packet here, see source and destination addresses, ports, data
send(pkt)
sniff(filter='port 666', prn=callback) #Assuming all relevant packets are redirected to port 666
如何完成重定向客户端发送和即将接收的每个数据包?
【问题讨论】:
标签: python linux iptables scapy man-in-the-middle