Build a Python Network Sniffer That Flags Plaintext Passwords on Your Own Network (Full Code)
Here is an uncomfortable truth: on many home and office networks, passwords still travel in plaintext. Old admin panels, FTP logins, legacy IoT devices and misconfigured apps send credentials that anyone on the same network can read with a packet sniffer. Today we will build one — in Python, on your own network — to find those leaks before an attacker does.
The Tool: Scapy
We will use Scapy, Python’s packet manipulation library. Install it with pip install scapy. Scapy can capture live packets, decode their layers (Ethernet, IP, TCP, HTTP) and let you inspect the payload as text. Only run this on a network you own or have written permission to test — sniffing someone else’s traffic without permission is illegal in most countries.
The Code
from scapy.all import sniff, TCP, Rawimport re# Patterns that suggest credentials in plaintextPATTERNS = { "password": re.compile(rb"(password|passwd|pwd)[\"'\s:=]+([^\s&\"']+)", re.I), "basic_auth": re.compile(rb"Authorization:\s*Basic\s+([A-Za-z0-9+/=]+)", re.I), "ftp_user": re.compile(rb"USER\s+(\S+)", re.I), "ftp_pass": re.compile(rb"PASS\s+(\S+)", re.I),}def check_packet(pkt): if not pkt.haslayer(Raw): return payload = bytes(pkt[Raw].load) src = pkt["IP"].src dst = pkt["IP"].dst sport = pkt[TCP].sport dport = pkt[TCP].dport for name, pattern in PATTERNS.items(): match = pattern.search(payload) if match: print(f"\n[!] PLAINTEXT CREDENTIAL on {src}:{sport} -> {dst}:{dport}") print(f" Type: {name}") print(f" Match: {match.group(0)[:80]!r}") print(" Fix: switch this service to TLS/SSH/SFTP immediately.")if __name__ == "__main__": print("Sniffing your own network for plaintext credentials...") print("Press Ctrl+C to stop.\n") # Only capture unencrypted protocols where credentials leak sniff(filter="tcp port 21 or tcp port 80 or tcp port 110 or tcp port 143", prn=check_packet, store=False)
How It Works
- Capture filter — we only listen on ports where plaintext credentials appear: FTP (21), HTTP (80), POP3 (110) and IMAP (143).
- Pattern matching — regular expressions scan each packet’s payload for password fields, HTTP Basic Auth headers and FTP login commands.
- Alert, don’t store — the script prints a warning with the source and destination, but never saves the credential itself. We are finding the problem, not collecting passwords.
Running It
Save as sniff_creds.py and run sudo python3 sniff_creds.py (root is needed to capture packets). Then log into an old HTTP admin panel or an FTP server on your own network and watch the alert appear. That visible proof is worth more than any lecture about encryption.
What To Do With What You Find
- HTTP logins → HTTPS. Put the service behind TLS with a free Let’s Encrypt certificate.
- FTP → SFTP or FTPS. FTP sends everything in plaintext by design.
- POP3/IMAP → use the TLS versions (ports 995/993) and disable plaintext auth.
- Basic Auth over HTTP is just Base64 — anyone can decode it. It is only safe over HTTPS.
Level Up
- Log findings to a file with timestamps instead of printing them.
- Add a check for session cookies sent over HTTP — those are just as stealable as passwords.
- Pair this with a TLS audit: scan your own services and list which ones still accept plaintext.
You just built a defensive network tool that proves a point no slide deck can: if your network can see it, so can an attacker. Fix the plaintext, and the sniffer goes quiet.



Comments
Post a Comment