# 05 · Web Exploitation

[Home](../../README.md) › [Categories](../CATEGORIES_OVERVIEW.md) › **Web exploitation**
&nbsp;·&nbsp; Presentation: slides 19–20 (mock student portal with "Open DevTools") &nbsp;·&nbsp; [← 04 · Digital forensics](04-DIGITAL-FORENSICS.md) · [06 · Reverse engineering →](06-REVERSE-ENGINEERING.md)

> [!CAUTION]
> **Only test websites you own or are explicitly authorised to test**: CTF challenge servers, deliberately vulnerable labs running on your own machine (like OWASP Juice Shop), and training platforms such as PortSwigger Web Security Academy. Trying these techniques on your university portal, a shop or any real site without written permission is illegal in most countries (e.g. the UK Computer Misuse Act 1990, the US Computer Fraud and Abuse Act) and can get you expelled. Finding a bug by accident? Stop, don't explore further, and report it through the site's official disclosure channel.

---

## Contents

- [A. Introduction](#a-introduction)
- [B. Prerequisites](#b-prerequisites)
- [C. Understanding the challenges](#c-understanding-the-challenges)
- [D. Step-by-step methodology](#d-step-by-step-methodology)
- [E. Tools and their usage](#e-tools-and-their-usage)
- [F. Recommended learning resources](#f-recommended-learning-resources)
- [G. Mini practice exercises](#g-mini-practice-exercises)
- [H. What to learn next](#h-what-to-learn-next)

---

## A. Introduction

### A scenario

You're checking your grades on the student portal. The URL ends in `?student=48213`, which is your ID. What would happen if the number were different? A well-built site checks that you're allowed to see that record; a badly built one just shows it. That single question, *"does the server actually check?"*, is the heart of web security.

### What it is

**Web exploitation** challenges give you a website or web app with a deliberate flaw. Your job is to understand how it works, find where it trusts something it shouldn't, and use that to reach the flag: a hidden page, an admin account, a secret in a database.

### What problems it deals with

- Input that the server trusts too much (injection).
- Pages that don't check *who* is asking (access control).
- Secrets left in the browser (comments, JavaScript, cookies).
- Mis-configured servers exposing files.

### Where you meet it in real life

Websites and APIs are the most attacked part of most organisations, because they're public by design. Banking, shopping, university systems and every mobile app's back end are web applications. **Web penetration testing** and **bug bounty** programmes (where companies pay for responsibly reported bugs) are large professions.

### Why it's interesting

You already use the web every day. Web challenges reveal what's happening under the surface, and the first steps need nothing but a browser.

### How it relates to cybersecurity

The [OWASP Top 10](https://owasp.org/Top10/2025/) is the industry's list of the most critical web risks. Developers who understand attacks write safer code; testers find flaws before criminals do.

---

## B. Prerequisites

| Level | What | Why |
|---|---|---|
| **Essential** | Using a browser and its Developer Tools | Your main tool. Press `F12`. |
| **Essential** | What a URL, a link and a form are | You'll modify them. |
| **Helpful** | Basic HTML, CSS and JavaScript | To read page source and scripts. [MDN Learn](https://developer.mozilla.org/en-US/docs/Learn_web_development) teaches them free. |
| **Helpful** | How HTTP works (requests, responses, status codes) | Explained below. |
| **Helpful** | Basic SQL (`SELECT … WHERE …`) | To understand SQL injection. |
| **Advanced** | A back-end language (Python, PHP, JavaScript/Node) | To read source code in harder challenges. |
| **Advanced** | Proxies (Burp Suite / ZAP) | To intercept and modify requests. |

- **Programming:** not required to start; reading HTML/JavaScript helps a lot. Python is useful for scripting requests.
- **Linux:** not required.
- **Networking:** a basic understanding of HTTP is enough.

---

## C. Understanding the challenges

### What a typical challenge looks like

> *(Fictional example written for this guide.)*
> **"Staff Only" · 100 points**
> The cafeteria's new menu site has an admin page. Regular students shouldn't be able to see it.
> 🔗 `http://challenge.example:8080/`

### What you're usually given

- A **URL** to a challenge server (sometimes one instance per player).
- Sometimes the **source code** (white-box), sometimes nothing (black-box).
- Occasionally a **Docker file** so you can run the app locally.

### Clues to look for

| Clue | What to check |
|---|---|
| `?id=5`, `?page=about`, `?file=menu.txt` in the URL | Change the value: access control, traversal, injection |
| A login form | Default credentials? SQL injection (in the lab)? Logic flaws? |
| A cookie like `role=student` or `admin=false` | Is the server trusting a value *you* control? |
| HTML comments `<!-- TODO: remove /debug -->` | Hidden pages or credentials |
| JavaScript doing "security" checks | Client-side checks can always be bypassed: the real check must be on the server |
| `robots.txt` | Lists paths the site doesn't want search engines to index, which often means interesting paths |
| Search boxes that echo your input | Possible XSS |

### Common challenge patterns

1. **Source inspection:** flag in comments, JavaScript or hidden form fields.
2. **Cookie or parameter tampering:** change `role=user` to `role=admin`.
3. **Broken access control / IDOR:** change an ID to see someone else's data.
4. **SQL injection:** input changes the meaning of a database query.
5. **Cross-site scripting (XSS):** input ends up executed as JavaScript in a page.
6. **Directory (path) traversal:** `../` lets you read files outside the intended folder.
7. **Logic flaws:** buying an item for a negative price, skipping a step in a process.

### Common beginner mistakes

| Mistake | Better habit |
|---|---|
| Testing real sites "just to see" | Only challenge servers and local labs. Always. |
| Running automated scanners immediately | Understand the app manually first. Many CTFs ban scanners; they also create noise. |
| Not reading the page source | `Ctrl+U` and DevTools first. |
| Believing the browser's restrictions | Disabled buttons, hidden fields and JavaScript checks are suggestions; the server decides. |
| Forgetting to note requests that worked | Keep a log, or use Burp/ZAP history. |

---

## D. Step-by-step methodology

### 1. Use the site like a normal user

**Why:** you can't spot what's abnormal until you know what's normal. Click everything, register an account if possible, note every page and parameter.

### 2. Read what the browser received

**Why:** everything sent to your browser is visible to you, including things developers forgot.

- View source (`Ctrl+U`), look for comments and hidden fields.
- DevTools → **Sources** (JavaScript files), **Application/Storage** (cookies, localStorage), **Network** (every request and response).
- Check `/robots.txt`.

### 3. Map the inputs

**Why:** every vulnerability needs an input. List URL parameters, form fields, cookies and headers.

### 4. Ask "what does the server trust?"

**Why:** that's where flaws live. For each input: *What if I change it? Remove it? Make it very long? Use a special character like `'`, `<` or `../`?*

### 5. Observe the response carefully

**Why:** error messages, status codes, response length and timing differences are all signals.

### 6. Form a hypothesis, test, refine

**Why:** random poking wastes time. "I think this parameter is used in a file path" → test with a safe traversal attempt in the challenge → read the result.

### 7. Look up the vulnerability class

**Why:** PortSwigger and OWASP explain each class with the *why* and the *fix*. Learn it properly, then solve.

### How websites work

```
 Browser (client)                         Web server
 ──────────────                           ──────────
 GET /grades?student=48213  ───────────►  checks session cookie
 Cookie: session=abc123                   queries the database
                            ◄───────────  200 OK + HTML page
```

- **Client–server architecture:** your browser (client) asks; the server answers. Anything on the client can be changed by the user. Only the server can enforce rules.
- **HTTP** is the protocol for those requests and responses. **HTTPS** is HTTP inside an encrypted TLS connection, so others on the network can't read or change it. HTTPS doesn't make the *app* secure; it secures the *transport*.
- **Request:** method (`GET` to read, `POST` to submit), path, headers (`Cookie`, `User-Agent`…), optional body.
- **Response:** status code (`200 OK`, `302 Found` redirect, `403 Forbidden`, `404 Not Found`, `500 Internal Server Error`), headers (`Set-Cookie`…), body (the HTML).
- **HTML** structures the page, **CSS** styles it, **JavaScript** makes it interactive, and it all runs in *your* browser.

Read more: [MDN: An overview of HTTP](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Overview).

### Cookies and sessions

HTTP doesn't remember you between requests. After login, the server sends a **cookie** (`Set-Cookie: session=abc123`); your browser sends it back with every request, and the server looks up which user that session belongs to. If a site instead stores `user=alice; role=student` in a cookie *without protection*, you can edit it. See [MDN: Cookies](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Cookies).

### Authentication vs authorisation

| | Authentication | Authorisation |
|---|---|---|
| Question | *Who are you?* | *What are you allowed to do?* |
| Example | Logging in with password + 2FA | Students see their own grades; lecturers can edit them |
| Typical flaw | Weak passwords, broken login logic | Changing `?student=48213` shows someone else's grades |

### Vulnerability classes, conceptually

**SQL injection (SQLi).** A web app builds a database query by gluing user input into a string:

```python
# VULNERABLE: never do this
query = "SELECT * FROM users WHERE name = '" + name + "'"
```

If the input contains a quote character, it ends the string early and the rest of the input is interpreted **as SQL code**, changing the meaning of the query (for example, making a condition always true). The fix is to **never build queries by string concatenation** and use **parameterised queries** instead, where the database treats input strictly as data:

```python
# SAFE
cursor.execute("SELECT * FROM users WHERE name = ?", (name,))
```

Learn and practise it in the [PortSwigger SQL injection labs](https://portswigger.net/web-security/sql-injection); background: [OWASP: SQL Injection](https://owasp.org/www-community/attacks/SQL_Injection).

**Cross-site scripting (XSS).** A page includes user input in its HTML without escaping it, so input such as an HTML tag is interpreted by the browser as part of the page, and script in it runs in other users' browsers. Consequences include stealing session data or acting as the victim. The fix: **escape output** for the context (HTML, attribute, JavaScript), use frameworks that escape by default, and add a Content Security Policy. Learn it at [PortSwigger: XSS](https://portswigger.net/web-security/cross-site-scripting) and [OWASP: XSS](https://owasp.org/www-community/attacks/xss/).

**Directory (path) traversal.** An app reads files using a name from the user, e.g. `?file=menu.txt`. If it doesn't validate the name, the sequence `../` ("go up one folder") may let a user read files outside the intended folder. The fix: don't pass user input to file paths; if you must, use an allow-list and resolve the canonical path. Learn it at [PortSwigger: Path traversal](https://portswigger.net/web-security/file-path-traversal).

**Broken access control.** The server doesn't check whether the logged-in user may access a resource: changing an ID (IDOR, *insecure direct object reference*), visiting `/admin` directly, or editing a `role` cookie. It's **#1 in the OWASP Top 10:2025**. Learn it at [PortSwigger: Access control](https://portswigger.net/web-security/access-control).

### The OWASP Top 10:2025

The current edition, from [owasp.org/Top10/2025](https://owasp.org/Top10/2025/):

| # | Risk |
|---|---|
| A01 | Broken Access Control |
| A02 | Security Misconfiguration |
| A03 | Software Supply Chain Failures |
| A04 | Cryptographic Failures |
| A05 | Injection (includes SQLi and XSS) |
| A06 | Insecure Design |
| A07 | Authentication Failures |
| A08 | Software or Data Integrity Failures |
| A09 | Security Logging and Alerting Failures |
| A10 | Mishandling of Exceptional Conditions |

---

## E. Tools and their usage

> [!TIP]
> DevTools solves most beginner web challenges. Add Burp Suite Community or ZAP when you need to modify requests.

### Browser Developer Tools

| | |
|---|---|
| **Website / Docs** | [Chrome DevTools](https://developer.chrome.com/docs/devtools/overview) · [Firefox DevTools](https://firefox-source-docs.mozilla.org/devtools-user/) |
| **Purpose** | Inspect HTML, run JavaScript, watch network traffic, edit cookies and storage |
| **Problem it solves** | Seeing everything the server sent you, and changing what your browser sends |
| **Platform** | Built into Chrome, Edge, Firefox, Safari (enable the Develop menu) |
| **Type · Cost** | Built-in · Free |
| **Level** | Beginner |
| **When to use** | Always, first |
| **Alternative** | View source (`Ctrl+U`) for a quick look |

**Try it:** press `F12` on a challenge page. **Elements**: look for comments. **Network**: reload and click a request to see its headers. **Application** (Chrome) / **Storage** (Firefox) → *Cookies*: double-click a value to edit it. **Console**: type `document.cookie`.

### Burp Suite Community Edition

| | |
|---|---|
| **Website** | <https://portswigger.net/burp/communitydownload> |
| **Documentation** | [Burp Suite documentation](https://portswigger.net/burp/documentation/desktop) · [Getting started](https://portswigger.net/burp/documentation/desktop/getting-started) |
| **Purpose** | An intercepting proxy: sits between your browser and the server so you can see and modify every request |
| **Problem it solves** | Changing requests the browser UI doesn't let you change; replaying requests with variations |
| **Platform** | Windows, macOS, Linux |
| **Type · Cost** | Installed · Community Edition is free (Professional is paid) |
| **Level** | Beginner → advanced |
| **When to use** | You need to tamper with requests (Proxy, Repeater) |
| **Installation** | Download from the link above. It includes a pre-configured browser, so no proxy setup is needed. |
| **Alternative** | ZAP (fully free and open source) |

**Try it:** *Proxy → Open browser*, visit your local Juice Shop, find the request in *HTTP history*, right-click → *Send to Repeater*, change a parameter, press *Send*.

### ZAP (Zed Attack Proxy)

| | |
|---|---|
| **Website** | <https://www.zaproxy.org/> |
| **Documentation** | [ZAP docs](https://www.zaproxy.org/docs/) · [Getting started](https://www.zaproxy.org/getting-started/) |
| **Purpose** | Free, open-source intercepting proxy and web scanner (formerly OWASP ZAP; now "ZAP by Checkmarx") |
| **Problem it solves** | Same as Burp: intercept, inspect, modify, plus automated scanning |
| **Platform** | Windows, macOS, Linux |
| **Type · Cost** | Installed · Free, open source |
| **Level** | Beginner → intermediate |
| **When to use** | You prefer fully free tools, or want automated scans **of your own local lab** |
| **Installation** | [zaproxy.org/download](https://www.zaproxy.org/download/) |
| **Alternative** | Burp Suite Community |

> [!WARNING]
> Automated scanning sends many requests. Only scan targets you own (your local Juice Shop) or where the rules explicitly allow it. Many CTFs forbid scanners.

### curl

| | |
|---|---|
| **Website** | <https://curl.se/> |
| **Documentation** | [curl docs](https://curl.se/docs/) · [Manual](https://curl.se/docs/manpage.html) |
| **Purpose** | Send HTTP requests from the command line |
| **Problem it solves** | Seeing raw responses and headers; sending exactly the request you want; scripting |
| **Platform** | Pre-installed on Windows 10/11, macOS and most Linux |
| **Type · Cost** | Built-in/installed · Free, open source |
| **Level** | Beginner |
| **When to use** | Quick header checks, custom headers or cookies, automation |
| **Alternative** | Python `requests` library; Burp Repeater |

> On Windows **PowerShell**, `curl` may be an alias for `Invoke-WebRequest`. Type `curl.exe` to be sure you get the real curl.

```bash
curl -i http://localhost:3000/                       # include response headers
curl -s http://localhost:3000/robots.txt             # read robots.txt
curl -b "role=admin" http://challenge.example/       # send a cookie
curl -X POST -d "user=test&pass=test" http://challenge.example/login
```

### OWASP Juice Shop

| | |
|---|---|
| **Website** | <https://owasp.org/www-project-juice-shop/> |
| **Documentation** | [Pwning OWASP Juice Shop (official companion guide)](https://pwning.owasp-juice.shop/) · [GitHub](https://github.com/juice-shop/juice-shop) |
| **Purpose** | A deliberately insecure online shop with 100+ challenges covering the OWASP Top 10 and more |
| **Problem it solves** | A **safe, legal** target to practise every web technique on your own machine |
| **Platform** | Anywhere Docker or Node.js runs |
| **Type · Cost** | Installed (local) · Free, open source |
| **Level** | Beginner → advanced |
| **When to use** | Whenever you want to practise web attacks hands-on |
| **Installation** | With [Docker Desktop](https://www.docker.com/products/docker-desktop/): `docker pull bkimminich/juice-shop` then `docker run --rm -p 127.0.0.1:3000:3000 bkimminich/juice-shop` and open <http://localhost:3000>. (Binding to `127.0.0.1` keeps it reachable only from your own computer, which matters because it's intentionally vulnerable.) |
| **Alternative** | [PortSwigger Web Security Academy](https://portswigger.net/web-security) (hosted labs, free account); the project also links a public demo instance that may be unavailable at times |

---

## F. Recommended learning resources

| Resource | Type | Why it's useful |
|---|---|---|
| [PortSwigger Web Security Academy](https://portswigger.net/web-security) | Free platform (account for labs) | The best free web-security course: explanations plus hundreds of hosted labs. Start with the [learning paths](https://portswigger.net/web-security/learning-paths). |
| [MDN Learn web development](https://developer.mozilla.org/en-US/docs/Learn_web_development) | Free tutorials | HTML, CSS, JavaScript and HTTP from scratch. |
| [OWASP Top 10:2025](https://owasp.org/Top10/2025/) | Official reference | What the industry considers the most critical risks. |
| [Pwning OWASP Juice Shop](https://pwning.owasp-juice.shop/) | Free book | Hints and solutions for every Juice Shop challenge. |
| [OverTheWire: Natas](https://overthewire.org/wargames/natas/) | Practice (no account) | A browser-based web-security wargame, level by level. |
| [Hacker101](https://www.hacker101.com/) | Free videos and CTF (account) | Web-security lessons from HackerOne, aimed at future bug hunters. |
| [Chrome DevTools docs](https://developer.chrome.com/docs/devtools/overview) | Official docs | Master your most important tool. |

---

## G. Mini practice exercises

### Exercise 1: Secrets in the page (your own local file)

- **Objective:** Use DevTools to find things hidden in a page.
- **Given:** Save this as `secret.html` on your computer and open it in a browser:

```html
<!doctype html>
<html>
<head><title>Cafeteria Menu</title></head>
<body>
  <h1>Today's menu</h1>
  <p>Soup of the day: tomato.</p>
  <!-- TODO before launch: remove FLAG{always_read_the_source} -->
  <script>document.cookie = "role=student";</script>
</body>
</html>
```

- **Hints:** View source (`Ctrl+U`) or DevTools → Elements. For the cookie, DevTools → Application/Storage → Cookies, or type `document.cookie` in the Console. (Some browsers don't store cookies for `file://` pages; if so, serve the folder with `python -m http.server` and open `http://localhost:8000/secret.html`.)
- **Learning outcome:** You know where to look for client-side secrets and understand that everything sent to the browser is visible.
- **Solution:** The flag is in the HTML comment; the cookie value is `role=student`. Change it to `role=admin` in DevTools and notice that **nothing checks it**, which is why servers must never trust client-side values.

### Exercise 2: Juice Shop warm-up

- **Objective:** Run a vulnerable lab locally and solve its first challenge.
- **Given:** OWASP Juice Shop running on <http://localhost:3000> (see installation above).
- **Hints:** Juice Shop has a hidden **Score Board** page that tracks all challenges. Finding it is one of the first challenges. Read the JavaScript in DevTools → Sources and look for route names. Also try `curl -i http://localhost:3000/` and look at the response headers.
- **Learning outcome:** You can set up a safe lab and use source inspection to discover hidden functionality.
- **Solution reference:** [Pwning OWASP Juice Shop: Finding the Score Board](https://pwning.owasp-juice.shop/companion-guide/latest/part2/score-board.html).

### Exercise 3: Your first SQL injection lab (authorised training environment)

- **Objective:** See SQL injection change a query's logic in a lab designed for it.
- **Given:** PortSwigger lab [*SQL injection vulnerability in WHERE clause allowing retrieval of hidden data*](https://portswigger.net/web-security/sql-injection/lab-retrieve-hidden-data) (free account required).
- **Hints:** Read the lab description: it tells you the exact query the app runs. Think about how a single quote and an SQL comment could change that query.
- **Learning outcome:** You understand why string concatenation in queries is dangerous and why parameterised queries fix it.
- **Solution reference:** Each PortSwigger lab has an official *Solution* section on the lab page.

### Exercise 4: Think like a defender

- **Objective:** Connect vulnerabilities to fixes.
- **Given:** The vulnerable and safe Python query examples in section D.
- **Question:** Why is the second one safe even if `name` contains a quote?
- **Learning outcome:** You can explain the root cause of injection.
- **Solution:** In a parameterised query, the database receives the SQL structure and the data **separately**, so input can never change the structure; it's always treated as a value.

---

## H. What to learn next

| Stage | Learn | Resources |
|---|---|---|
| **Beginner** | DevTools, HTTP, cookies, source inspection, basic access control | Exercises above, [Natas](https://overthewire.org/wargames/natas/) levels 0–10, [CyLab library](https://learn.cylabacademy.org/library) (Web Exploitation) |
| **Intermediate** | Burp/ZAP, SQLi, XSS, path traversal, authentication flaws | [PortSwigger Apprentice labs](https://portswigger.net/web-security/all-labs), [Juice Shop](https://owasp.org/www-project-juice-shop/) |
| **Advanced** | SSRF, deserialisation, template injection, request smuggling, code review | PortSwigger Practitioner/Expert labs, advanced web CTF [writeups](https://ctftime.org/writeups) |

**Related guides:** [04 · Digital forensics](04-DIGITAL-FORENSICS.md) (HTTP in packet captures) · [Browser-based tools](../tools/BROWSER-BASED-TOOLS.md) · [Installable tools](../tools/INSTALLABLE-TOOLS.md)

---

[← 04 · Digital forensics](04-DIGITAL-FORENSICS.md) &nbsp;|&nbsp; [06 · Reverse engineering →](06-REVERSE-ENGINEERING.md)
