Practice library / Web applications and APIs
Workbook · Easy · 3 hours
HTTP & Web Requests
How HTTP works: methods, headers, cookies, proxies, and Burp basics.
On this page 5 sections
HTTP is the protocol that every web attack rides on. Every form submission, every API call and every page view is a request and a response that follow this same text-based format. A tester who reads HTTP by eye sees the flaw that a browser hides inside a rendered page. This workbook covers the methods, headers, status codes and cookies that make the protocol work, and uses curl as the one tool that shows the raw exchange without guessing. The parts fit together because almost every web finding — CSRF, session fixation, missing security headers, weak redirects — is a misuse of one of them. You cannot report a flaw that you cannot read.
What You'll Learn
- Read an HTTP request and an HTTP response line by line
- Send requests with
curland choose the correct method - Explain the headers that matter for security and for debugging
- Interpret status codes, redirects and error pages
- Trace how a cookie creates a session, and read its security flags
- Send query and body parameters in the correct encoding
About This Workbook
Every web vulnerability is a flaw in how a server handles an HTTP request, or in how a browser handles a response. If you read HTTP fluently, you see the flaw. If you do not, you only see the page.
This workbook teaches the protocol with one tool: curl. curl shows you exactly what is sent and received. A browser hides most of it.
Authorised targets only. Send requests only to systems you own or have written permission to test. In this workbook, example.com is a public page for harmless GET and HEAD requests. 10.0.0.5 stands for a lab VM that you control, for example Metasploitable 2 or a DVWA install. Do not run the commands against any other site.
Setup. You need a terminal with curl 7.68 or newer. Check it:
curl --version | head -1curl 8.5.0 (x86_64-pc-linux-gnu) libcurl/8.5.0 OpenSSL/3.0.13 zlib/1.3Your lab VM. This website hosts no targets, no virtual machines and no lab files. 10.0.0.5 is an example address: replace it with the address of a VM or container that you run on your own computer. That one host needs two parts. The first is a small notes application. It has /api/notes, allows GET, POST and OPTIONS (not DELETE), holds note 1 with the text buy milk, and answers / with 200, /admin with 403, and /login.php and /nope with 404. You write this small application yourself, in any language. The second is DVWA (Damn Vulnerable Web Application, by the DVWA team on GitHub; it runs with docker compose), reached at /dvwa/ over plain HTTP with the login admin and password. Your header values, cookie values and tokens differ from the output shown. Take a snapshot of the VM, or note the container state, before you start.
Later chapters link to practice: the Introduction to Web Applications workbook for the architecture around HTTP, and the lab Burp Suite Basics to repeat these requests in a proxy.
Chapter 1 — Request & Response
Objectives
- Name the parts of a request and a response
- Explain why HTTP is stateless
- Show the raw exchange with
curl -v - Tell HTTP/1.1, HTTP/2 and HTTP/3 apart
Explanation
HTTP (HyperText Transfer Protocol) is a text-based protocol. A client (a browser, curl, a mobile app) sends a request. A server sends back a response. One request gets one response.
HTTP is stateless. The server does not remember the last request. Every request must carry all the data that the server needs. Chapter 3 shows how cookies add memory on top.
HTTPS is HTTP inside a TLS tunnel. The messages are the same. Only the transport is encrypted. A network observer sees the server name and the size of the data. The observer does not see the path, headers or body.
A request has four parts:
| Part | Example | Meaning |
|---|---|---|
| Request line | GET /login?next=/home HTTP/1.1 | Method, path with query string, version |
| Headers | Host: example.com | Metadata, one Name: value per line |
| Blank line | (empty) | Ends the headers |
| Body | user=alice&pass=... | Optional data (used with POST, PUT) |
A response has the same shape:
| Part | Example | Meaning |
|---|---|---|
| Status line | HTTP/1.1 200 OK | Version, status code, reason text |
| Headers | Content-Type: text/html | Metadata about the response |
| Blank line | (empty) | Ends the headers |
| Body | <html>... | The content |
A URL has parts too. In https://shop.example.com:8443/items/7?sort=price#reviews:
httpsis the scheme.shop.example.comis the host and8443the port (the default is 80 for HTTP and 443 for HTTPS)./items/7is the path.sort=priceis the query string.reviewsis the fragment. The browser keeps the fragment. It is never sent to the server.
Versions. HTTP/1.1 is text. HTTP/2 is binary and sends many requests over one connection. HTTP/3 uses QUIC over UDP. The meaning of methods, headers and status codes is the same in all three. curl shows HTTP/2 messages in the HTTP/1.1 text form, so you can read them.
Worked example
Send a request with -v (verbose). Lines that start with > are sent. Lines that start with < are received. Lines that start with * are connection notes from curl.
curl -v --http1.1 https://example.com/ -o /dev/null* Connected to example.com (93.184.216.34) port 443
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384
> GET / HTTP/1.1
> Host: example.com
> User-Agent: curl/8.5.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Type: text/html; charset=UTF-8
< Cache-Control: max-age=604800
< Content-Length: 1256
<The output differs a little on every run. Read it as follows:
GET / HTTP/1.1is the request line. The method isGET, the path is/.Hosttells the server which site you want. One IP address often serves many sites, andHostselects the site.User-Agentnames the client. A client can set any value, so a server cannot trust it.HTTP/1.1 200 OKis the status line. The request worked.-o /dev/nulldiscards the body so the headers stay readable.
Show only the response headers with -I. This sends a HEAD request (see Chapter 2):
curl -sI https://example.com/HTTP/2 200
content-type: text/html
etag: "3147526947"
cache-control: max-age=604800
content-length: 1256The line starts with HTTP/2: the server chose HTTP/2 by itself. Header names are lower case in HTTP/2. Header names are not case sensitive in any version.
A browser and curl send different User-Agent and Accept headers, and a server can answer them differently. When a page behaves differently in curl, compare the headers first.
Practice questions
- Which part of a request ends the headers?
- A user opens
https://example.com/a?x=1#top. Which of/a,x=1andtopdo the server logs show? - Why does a server need the
Hostheader when the client already used its IP address? - A colleague says: "HTTPS hides the URL from the network". Is that fully correct?
Answers
- The blank line. Everything after it is the body.
/aandx=1. The fragmenttopstays in the browser. Because the query string is logged, never put secrets in it.- One IP address can host many sites. The
Hostheader says which one the client wants. - The path and query are hidden. The server name is still visible (in the DNS lookup and in the TLS handshake). So the statement is only partly correct.
Chapter 2 — Methods & Headers
Objectives
- Choose the correct method for a task and know which are safe
- Send
GET,POST,PUT,DELETE,HEADandOPTIONSwithcurl - Read the headers that matter for security
- Set the correct
Content-Typefor a body
Explanation
The method says what the client wants to do with the resource.
| Method | Use | Safe? | Has body? |
|---|---|---|---|
GET | Read a resource | Yes | No |
HEAD | Same as GET, but headers only | Yes | No |
POST | Send data to be processed (form, create) | No | Yes |
PUT | Replace a resource with the body | No | Yes |
PATCH | Change part of a resource | No | Yes |
DELETE | Remove a resource | No | Rare |
OPTIONS | Ask which methods the server allows | Yes | No |
Safe means the request must not change anything on the server. A GET that deletes data is a design fault. It also lets a harmful image tag or link trigger the action (this is the base of a CSRF attack).
A server can allow only some methods on a path. A path that allows PUT or DELETE for anonymous users is a finding. Find the allowed methods with OPTIONS, then test only the paths in your scope.
Headers carry the metadata. The important ones fall into groups.
| Header | Direction | Why it matters |
|---|---|---|
Host | Request | Selects the site |
User-Agent | Request | Names the client. Easy to fake |
Accept | Request | Formats the client can read |
Authorization | Request | Credentials (Basic, Bearer) |
Cookie | Request | Sends the cookies back |
Referer | Request | The page that linked here (the spelling is historic) |
Content-Type | Both | Format of the body |
Content-Length | Both | Size of the body in bytes |
Location | Response | Where a redirect goes |
Set-Cookie | Response | Asks the browser to store a cookie |
Server, X-Powered-By | Response | Names the software. Information leak |
Cache-Control | Response | Who may store the response and for how long |
The security headers are response headers that tell the browser to protect the user:
| Header | Protects against |
|---|---|
Strict-Transport-Security | Downgrade to plain HTTP |
Content-Security-Policy | Cross-site scripting and unwanted resources |
X-Content-Type-Options: nosniff | The browser guessing a file type |
X-Frame-Options or CSP frame-ancestors | Clickjacking (the page inside a hostile frame) |
Referrer-Policy | Leaking URLs to other sites |
A missing header is a hardening gap. It is not a vulnerability by itself. Report it with a low rating and a one-line fix.
Content types. Content-Type tells the receiver how to parse the body. A wrong type causes parser errors, and sometimes security gaps.
| Content-Type | Body looks like |
|---|---|
application/x-www-form-urlencoded | user=alice&role=staff (the default for HTML forms) |
application/json | {"user":"alice","role":"staff"} |
multipart/form-data | Parts with boundaries (file uploads) |
text/html | A web page |
Worked example
All requests here go to the lab VM 10.0.0.5. It runs a small test application that you control.
1. Ask what the server allows.
curl -i -X OPTIONS http://10.0.0.5/api/notesHTTP/1.1 204 No Content
Allow: GET, POST, OPTIONS
Content-Length: 0The path allows GET and POST. It does not allow PUT or DELETE.
2. Read with GET.
curl -i http://10.0.0.5/api/notes/1HTTP/1.1 200 OK
Content-Type: application/json
Server: Apache/2.4.7 (Ubuntu)
X-Powered-By: PHP/5.3.10
{"id":1,"text":"buy milk"}The Server and X-Powered-By lines give the exact software and version. An attacker looks up known flaws for these versions. Remove both headers in production.
3. Create with POST and a JSON body. -d sends the body and makes the method POST. -H sets a header.
curl -i -H 'Content-Type: application/json' \
-d '{"text":"call the bank"}' http://10.0.0.5/api/notesHTTP/1.1 201 Created
Location: /api/notes/2
Content-Type: application/json
{"id":2,"text":"call the bank"}201 Created and Location tell you where the new resource is.
4. Try a method that the server does not allow.
curl -i -X DELETE http://10.0.0.5/api/notes/2HTTP/1.1 405 Method Not Allowed
Allow: GET, POST, OPTIONSThe server refuses and lists the methods it accepts. This is correct behaviour.
5. Set your own headers. Change the User-Agent and add a custom header:
curl -s -H 'User-Agent: KaliRange-Workbook' -H 'X-Test: 1' \
http://10.0.0.5/ -o /dev/null -w '%{http_code}\n'200-s hides the progress bar. -w '%{http_code}\n' prints only the status code after the transfer. Use this form in scripts.
6. Check the security headers of a response. Filter the headers with grep:
curl -sI https://example.com/ | grep -i -E 'strict-transport|content-security|x-frame|x-content-type' \
|| echo "no security headers found"no security headers foundThis page sends none of them. For a real site, the report line is: "Add Strict-Transport-Security: max-age=31536000 and X-Content-Type-Options: nosniff."
Practice questions
- A search form changes the data on the server when you submit it with
GET. Name the two problems. - Which
curlcommand sends{"a":1}as JSON tohttp://10.0.0.5/api/x? - A response contains
Server: nginx/1.18.0. Why is this a small finding? - What does
curl -s -o /dev/null -w '%{http_code}' URLprint?
Answers
- A
GETmust be safe, so the design is wrong. Also, links, images and prefetching can trigger the change without the user's intent, and the URL is stored in logs and history. curl -H 'Content-Type: application/json' -d '{"a":1}' http://10.0.0.5/api/x- The version helps an attacker choose known flaws. The fix is to hide the version (
server_tokens off;in nginx) and to patch. Hiding is not a replacement for patching. - Only the three-digit status code, for example
200.
Chapter 3 — State & Parameters
Objectives
- Explain how a cookie and a session ID give HTTP a memory
- Read the flags of a
Set-Cookieheader - Log in with
curland keep the cookie - Send parameters in the query string and in the body
- Apply and decode URL encoding
- Read status codes in groups and follow redirects
Explanation
Cookies and sessions. After a login, the server needs to know "this request is from Alice" on every later request. The server creates a session: a record on the server with a random, long session ID. It sends the ID to the browser in a Set-Cookie header. The browser sends it back in a Cookie header on every request to that site.
The session ID is a key. Whoever holds it is the user. That is why attackers try to steal it (cross-site scripting, network capture, a leaked log).
A cookie has flags. They are a basic defence:
| Flag | Meaning | Protects against |
|---|---|---|
HttpOnly | JavaScript cannot read the cookie | Theft of the cookie by injected scripts |
Secure | Sent only over HTTPS | Capture on plain HTTP |
SameSite=Lax or Strict | Not sent on most cross-site requests | CSRF |
Path, Domain | Limit which URLs get the cookie | Wide exposure |
Max-Age, Expires | Lifetime. No value means a session cookie | Long-lived stolen cookies |
A session ID must also be random, long and new after login. A server that keeps the same ID before and after login has a session fixation flaw.
Parameters send data from the client. There are two main places:
- Query string: after
?in the URL, asname=valuepairs joined by&. It is visible in logs, history and theRefererheader. Use it for searches and filters. Never put passwords or tokens in it. - Body: after the headers. Use it for forms, logins and uploads. The body is not in the URL, but it is not secret either. Only HTTPS protects it.
Parts of the path can also carry values (/items/7). A web application treats all of these as untrusted input.
URL encoding. A URL can hold only certain characters. Other characters become % plus two hex digits:
| Character | Encoded |
|---|---|
| space | %20 (or + in form data) |
& | %26 |
= | %3D |
/ | %2F |
< and > | %3C and %3E |
% itself | %25 |
Encoding stops & or = inside a value from breaking the parameter structure. Servers and filters decode input, sometimes more than once. A check that reads the data before decoding can be bypassed. This is why defenders validate the decoded value.
Status codes. The first digit gives the class:
| Class | Meaning | Common codes |
|---|---|---|
| 1xx | Information | 101 Switching Protocols |
| 2xx | Success | 200 OK, 201 Created, 204 No Content |
| 3xx | Redirect | 301 Moved Permanently, 302 Found, 304 Not Modified |
| 4xx | Client error | 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 405, 429 Too Many Requests |
| 5xx | Server error | 500 Internal Server Error, 502 Bad Gateway, 503 Service Unavailable |
Two codes are often confused. 401 means "you are not authenticated" (log in). 403 means "the server knows the request and refuses it". A 500 often means that your input reached code that did not expect it. A defender reads a rise in 4xx and 5xx in the logs as a sign of scanning or abuse.
A redirect (3xx) has a Location header. A browser follows it by itself. curl follows it only with -L. Look at each hop to see where the traffic really goes.
Worked example
The lab VM 10.0.0.5 runs DVWA (Damn Vulnerable Web Application), a deliberately weak test application. Use its documented default login only on your own copy.
1. Request a protected page without a session.
curl -i http://10.0.0.5/dvwa/index.phpHTTP/1.1 302 Found
Set-Cookie: PHPSESSID=q9v2l4r1s8m0t3k7a5b6c1d2e3; path=/; HttpOnly
Location: login.phpThe server redirects you to the login page (302). It also starts a session and sets a cookie. Check the flags. HttpOnly is present. Secure is missing because the lab uses plain HTTP, and SameSite is missing too.
2. Follow the redirect and save the cookie. -c writes the cookies to a file (the cookie jar). -b sends them. -L follows redirects. Use the same file for both.
curl -s -L -c jar.txt -b jar.txt -o /dev/null -w '%{http_code} %{url_effective}\n' \
http://10.0.0.5/dvwa/index.php200 http://10.0.0.5/dvwa/login.phpYou ended on login.php with status 200. %{url_effective} shows the last URL after all redirects.
3. Read the login form. Look at the form field names:
curl -s -b jar.txt http://10.0.0.5/dvwa/login.php | grep -i '<input'<input type="text" class="loginInput" size="20" name="username"><br />
<input type="password" class="loginInput" AUTOCOMPLETE="off" size="20" name="password"><br />
<input type="submit" value="Login" name="Login">
<input type='hidden' name='user_token' value='0f1e2d3c4b5a69788796a5b4c3d2e1f0' />The form needs username, password, Login and a hidden user_token. The token is an anti-CSRF token: the server checks that the form came from its own page. Copy the token value from your output.
4. Send the login as a POST body. Use --data-urlencode so that curl encodes each value for you:
curl -i -b jar.txt -c jar.txt \
--data-urlencode 'username=admin' \
--data-urlencode 'password=password' \
--data-urlencode 'Login=Login' \
--data-urlencode 'user_token=0f1e2d3c4b5a69788796a5b4c3d2e1f0' \
http://10.0.0.5/dvwa/login.phpHTTP/1.1 302 Found
Location: index.php
Set-Cookie: PHPSESSID=h7x2n9p4w6y1z3c5v8b0m2l4k6; path=/; HttpOnlyThe login worked (302 to index.php). Look at the Set-Cookie line: the session ID changed after login (compare with step 1). A server must do this. If the ID stayed the same, the application would have the session fixation flaw from the explanation.
5. Use the session. Send the saved cookie to a page that needs it:
curl -s -b jar.txt -o /dev/null -w '%{http_code}\n' http://10.0.0.5/dvwa/index.php200Without -b jar.txt the same request returns 302. The cookie is the whole proof of identity. Treat your own jar.txt as a secret: delete it when you finish.
6. Query parameters and encoding. Send two query parameters with -G (put the data in the URL) and --data-urlencode:
curl -s -G -b jar.txt -o /dev/null -w '%{url_effective}\n' \
--data-urlencode 'id=1 & 2' \
--data-urlencode 'Submit=Submit' \
http://10.0.0.5/dvwa/vulnerabilities/sqli/http://10.0.0.5/dvwa/vulnerabilities/sqli/?id=1%20%26%202&Submit=SubmitThe space became %20 and & became %26. The & inside the value did not split the parameter. Decode a value by hand when you read a log:
printf '%b\n' "$(echo '%3Cb%3Ehi%3C%2Fb%3E' | sed 's/%/\\x/g')"<b>hi</b>7. Read status codes in a loop. Check which paths exist in your own lab. The -w format prints one line per path:
for p in / /login.php /admin /nope; do
curl -s -o /dev/null -w "%{http_code} $p\n" http://10.0.0.5$p
done200 /
404 /login.php
403 /admin
404 /nopeRead this like a defender. /admin answers 403: it exists, but access is denied. A 404 says nothing exists there. A server that answers 403 for existing paths and 404 for missing paths tells a scanner which paths are real. Some hardened servers return the same code for both.
Debugging rule. When a request fails, run it again with curl -v. Compare the status code, the Location and the Set-Cookie lines before you change anything else.
Practice questions
- A cookie has
HttpOnlybut noSecure. Which attack does it still allow, and on which kind of network? - A login form posts the password in the query string. Name two places where it will leak.
- Decode
%2Fetc%2Fhosts%3Fa%3D1. - A response is
401. Another is403. What does each tell the client? - After login the session ID does not change. Which flaw is this, and what is the fix?
- What does
curl -Ldo, and why can it hide a problem?
Answers
HttpOnlystops scripts reading the cookie. WithoutSecure, the browser sends the cookie over plain HTTP too. Anyone who can read the traffic (for example on an open Wi-Fi network) can capture it. Fix: addSecureand use HTTPS everywhere, withStrict-Transport-Security.- The server access log, the browser history, proxy logs, and the
Refererheader sent to other sites. Send passwords in aPOSTbody over HTTPS. /etc/hosts?a=1401: authentication is missing or wrong. The client can log in and try again.403: the server understood the request and refuses it. A new login with the same rights does not help.- Session fixation. An attacker who plants a known ID before login gets the logged-in session. Fix: create a new session ID at login, and discard the old one.
- It follows
Locationheaders automatically. You only see the last response, and you can miss a redirect that sets a cookie or leaks data on the way. Use-vor-iwithout-Lto inspect each hop.
Final Review
Answer without notes. Then run the commands again on your lab VM to check.
- Write a request line and a
Hostheader for the path/items?id=7onshop.example.com. - Which method and header send
{"qty":2}to an API? - Which
curloptions log in, keep the cookie, and then call a second page with it? - List three response headers you check on every web application, and why.
- Name one status code for each class: 2xx, 3xx, 4xx, 5xx.
Answers
GET /items?id=7 HTTP/1.1andHost: shop.example.com.POST(orPUTto replace) withContent-Type: application/json, and-d '{"qty":2}'.-c jar.txton the login request to save, then-b jar.txton every next request. Add-Lto follow redirects.- For example
Set-Cookie(flags),Strict-Transport-Security(forces HTTPS),Content-Security-Policy(limits scripts).ServerandX-Powered-Byalso leak versions. - For example
200,302,403,500.
Next. Repeat these requests in a proxy: the lab Burp Suite Basics shows each request and lets you change it before it is sent. Then read Introduction to Web Applications for the server side of the exchange.
Sign in to track progress and send feedback.
Related
This workbook is extra practice for the course Web applications and APIs. Do the lessons first.Open the course