Scapy fundamentals
Commands for the interactive scapy interpreter:
conf.ifaceshows the currently used interfaceconf.iface='tun0'sets the interface to use
lsshows all protocolsls(TCP)shows all known headers for a given protocollscshows build-in functions- Details about a packet
p:shows general informationpp.summary()shows also general informationp.show()shows each field and its valuels(p)shows each field and its value and also the default values for each field.hexdump(p)shows the whole packet as hexwireshark(p)opens the packet in wireshark
- Sending packet
p:send(p)sends the packet and adds layers below, e.g. includes it into a Ethernet frame.sendp(p)sends the packet without adding additional layers.answered, unanswered = sr(p)send and receive packetsanswered, unanswered = sr1(p)send and receive one packet and stop then
Crafting packets
Create a simple TCP/IP packet:
// Create an IP packet to a host. p = IP(dst="10.10.10.10") // Add a TCP packet over the IP packet with a destination port. p /= TCP(dport=[80, 443]) // Send the packet and receive/evalute 1 return packet. sr1(p) // The same in one command, also with two return sets: answered, unanswered = sr1(IP(dst="10.10.10.10")/TCP(dport=[80, 443])) // afterwards you can use the variables to inspect all successful and unsuccessful connection attempts.
The packets are stacked together and can modified at each level:

When querying for a field, it searches the field through all levels. E.g. when typing p.payload it will return the payload from the IP packet because the Ethernet packet doesn’t have a payload field. Alternative: p[IP].payload queries the field for the given protocol within the stack.
Leave a Reply
You must be logged in to post a comment.