HTTP in Cleartext versus HTTPS
Plain HTTP sends everything as readable text: the URL, the headers, the cookies, the form fields. Anyone on the path (the Wi-Fi next to you, a compromised router, an ARP spoofer on the LAN, an ISP) can read it and change it. That was acceptable for public documents in 1996. It is not acceptable for a login form, and today it is not acceptable for anything, because an attacker who can change one HTTP response can inject script into the page. This lesson reads a cleartext login out of the sample capture, as an analyst checking the exposure would, and then shows what HTTPS changes on the wire. HTTP itself is covered in HTTP/1.1.
The capture is the synthetic http.pcap: a lab client 10.10.0.5 logs in to www.lab.test (10.10.0.10) with the lab-only password lab-only-123. Reading it is the point of the lesson; reading real people's traffic needs authorisation.
Reading the login off the wire
tcpdump -A prints payloads as ASCII (the IP and TCP headers come out as a few junk characters before the text, which is why grep -o cuts out just the interesting parts). A filter for segments with data going to port 80 is enough to see both requests:
tcpdump -q -nn -A -r $SAMPLES/pcap/http.pcap 'tcp dst port 80 and tcp[tcpflags] & tcp-push != 0' 2>/dev/null | grep -a -o -E '(GET|POST) /[^ ]* HTTP/1\.1|^Host: .*|^user=.*'GET / HTTP/1.1
Host: www.lab.test
POST /login HTTP/1.1
Host: www.lab.test
user=alice&password=lab-only-123
Wireshark's "Follow TCP stream" puts both directions of one connection together. tshark -z follow does the same in the terminal; stream 1 is the login:
tshark -r $SAMPLES/pcap/http.pcap -q -z follow,tcp,ascii,1
===================================================================
Follow: tcp,ascii
Filter: tcp.stream eq 1
Node 0: 10.10.0.5:50414
Node 1: 10.10.0.10:80
173
POST /login HTTP/1.1
Host: www.lab.test
User-Agent: lab-client/1.0
Content-Type: application/x-www-form-urlencoded
Content-Length: 32
user=alice&password=lab-only-123
114
HTTP/1.1 302 Found
Server: lab-httpd
Location: /home
Set-Cookie: session=lab42; HttpOnly
Content-Length: 0
===================================================================
Everything an attacker needs is there: the username and password in the request body, and in the response the session cookie session=lab42, which is as good as the password until the session ends. The cookie is HttpOnly (JavaScript can't read it) but not Secure, so the browser would also send it over plain HTTP.
What a defender extracts
For an exposure assessment you want a list, not a transcript: which requests carried credentials or session tokens in the clear, to which hosts. tshark's HTTP fields make that a one-liner; the urlencoded-form dissector even splits the form into keys and values.
tshark -r $SAMPLES/pcap/http.pcap -Y 'http.request or http.response' -T fields -E header=y \
-e frame.number -e ip.dst -e http.request.method -e http.request.uri -e http.response.code -e http.set_cookie
echo "--- form fields sent in cleartext:"
tshark -r $SAMPLES/pcap/http.pcap -Y 'urlencoded-form' -T fields -e ip.src -e http.host -e urlencoded-form.keyframe.number ip.dst http.request.method http.request.uri http.response.code http.set_cookie
4 10.10.0.10 GET /
6 10.10.0.5 200
14 10.10.0.10 POST /login
16 10.10.0.5 302 session=lab42; HttpOnly
--- form fields sent in cleartext:
10.10.0.5 www.lab.test user,password
Note that the second command prints only the keys (user, password), not the values. When you report a cleartext-credential finding, show that a password was exposed, not the password.
The same check in Python
When the bytes are in hand (from a sensor, a proxy log or a capture), a few lines of Python flag the same problems. The request and response below are the payloads of frames 14 and 16 of the capture.
from urllib.parse import parse_qs
request = (b"POST /login HTTP/1.1\r\nHost: www.lab.test\r\nUser-Agent: lab-client/1.0\r\n"
b"Content-Type: application/x-www-form-urlencoded\r\nContent-Length: 32\r\n\r\n"
b"user=alice&password=lab-only-123")
response = (b"HTTP/1.1 302 Found\r\nServer: lab-httpd\r\nLocation: /home\r\n"
b"Set-Cookie: session=lab42; HttpOnly\r\nContent-Length: 0\r\n\r\n")
SECRET_KEYS = {"password", "pass", "pwd", "token", "secret", "api_key"}
def split(msg):
head, _, body = msg.partition(b"\r\n\r\n")
lines = head.decode().split("\r\n")
headers = {}
for line in lines[1:]:
k, _, v = line.partition(":")
headers.setdefault(k.strip().lower(), []).append(v.strip())
return lines[0], headers, body
start, h, body = split(request)
findings = []
if h.get("content-type", [""])[0].startswith("application/x-www-form-urlencoded"):
form = parse_qs(body.decode())
exposed = sorted(k for k in form if k.lower() in SECRET_KEYS)
if exposed:
findings.append(f"credential fields over plain HTTP: {exposed} (host {h['host'][0]})")
if "authorization" in h:
findings.append("Authorization header over plain HTTP")
status, rh, _ = split(response)
for c in rh.get("set-cookie", []):
attrs = {a.strip().split("=")[0].lower() for a in c.split(";")[1:]}
missing = sorted({"secure", "httponly", "samesite"} - attrs)
findings.append(f"cookie {c.split('=')[0]!r} set over HTTP, missing attributes: {missing}")
if "strict-transport-security" not in rh:
findings.append("no Strict-Transport-Security header (it is only honoured over HTTPS anyway)")
print(start, "->", status)
for f in findings:
print(" -", f)POST /login HTTP/1.1 -> HTTP/1.1 302 Found
- credential fields over plain HTTP: ['password'] (host www.lab.test)
- cookie 'session' set over HTTP, missing attributes: ['samesite', 'secure']
- no Strict-Transport-Security header (it is only honoured over HTTPS anyway)
What HTTPS changes on the wire
With HTTPS the same exchange runs inside TLS. A passive observer still sees:
- the IP addresses and ports (
10.10.0.10:443), - the server name in the TLS ClientHello (SNI, unless Encrypted Client Hello is used; see TLS Records and the ClientHello),
- the sizes and timing of the encrypted records.
They no longer see the URL path, the headers, the cookies or the form, and they can't modify anything without the client noticing (each record is authenticated). An active attacker who redirects the connection can't present a valid certificate for www.lab.test, so the browser stops with an error.
How cleartext exposure is detected
- Network sensors: IDS rules for HTTP requests with password-like form fields or
Authorization: Basicon port 80; Zeek'shttp.loglists every cleartext request with host, URI and status. - Captures at the edge filtered with
http.request(any cleartext request at all is a finding on most corporate networks today). - Scans of your own sites: which hosts answer on port 80 with content instead of a redirect, and which cookies lack
Secure. - Browser and proxy reports: mixed-content warnings, HSTS preload checks.
How it is fixed
- Serve everything over HTTPS and make port 80 only redirect (
301to thehttps://URL), with no content and no cookies. - HSTS (
Strict-Transport-Security: max-age=31536000; includeSubDomains, RFC 6797) so browsers never try plain HTTP again for the domain, which also stops "SSL stripping" attacks that downgrade the first request; consider the preload list. - Cookie attributes:
Secure(only over HTTPS),HttpOnly,SameSite; use the__Host-prefix for session cookies. - Rotate exposed secrets: if a capture shows a credential in clear, that password and every session from the exposure window must be treated as compromised.
Pitfalls
- Redirecting to HTTPS after the login page has already been served over HTTP: the form may still post to
http://. - Setting HSTS on a test domain with
includeSubDomainsand breaking every internal HTTP-only subdomain. - Believing internal traffic doesn't need TLS. ARP spoofing, compromised hosts and mirror ports make internal networks just as observable.
Practice
1. Which frame of the capture carries the session cookie, and why is that worse than the password alone?
Frame 16, the 302 response, in Set-Cookie: session=lab42. A stolen session cookie gives immediate access without knowing the password and often bypasses MFA, which was completed before the cookie was issued.
2. Write a tshark display filter that finds HTTP Basic authentication in a capture.
http.authorization contains "Basic" (or http.authbasic, the field where Wireshark decodes the credentials). As with the form, report that it happened, not the decoded value.
3. A site sets HSTS but serves its first page over HTTP to new visitors. Is it protected?
Not on the very first visit: until the browser has seen the HSTS header over HTTPS once, an attacker can intercept the first plain-HTTP request. HSTS preloading closes that gap by shipping the domain in the browser's built-in list.
Test yourself
What could a passive observer read in the sample login exchange?
- Only the IP addresses
- The URL, headers, username, password and session cookie
- Only the password
- Nothing, HTTP is encrypted
Which cookie attribute stops the browser from sending the cookie over plain HTTP?
- HttpOnly
- Secure
- SameSite
- Path
What does HSTS protect against?
- SQL injection
- Downgrading the connection to plain HTTP (SSL stripping) after the first secure visit
- Weak passwords
- DNS amplification
Over HTTPS, which of these is still visible to a passive observer (without Encrypted Client Hello)?
- The form fields
- The URL path
- The server name in the ClientHello (SNI)
- The session cookie