How HTTP Works: Requests, Cookies & Session Hijacking (Animated)
HTTP is the language of the web: the browser sends a request, the server sends a response. HTTP itself remembers nothing between requests, so websites use cookies to know you are logged in. Steal the cookie and you steal the session.
1. Request & response: ask for a page, get a page
After the TCP handshake, the browser sends a text request. The first line holds the method, the path and the version; headers follow.
- GET (Your laptop → Web server):
GETis the method,/index.htmlthe path. TheHostheader says which website on that server is wanted. - 200 OK (Web server → Your laptop):
200means success. Others you’ll meet daily: 301 moved, 403 forbidden, 404 not found, 500 server error.
Wireshark filter:
http.request
2. Login & cookie: how the site remembers you
The browser POSTs the login form. If the password is right, the server creates a session and sends its ID back in a Set-Cookie header.
- POST (Your laptop → Web server): On plain HTTP the form body, including the password, crosses the network as readable text.
- 302 FOUND (Web server → Your laptop): The server issues
session=8f3a1c9e7b. That random value now is your identity on this site. - GET (Your laptop → Web server): Every later request carries the cookie automatically, so the server knows it’s Priya without asking for the password again.
Wireshark filter:
http.request.method == "POST"
3. Session hijacking: attack: steal the cookie, become the user
On an open or shared Wi-Fi, an attacker can read unencrypted traffic. They don’t need the password: copying the session cookie is enough.
- GET (Your laptop → Web server): Priya browses normally over HTTP.
- SNIFFED (Router → Attacker): The attacker’s sniffer sees the same packet and extracts the cookie.
- GET (Attacker → Web server): The attacker sends a request with Priya’s cookie from their own machine.
- 200 OK (Web server → Attacker): The server cannot tell the difference. The attacker is inside the account without ever knowing the password.
Wireshark filter:
http.cookie contains "session"
4. Https & safe cookies: defence: encrypt it and lock the cookie
HTTPS encrypts the whole exchange, and cookie flags stop the browser from ever sending the cookie insecurely.
- HTTPS (Your laptop → Web server): The same request, now inside TLS.
- SNIFFED (Router → Attacker): The sniffer still captures the packet, but it is unreadable. No cookie, no password.
Server response header:
Set-Cookie: session=…; Secure; HttpOnly; SameSite=Lax Strict-Transport-Security: max-age=31536000
Practise this in a real lab
Intercept and edit real requests in Burp Suite, replay a stolen session cookie in the lab, then fix the application properly.
Explore ER Segment training →FAQ
What is the difference between GET and POST?
GET asks for a resource and should not change anything. POST sends data to the server, such as a login form.
What do HTTP status codes mean?
2xx success, 3xx redirect, 4xx the client made an error (404 not found, 401 unauthorised), 5xx the server failed.
What do HttpOnly and Secure cookie flags do?
Secure sends the cookie only over HTTPS. HttpOnly hides it from JavaScript, which limits theft through XSS.