Day 94 -
#100DaysOfCybersecurity
Today I completed a hands-on lab on Packet Crafting with Scapy, a powerful Python-based packet manipulation tool used by penetration testers and security researchers.
Unlike traditional scanners, Scapy allows you to manually craft, send, sniff, and analyze packets, making it extremely useful for reconnaissance, testing network behavior, and security research.
Activities I carried out:
🔎 Exploring Scapy
I started by launching Scapy in interactive mode and exploring its capabilities.
Using the ls() function, I viewed the large list of supported protocols and packet formats.
For example, Scapy supports 9 different TFTP packet formats.
TFTP is a useful protocol used to send and receive files on a LAN segment.
I also examined the structure of an IPv4 packet header using:
ls(IP)
This revealed important packet fields such as:
- TTL (Time To Live)
- Source and Destination IP addresses
- Protocol field (ICMP, TCP, UDP)
- Header checksum
Understanding these fields is essential when crafting custom packets.
📡 Sniffing Network Traffic
Next, I used Scapy’s sniff() function to capture traffic on the internal network interface.
Example:
sniff(iface="eth0")
I generated traffic by pinging a host and then reviewed the captured packets using:
- summary() function for native view, and
- nsummary() for number line view
I also filtered traffic to capture only ICMP packets and saved the capture to a .pcap file using:
wrpcap("icmp.pcap", a)
'a' is the variable I used to store the output of the sniff() function
Then, I used Wireshark to open the pcap for deeper analysis.
📦 Crafting a Custom ICMP Packet
I created and sent a custom ICMP packet to the target host 10.6.6.23.
Example:
send(IP(dst="10.6.6.23")/ICMP()/"This is a test")
The packet capture confirmed both the ICMP echo-request and echo-reply, and I observed that the crafted packet contained my custom payload in the raw data field.
🔌 Crafting a TCP SYN Packet
Finally, I crafted a TCP SYN packet to test whether port 445 (SMB) was open on the target system.
Example:
send(IP(dst="10.6.6.23")/TCP(dport=445, flags="S"))
The response returned a SYN-ACK (SA) flag, confirming that port 445 was open.
Key lessons I learned from this lab:
- Scapy is Python based and run in an interactive command mode.
- It allows deep control over packet creation and analysis.
- Packet crafting can reveal how systems respond to specific network interactions.
- Custom packets can be used for reconnaissance, testing firewall behavior, and identifying open services.
Understanding tools like Scapy helps to analyze networks at a much deeper level than traditional scanning tools alone.
@jay_hunts @ireteeh @segoslavia
#RedTeamer #Cybersecurity #EthicalHacking #Scapy #NetworkSecurity #PacketAnalysis