Skip to content

Instantly share code, notes, and snippets.

@brosahay
Created August 11, 2022 21:10
Show Gist options
  • Save brosahay/13b187b2e624a3c72c4561d10d3b1116 to your computer and use it in GitHub Desktop.
Save brosahay/13b187b2e624a3c72c4561d10d3b1116 to your computer and use it in GitHub Desktop.
Small helper scritpt to replay Scapy traffic
#!/usr/bin/env python
from scapy.arch import get_if_hwaddr, get_if_addr, get_if_addr6
from scapy.config import conf
from scapy.layers.inet import IP
from scapy.layers.inet6 import IPv6
from scapy.layers.l2 import Ether
from scapy.sendrecv import sendp, send
from scapy.utils import rdpcap
def network_replay():
pkts = rdpcap("capture.pcapng")
for pkt in pkts:
if IP in pkt:
pkt[IP].src = get_if_addr(conf.iface)
if IPv6 in pkt:
pkt[IPv6].src = get_if_addr6(conf.iface)
if Ether in pkt:
pkt[Ether].src = get_if_hwaddr(conf.iface)
try:
del pkt.chksum
except AttributeError:
pass
print("ready: " + pkt.summary())
sendp(pkt)
if __name__ == '__main__':
network_replay()
# activate venv
# run sudo ./main.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment