learn/phase-1/p1-w2/lesson 03
Milestone 2 · lesson 3

HTTP & HTTPS: How the Web Talks

Interactive: build real HTTP requests in the HTTP Lab and capture five flags.
Lab: Just Plain Text

Follow a hint in the HTML to an undocumented endpoint and read its response.

What you'll learn

  • Explain what HTTP and HTTPS are, and the difference between them.
  • Read a URL and name each part (scheme, host, port, path, query, fragment).
  • Read an HTTP request and response, and the headers that matter.
  • Use the common methods (GET/POST/PUT/DELETE) and read status codes.
  • Understand how cookies let a stateless protocol remember you.

HTTP & HTTPS: How the Web Talks

Every time you open a web page, your browser and a web server hold a short conversation. HTTP is the language they speak. Learn to read and write it, and most of web hacking suddenly makes sense, because almost every web attack is just an unusual HTTP request.

What is HTTP?

HTTP stands for HyperText Transfer Protocol. It is the agreed set of rules browsers and servers use to move web content, HTML pages, images, videos, files, back and forth. It was created around 1989 to 1991 by Tim Berners-Lee and his team at CERN, and it is plain text, so a human can read a request or response directly.

What is HTTPS?

HTTPS (the S is for Secure) is HTTP wrapped in encryption (TLS, from the TLS lesson). It adds two guarantees:

  • Privacy , anyone sniffing the network sees only scrambled ciphertext, not your data.
  • Identity , the server proves who it is with a certificate, so you know you aren't talking to an impostor.

That is the padlock in your address bar. Always prefer HTTPS, and never send passwords over plain HTTP.

Anatomy of a URL

A URL (Uniform Resource Locator) is the address that tells the browser where and how to fetch something. A full one has several parts, though most requests use only a few:

https://admin:pass@hackingpath.com:443/view-lesson?id=1#section2
scheme
user info
host
port
path
query
fragment

Most requests use only a few of these. The scheme, host and path are the essentials.

  • Scheme , the protocol to use: https, http, ftp.
  • User info , an optional user:password@ for sites that need a login in the URL.
  • Host , the domain name (or IP) of the server, hackingpath.com.
  • Port , which port to connect to (default 80 for HTTP, 443 for HTTPS). Any port 1 to 65535 is possible.
  • Path , which resource on the server, /view-lesson.
  • Query , extra input after a ?, ?id=1 asks for the item with id 1.
  • Fragment , a #section2 jump to a spot on the page (handled by the browser, not sent to the server).

A request and a response

To load a page the browser sends a request; the server sends back a response.

An example request:

GET /lessons HTTP/1.1
Host: hackingpath.com
User-Agent: Mozilla/5.0 (HackingPath)
Accept: text/html

  • Line 1 is the request line: the method (GET), the path (/lessons), and the version (HTTP/1.1).
  • The next lines are headers, extra information for the server (which site, which browser, what it accepts).
  • A blank line marks the end of the request.

An example response:

HTTP/1.1 200 OK
Server: nginx
Content-Type: text/html
Content-Length: 137

<html><body>Welcome to Hacking Path</body></html>
  • Line 1 is the status line: the version and a status code (200 OK = success).
  • Content-Type tells the browser what kind of data follows (HTML here); Content-Length says how many bytes to expect.
  • After the blank line comes the body, the actual content you asked for.

A real example, curl against a live site

You don't need a browser to see this in action, curl prints the raw response of any site. Try it on this very page:

$ curl "https://hackingpath.com/"
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="stylesheet" href="/assets/styles-XXXXXXXX.css"/>
<title>Hacking Path: Learn ethical hacking, from zero.</title>
...

That wall of HTML is exactly what your browser receives before it renders anything, curl just skips the rendering step and shows you the raw material. Run curl -I https://hackingpath.com/ instead and you get only the response headers, no body, a fast way to check what server and technology a site is running.

Methods, the verb of the request

The method says what you intend to do. You will mostly meet four:

MethodMeaningExample
GETRead / fetch somethingOpen a page
POSTCreate a new recordSign up a user
PUTUpdate an existing recordChange your email
DELETERemove a recordDelete a photo

Status codes, the outcome

The first digit of the code tells you the category:

RangeCategoryMeaning
1xxInformationalKeep going (rare)
2xxSuccessIt worked
3xxRedirectLook somewhere else
4xxClient errorYou got it wrong
5xxServer errorThe server broke

The ones you will see most:

  • 200 OK , success. 201 Created , a new record was made.
  • 301/302 , moved (permanent / temporary redirect).
  • 400 Bad Request , something was wrong or missing in your request.
  • 401 Unauthorized , log in first. 403 Forbidden , you're logged in but still not allowed.
  • 404 Not Found , no such page. 405 Method Not Allowed , wrong method for this route.
  • 500 Internal Server Error , the server crashed. 503 Service Unavailable , overloaded or down for maintenance.

Headers, the extra details

Headers carry information alongside the request or response. A few worth knowing:

  • Request , Host (which site, when one server hosts many), User-Agent (your browser), Content-Length (size of the data you're sending), Cookie (see below).
  • Response , Set-Cookie (store this cookie), Content-Type (what kind of data), Content-Length (how big), Cache-Control (how long to cache).

Cookies, how the web remembers you

HTTP is stateless: each request stands alone, the server forgets you the instant it replies. So how do sites keep you logged in? Cookies. The server sends a Set-Cookie header once; your browser stores it and automatically attaches it (as a Cookie header) on every later request, so the server recognises you again.

BROWSERSERVER1 · GET /login (request + headers)2 · 200 OK + Set-Cookie: session=…3 · GET /dashboard Cookie: session=…4 · 200 OK (server remembers you)the cookie is how a stateless protocol "remembers" you

The cookie value is usually a random session token (not your password in plain text). You can watch cookies fly back and forth in your browser's developer tools, under the Network tab.

Try it, the HTTP Lab

Use the HTTP Lab beside you. Build requests and capture all five flags:

  1. Send a GET to /room.
  2. GET /blog with the query parameter id = 1.
  3. Send a DELETE to /user/1.
  4. PUT to /user/2 with the parameter username = admin.
  5. POST to /login with username = hp and password = letmein.

Watch what happens when you get it slightly wrong: a wrong method returns 405, a missing parameter returns 400, and bad credentials return 401. That feedback is the lesson.

Why this matters

Web hacking is the art of sending requests a site did not expect, a method it didn't plan for, a parameter it didn't validate, a cookie it trusted too much. Once you can read and write HTTP fluently, tools like Burp Suite and curl become extensions of your hands.

Check your understanding

11 questions

Type an answer and press Check. Grading is keyword-based and forgiving, so short answers are fine.

  1. 1

    HTTP or HTTPS: which one encrypts the traffic and proves the server's identity?

  2. 2

    In the request line GET / HTTP/1.1, which version of the protocol is being used?

  3. 3

    In the URL https://hackingpath.com:443/view?id=1, what is the host?

  4. 4

    Which method would create a new record, such as signing up a new user?

  5. 5

    Which method would update an existing record, such as changing your email address?

  6. 6

    Which method would remove a record, such as deleting a photo you uploaded?

  7. 7

    Which status code means a new resource was created (for example a new account)?

  8. 8

    Which status code means the page or resource you asked for does not exist?

  9. 9

    You try to open a page but you haven't logged in yet. Which status code fits?

  10. 10

    Which response header tells your browser to store a cookie?

  11. 11

    Which request header identifies which browser software you are using?