I am trying to sniff my wifi for received packets. When I receive an ftp packet, I reverse the source and destination (Mac address, IP address and ports) and then send them back again.
However when I check wireshark, I find that the modified packet sent has an error "[Malformed Packet] [ETHERNET FRAME CHECK SEQUENCE INCORRECT]" although I deleted the checksums before I send the packet back. Below is the function I defined to modify received packet src/dst:
def modify_packet(pkt):
source_mac_address = pkt[Ether].src
destination_mac_address = pkt[Ether].dst
destination_address = pkt[IP].dst
source_address = pkt[IP].src
destination_port = pkt[TCP].dport
source_port = pkt[TCP].sport
pkt[Ether].dst = source_mac_address
pkt[Ether].src = destination_mac_address
pkt[IP].dst = source_address
pkt[IP].src = destination_address
pkt[TCP].dport = source_port
pkt[TCP].sport = destination_port
del pkt[IP].chksum
del pkt[TCP].chksum
send(pkt)
return