Skip to content

Instantly share code, notes, and snippets.

@voidbar
Last active May 25, 2022 12:27
Show Gist options
  • Save voidbar/c21cf66bd336f45f9f73eeb04ec2ce48 to your computer and use it in GitHub Desktop.
Save voidbar/c21cf66bd336f45f9f73eeb04ec2ce48 to your computer and use it in GitHub Desktop.
Creating a valid pcap from raw packet ethernet bytes using scapy
import sys
import scapy.all as s
pkt_bytes = [0x01, 0x00, 0x5e, 0x00, 0x00, 0xfb, 0x48, 0x4d, 0x7e, 0xb9, 0x4d, 0x34, 0x08, 0x00, 0x45, 0x00, 0x00, 0x6a,
0xae, 0x07, 0x40, 0x00, 0xff, 0x11, 0x8e, 0x1a, 0x0a, 0xa6, 0x53, 0xbf, 0xe0, 0x00, 0x00, 0xfb, 0x14, 0xe9,
0x14, 0xe9, 0x00, 0x56, 0xf6, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x05, 0xd7, 0x94, 0xd7, 0x99, 0x21, 0x00, 0x00, 0x0c, 0x00, 0x01, 0xc0, 0x0c, 0x00, 0x0c, 0x00, 0x01, 0x00,
0x00, 0x11, 0x94, 0x00, 0x20, 0x1d, 0x48, 0x50, 0x20, 0x4c, 0x61, 0x73, 0x65, 0x72, 0x4a, 0x65, 0x74, 0x20,
0x4d, 0x46, 0x50, 0x20, 0x4d, 0x36, 0x33, 0x30, 0x20, 0x5b, 0x43, 0x41, 0x43, 0x39, 0x31]
def main(filepath):
print(f"Writing pcap file to {filepath}...")
s.wrpcap(filepath, [s.Ether(pkt_bytes)])
if "__main__" == __name__:
if len(sys.argv) < 2:
print(f"usage: {sys.argv[0]} {{OUTPUT_FILE}}")
sys.exit(1)
main(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment