こさろぐ

岡山のエンジニア雑記

TryHackMe h4cked writeup

h4ckedのwriteupです。

tryhackme.com

Oh no! We've been hacked!

It seems like our machine got hacked by an anonymous threat actor. However, we are lucky to have a .pcap file from the attack. Can you determine what happened? Download the .pcap file and use Wireshark to view it.

Wiresharkでファイルを開きます。

The attacker is trying to log into a specific service. What service is this?

21番ポートに通信しているので、FTPということが分かります。
21は一般的にはFTPですね。

ブルートフォースで有名なツールと言えばHydraですね。
Hydraを知らなくても、「Van Hauser」でググると分かると思います。

The attacker is trying to log on with a specific username. What is the username?

Wiresharkを丁寧に見てみましょう。Userが見つかります。

What is the user's password?

ブルートフォースをかけているリクエストとレスポンスの山になっていますが、
ログイン成功のログが出ています。
ポートを見てみると、57078とあります。

リクエスト側のログで、Source Portが57078のものを探します。
これが成功したリクエストなので、パスワードが分かりますね!

What is the current FTP working directory after the attacker logged in?

PWDのリクエストに対して、/var/www/htmlのレスポンスが返ってきています。

The attacker uploaded a backdoor. What is the backdoor's filename?

shell.phpを保存しているログがあります。

The backdoor can be downloaded from a specific URL, as it is located inside the uploaded file. What is the full URL?

FTP-DATAの通信を見ると、URLが見つかりました。

Which command did the attacker manually execute after getting a reverse shell?

リバースシェル獲得後は、80ポート→5XXXXポートへリクエストが飛ぶようになっています。
その際に最初に実行しているコマンドはwhoamiですね。

What is the computer's hostname?

レスポンスに設定されています。

Which command did the attacker execute to spawn a new TTY shell?

pythonコマンドで設定していることが分かります。

Which command was executed to gain a root shell?

sudo suを実行していることが分かります。

The attacker downloaded something from GitHub. What is the name of the GitHub project?

git cloneで設定しているプロジェクトが分かります。

The project can be used to install a stealthy backdoor on the system. It can be very hard to detect. What is this type of backdoor called?

ステルスなバックドアはrootxxxですね。

Hack your way back into the machine

Run Hydra (or any similar tool) on the FTP service. The attacker might not have chosen a complex password. You might get lucky if you use a common word list.

Hydraで調べます。ユーザーは先ほどのユーザーを使用します。

Change the necessary values inside the web shell and upload it to the webserver

FTPでshell.phpをダウンロードし、IP部分を自分のIPに変更し、再びアップロードします。

Create a listener on the designated port on your attacker machine. Execute the web shell by visiting the .php file on the targeted web server.

ローカルで80番ポートで待ち構えます。
その後、WebブラウザでターゲットIP/shell.phpにアクセスすると、シェルを獲得できます。

Become root!

jennyにユーザーをスイッチして、sudo suを入力するとrootに昇格できます。
これでフラグをゲットできます。