hackingDNA
← Attack techniques

Session Sniffing

intermediatePrimary Method

Intercepting communication between user and server to capture session cookies and IDs. The most common method used in session hijacking attacks.

Detailed Overview

Session sniffing involves monitoring network traffic to capture session tokens. Attackers position themselves between the user and server, typically on unsecured networks like public Wi-Fi. The technique exploits unencrypted HTTP traffic or weak SSL/TLS implementations. Modern attackers use sophisticated packet analyzers to filter and extract session identifiers from live network streams.

Prevention Strategies

  • 01Always use HTTPS with strong TLS configuration
  • 02Implement certificate pinning in mobile applications
  • 03Avoid using public Wi-Fi for sensitive transactions
  • 04Use VPN connections when on untrusted networks
  • 05Enable HSTS (HTTP Strict Transport Security) headers

Tools

Common software used to explore or defend against this technique.

  • Wireshark
  • tcpdump
  • Burp Suite
  • Fiddler

BYO — Build your code

Programmatic approaches that recreate what tools do — for learning, detection, and hardening on systems you are authorized to test.

01

Filter HTTP cookies with Scapy

python

Educational packet filter that looks for Cookie headers on a local lab network you control.

from scapy.all import sniff, Raw

def has_cookie(pkt):
    if pkt.haslayer(Raw):
        payload = bytes(pkt[Raw].load).decode("latin-1", errors="ignore")
        if "Cookie:" in payload:
            print(payload.split("Cookie:", 1)[1].split("\r\n", 1)[0].strip())

# Lab only: interface + BPF filter you own
sniff(iface="eth0", filter="tcp port 80", prn=has_cookie, store=False)
02

Parse pcap for Set-Cookie

python

Offline analysis of a capture file to inventory session-related cookies.

from scapy.all import rdpcap, Raw

def cookie_names(pcap_path: str) -> set[str]:
    names: set[str] = set()
    for pkt in rdpcap(pcap_path):
        if not pkt.haslayer(Raw):
            continue
        text = bytes(pkt[Raw].load).decode("latin-1", errors="ignore")
        for line in text.split("\r\n"):
            if line.lower().startswith("set-cookie:"):
                names.add(line.split(":", 1)[1].split("=", 1)[0].strip())
    return names

print(cookie_names("lab-capture.pcap"))

Educational Videos

Curated collection of tutorials and explanations to deepen your understanding.

01

Session Hijacking Explained - How Hackers Steal Your Sessions

https://www.youtube.com/watch?v=1pwzuFm-cUo
02

Network Packet Sniffing Tutorial with Wireshark

https://www.youtube.com/watch?v=TkCSr30UojM
03

Session Sniffing Attack Demo - Complete Walkthrough

https://www.youtube.com/watch?v=HcrQy0C-hEA
04

How HTTPS Protects Against Session Sniffing

https://www.youtube.com/watch?v=w0QbnxKRD0w
05

Preventing Session Hijacking - Security Best Practices

https://www.youtube.com/watch?v=vRBihr41JTo

Related Techniques