Intermediate

Packet Analysis

Every bit on the wire tells a story. Understanding packet structure lets you see what tools abstract away—and spot what they miss.

Beyond the GUI

This module focuses on understanding the structure of packets. For Wireshark usage, see the Wireshark Cheatsheet.

Ethernet Frame Structure (Layer 2)

Every packet on a LAN starts with an Ethernet frame. Understanding this helps with ARP attacks and MAC analysis.

Ethernet II Frame Format:
Preamble
7 bytes
SFD
1 byte
Dest MAC
6 bytes
Src MAC
6 bytes
EtherType
2 bytes
Payload (IP Packet)
46-1500 bytes
FCS
4 bytes

EtherType Values

  • 0x0800 - IPv4
  • 0x0806 - ARP
  • 0x86DD - IPv6
  • 0x8100 - 802.1Q VLAN

Security Notes

  • • MAC addresses can be spoofed
  • • ARP has no authentication
  • • VLAN tags can be injected (double tagging)

IPv4 Header Structure (Layer 3)

IPv4 Header (20-60 bytes):
 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Version|  IHL  |    DSCP   |ECN|         Total Length          |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|         Identification        |Flags|     Fragment Offset     |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|  Time to Live |    Protocol   |        Header Checksum        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                       Source IP Address                       |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                    Destination IP Address                     |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                    Options (if IHL > 5)                       |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Protocol Numbers

  • 1 - ICMP
  • 6 - TCP
  • 17 - UDP
  • 47 - GRE
  • 50 - ESP (IPSec)

TTL Analysis

  • • Linux default: 64
  • • Windows default: 128
  • • Cisco/network: 255
  • • Use for OS fingerprinting

Attack Vectors

  • • IP spoofing (source IP)
  • • Fragmentation attacks
  • • TTL manipulation
  • • IP options abuse

TCP Header Structure (Layer 4)

TCP Header (20-60 bytes):
 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|          Source Port          |       Destination Port        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                        Sequence Number                        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                    Acknowledgment Number                      |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|  Data |       |C|E|U|A|P|R|S|F|                               |
| Offset| Rsrvd |W|C|R|C|S|S|Y|I|            Window             |
|       |       |R|E|G|K|H|T|N|N|                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|           Checksum            |         Urgent Pointer        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                    Options (if Data Offset > 5)               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

TCP Flags (Critical for Scanning)

SYN
Initiate connection
ACK
Acknowledge data
RST
Reset connection
FIN
Close connection
PSH
Push data now
URG
Urgent pointer
ECE
ECN Echo
CWR
Congestion Window

Practical Packet Analysis

Examine Raw Packets with tcpdump

tcpdump-analysis.sh
bash
# Capture packets in hex/ASCII
tcpdump -i eth0 -X -c 10

# Show TCP flags
tcpdump -i eth0 'tcp[tcpflags] & (tcp-syn|tcp-ack) != 0'

# Capture to file for Wireshark
tcpdump -i eth0 -w capture.pcap
# Capture packets in hex/ASCII
tcpdump -i eth0 -X -c 10

# Show TCP flags
tcpdump -i eth0 'tcp[tcpflags] & (tcp-syn|tcp-ack) != 0'

# Capture to file for Wireshark
tcpdump -i eth0 -w capture.pcap

Scapy - Craft Custom Packets (Python)

scapy-craft.py
python
from scapy.all import *

# Create and examine an IP packet
ip = IP(dst="192.168.1.1")
tcp = TCP(dport=80, flags="S")  # SYN packet
packet = ip/tcp

# Show packet layers
packet.show()

# Send the packet
send(packet)
from scapy.all import *

# Create and examine an IP packet
ip = IP(dst="192.168.1.1")
tcp = TCP(dport=80, flags="S")  # SYN packet
packet = ip/tcp

# Show packet layers
packet.show()

# Send the packet
send(packet)

Legal Reminder

Sending crafted packets to systems you don't own is illegal. Practice on your own lab networks.