Courses3 levels
Level 1 · Foundations11 courses
Level 2 · Core5 courses
Level 3 · Advanced5 courses
Labs8 topics
Library Practice exams AI Range Pricing Start free

Practice library / Web applications and APIs

Workbook · Easy · 3 hours

HTTP & Web Requests

How HTTP works: methods, headers, cookies, proxies, and Burp basics.

  • http
  • headers
  • cookies
  • status-codes
  • burp-suite
On this page 5 sections
  1. ·About This Workbook
  2. ·Chapter 1 — Request & Response
  3. ·Chapter 2 — Methods & Headers
  4. ·Chapter 3 — State & Parameters
  5. ·Final Review

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 curl and 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 -1
curl 8.5.0 (x86_64-pc-linux-gnu) libcurl/8.5.0 OpenSSL/3.0.13 zlib/1.3

Your 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:

PartExampleMeaning
Request lineGET /login?next=/home HTTP/1.1Method, path with query string, version
HeadersHost: example.comMetadata, one Name: value per line
Blank line(empty)Ends the headers
Bodyuser=alice&pass=...Optional data (used with POST, PUT)

A response has the same shape:

PartExampleMeaning
Status lineHTTP/1.1 200 OKVersion, status code, reason text
HeadersContent-Type: text/htmlMetadata 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:

  • https is the scheme.
  • shop.example.com is the host and 8443 the port (the default is 80 for HTTP and 443 for HTTPS).
  • /items/7 is the path.
  • sort=price is the query string.
  • reviews is 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.1 is the request line. The method is GET, the path is /.
  • Host tells the server which site you want. One IP address often serves many sites, and Host selects the site.
  • User-Agent names the client. A client can set any value, so a server cannot trust it.
  • HTTP/1.1 200 OK is the status line. The request worked.
  • -o /dev/null discards 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: 1256

The 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

  1. Which part of a request ends the headers?
  2. A user opens https://example.com/a?x=1#top. Which of /a, x=1 and top do the server logs show?
  3. Why does a server need the Host header when the client already used its IP address?
  4. A colleague says: "HTTPS hides the URL from the network". Is that fully correct?
Answers
  1. The blank line. Everything after it is the body.
  2. /a and x=1. The fragment top stays in the browser. Because the query string is logged, never put secrets in it.
  3. One IP address can host many sites. The Host header says which one the client wants.
  4. 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, HEAD and OPTIONS with curl
  • Read the headers that matter for security
  • Set the correct Content-Type for a body

Explanation

The method says what the client wants to do with the resource.

MethodUseSafe?Has body?
GETRead a resourceYesNo
HEADSame as GET, but headers onlyYesNo
POSTSend data to be processed (form, create)NoYes
PUTReplace a resource with the bodyNoYes
PATCHChange part of a resourceNoYes
DELETERemove a resourceNoRare
OPTIONSAsk which methods the server allowsYesNo

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.

HeaderDirectionWhy it matters
HostRequestSelects the site
User-AgentRequestNames the client. Easy to fake
AcceptRequestFormats the client can read
AuthorizationRequestCredentials (Basic, Bearer)
CookieRequestSends the cookies back
RefererRequestThe page that linked here (the spelling is historic)
Content-TypeBothFormat of the body
Content-LengthBothSize of the body in bytes
LocationResponseWhere a redirect goes
Set-CookieResponseAsks the browser to store a cookie
Server, X-Powered-ByResponseNames the software. Information leak
Cache-ControlResponseWho may store the response and for how long

The security headers are response headers that tell the browser to protect the user:

HeaderProtects against
Strict-Transport-SecurityDowngrade to plain HTTP
Content-Security-PolicyCross-site scripting and unwanted resources
X-Content-Type-Options: nosniffThe browser guessing a file type
X-Frame-Options or CSP frame-ancestorsClickjacking (the page inside a hostile frame)
Referrer-PolicyLeaking 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-TypeBody looks like
application/x-www-form-urlencodeduser=alice&role=staff (the default for HTML forms)
application/json{"user":"alice","role":"staff"}
multipart/form-dataParts with boundaries (file uploads)
text/htmlA 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/notes
HTTP/1.1 204 No Content
Allow: GET, POST, OPTIONS
Content-Length: 0

The 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/1
HTTP/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/notes
HTTP/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/2
HTTP/1.1 405 Method Not Allowed
Allow: GET, POST, OPTIONS

The 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 found

This 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

  1. A search form changes the data on the server when you submit it with GET. Name the two problems.
  2. Which curl command sends {"a":1} as JSON to http://10.0.0.5/api/x?
  3. A response contains Server: nginx/1.18.0. Why is this a small finding?
  4. What does curl -s -o /dev/null -w '%{http_code}' URL print?
Answers
  1. A GET must 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.
  2. curl -H 'Content-Type: application/json' -d '{"a":1}' http://10.0.0.5/api/x
  3. 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.
  4. 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-Cookie header
  • Log in with curl and 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:

FlagMeaningProtects against
HttpOnlyJavaScript cannot read the cookieTheft of the cookie by injected scripts
SecureSent only over HTTPSCapture on plain HTTP
SameSite=Lax or StrictNot sent on most cross-site requestsCSRF
Path, DomainLimit which URLs get the cookieWide exposure
Max-Age, ExpiresLifetime. No value means a session cookieLong-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, as name=value pairs joined by &. It is visible in logs, history and the Referer header. 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:

CharacterEncoded
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:

ClassMeaningCommon codes
1xxInformation101 Switching Protocols
2xxSuccess200 OK, 201 Created, 204 No Content
3xxRedirect301 Moved Permanently, 302 Found, 304 Not Modified
4xxClient error400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 405, 429 Too Many Requests
5xxServer error500 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.php
HTTP/1.1 302 Found
Set-Cookie: PHPSESSID=q9v2l4r1s8m0t3k7a5b6c1d2e3; path=/; HttpOnly
Location: login.php

The 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.php
200 http://10.0.0.5/dvwa/login.php

You 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.php
HTTP/1.1 302 Found
Location: index.php
Set-Cookie: PHPSESSID=h7x2n9p4w6y1z3c5v8b0m2l4k6; path=/; HttpOnly

The 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.php
200

Without -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=Submit

The 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
done
200 /
404 /login.php
403 /admin
404 /nope

Read 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

  1. A cookie has HttpOnly but no Secure. Which attack does it still allow, and on which kind of network?
  2. A login form posts the password in the query string. Name two places where it will leak.
  3. Decode %2Fetc%2Fhosts%3Fa%3D1.
  4. A response is 401. Another is 403. What does each tell the client?
  5. After login the session ID does not change. Which flaw is this, and what is the fix?
  6. What does curl -L do, and why can it hide a problem?
Answers
  1. HttpOnly stops scripts reading the cookie. Without Secure, 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: add Secure and use HTTPS everywhere, with Strict-Transport-Security.
  2. The server access log, the browser history, proxy logs, and the Referer header sent to other sites. Send passwords in a POST body over HTTPS.
  3. /etc/hosts?a=1
  4. 401: 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.
  5. 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.
  6. It follows Location headers automatically. You only see the last response, and you can miss a redirect that sets a cookie or leaks data on the way. Use -v or -i without -L to inspect each hop.

Final Review

Answer without notes. Then run the commands again on your lab VM to check.

  1. Write a request line and a Host header for the path /items?id=7 on shop.example.com.
  2. Which method and header send {"qty":2} to an API?
  3. Which curl options log in, keep the cookie, and then call a second page with it?
  4. List three response headers you check on every web application, and why.
  5. Name one status code for each class: 2xx, 3xx, 4xx, 5xx.
Answers
  1. GET /items?id=7 HTTP/1.1 and Host: shop.example.com.
  2. POST (or PUT to replace) with Content-Type: application/json, and -d '{"qty":2}'.
  3. -c jar.txt on the login request to save, then -b jar.txt on every next request. Add -L to follow redirects.
  4. For example Set-Cookie (flags), Strict-Transport-Security (forces HTTPS), Content-Security-Policy (limits scripts). Server and X-Powered-By also leak versions.
  5. 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