TryHackMe 歴1ヵ月半が参加する Advent of Cyber 2022 [Day 9]

9日目。

[Day 9] Dock the halls

This task is a bit more complex than what you have seen so far in the event.

今回はなんだかいつもと雰囲気が違いそうだ。解説に Challenge Walkthrough が書いてあるのでそれを見ながら進めるのがよい。

手元の WSL 環境で Metasploit がうまく動かず詰んだのでおとなしく TryHackMe が用意してくれた Kali Linux を使う。

Deploy the attached VM, and wait a few minutes. What ports are open?

namp コマンドを使う。オプションは好みで。"What ports are open?" は「何番ポートが開いているか」という意味。

What framework is the web application developed with?

ウェブページを覗くと右下にフレームワークが記述してある。

What CVE is the application vulnerable to?

Exploit Database さんの出番。ただ、サイトの Search ボックスから検索してもいまいち引っかからない印象があるので GoogleLaravel v8.26.1 site:https://www.exploit-db.com と検索する。うまく引っかかるのでサイトを見て CVE を回答する。

What command can be used to upgrade the last opened session to a Meterpreter session?

解説に書いてあるコマンドを回答する。

What file indicates a session has been opened within a Docker container?

解説文にそれらしきファイル名があるのでそれを回答する。"We can also see, due to the presence of ..." とあるがどこで見られるんだ

What file often contains useful credentials for web applications?

解説に "we can see there are database credentials available:" と画像付きで説明がある。

What database table contains useful credentials?

ここからは実際に手元で動かして答えを探していく。

まずは msfconsole コマンドで Metasploit を起動する。Metasploit では CVE で検索ができるので search コマンドで CVE-2021-3129 を検索する。使えるモジュールが見つかるので use コマンドで exploit/multi/php/ignition_laravel_debug_rce のモジュール内へ移行する(コンソールが msf6> から msf6 exploit(multi/php/ignition_laravel_debug_rce) > に変化する)。

check rhost=10.10.206.67 HttpClientTimeout=20 コマンドで実際に rhost(ターゲットとなるリモートホスト)が攻撃可能かをチェックする(別にしなくてもいい)。

攻撃可能とわかったので次に攻撃に必要な設定を options コマンドで確認する。Required の値が yes で Current Settiong が空白な箇所は設定が必要である。

普段は set コマンドで設定してから run コマンドで攻撃となるが、解説には run コマンドに引数を与えて実行しているので今回はそれに従う。Note に記述してある通り、LHOST として eth0 の IP アドレスを用いる。ちなみに ip addr コマンドは Metasploit のコンソール上でも使える。

実行すると攻撃が成功し、コマンドが使えるようになる。

その後は一旦 background コマンドで Metasploit のコンソールに戻って、sessions -u -1 コマンドで Meterpreter セッションを張る。

sessions -i -1 コマンドを使うと次は Meterpreter > と表示され、コマンドが実行できるようになる。ここで resolve <Hostname> コマンドを用いると Hostname に対する IP Address が得られるので webservice_database の IP アドレスを調べる。ここで得た IP アドレスは覚えておく。ところで webservice_database ってどこから出てきた?

IP アドレスを見るとわかる通り、これでは外からはアクセスできない。しかし、なにやら Metasploit ならそれができるようになるらしい(よくわかんない……)。

まずは background コマンドで Metasploit に戻り、msfconsole のグローバルルーティングテーブルに先ほどの IP アドレス、そして 172.17.0.1 を登録する。172.17.0.1 は Docker 側のデフォルトゲートウェイを表すアドレスらしい(?)。

有用な情報を得るためにデータベースを調べる。調査には Metasploit の auxiliary/scanner/postgres/postgres_schemadump モジュールと auxiliary/admin/postgres/postgres_sql モジュールを用いる。前者でスキーマを抽出し、後者で SQl 文を実行しする。ここで santa のパスワードも読み取れる。

What is Santa's password?

先のコマンドで得た santa のパスワードを回答する。

What ports are open on the host machine?

curl --proxy socks4a://localhost:9050 http://172.17.0.1 -v コマンドで proxy が動いているのが確認できる。また、proxychains コマンドで Nmap を実行できるので開いているポートを確認できる。

What is the root flag?

SSH が開いていることが分かったので auxiliary/scanner/ssh/ssh_login モジュールを使用してログインを試みる。

モジュール内で run ssh://... コマンドを実行した後は新たにセッションが張られているのが確認できる。

セッションが張られたので、sessions -i -1 コマンドで接続し、フラグを読み取る。

Day 9 is done! You might want to take a well-deserved rest now. If this challenge was right up your alley, though, we think you might enjoy the Compromising Active Directory module!

No answer needed

感想

解説を読めば解答は得られたが、正直後半に行くにつれてなんでそれはこうなんだ?といったことが多く、記事も雑になってしまった感が否めない。世の中わからないことだらけ!