-
-
Save jacktang/faee34ecb5e569f2cd88e514f45ad3b8 to your computer and use it in GitHub Desktop.
Resend udp packet to another host using pcap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import pcap | |
import socket | |
from scapy.all import * | |
conf.use_pcap=True # because by default scapy try to use raw socket and can't assign bpf filter | |
conf.verb=0 # it just grab all traffic and get error on processing | |
import scapy.arch.pcapdnet | |
send_to_address = "192.168.0.5" | |
send_to_port = 2055 | |
bpf_filter="udp and dst port 9996" | |
iface="eth0" | |
def resend_action(p): | |
newpkt = craft_packet(p) | |
newpkt[IP].dst = send_to_address | |
newpkt[UDP].dport = send_to_port | |
send(newpkt[IP]) | |
def craft_packet(pkt): | |
# make new packet based on original packet | |
newpkt = Ether()/\ | |
IP(src=pkt[IP].src, dst=pkt[IP].dst, id=pkt[IP].id)/\ | |
UDP(sport=pkt[UDP].sport, dport=pkt[UDP].dport)/\ | |
Raw(load=pkt[Raw].load) | |
return newpkt | |
while 1: | |
sniff(filter=bpf_filter, iface=iface, prn=resend_action, store=0, promisc=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment