-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathvulndap.go
108 lines (86 loc) · 2.15 KB
/
vulndap.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
package main
import (
"fmt"
"gopkg.in/ldap.v2"
"net/http"
)
import "github.com/digininja/vuLnDAP/config"
type Vulndap struct {
bindusername string
bindpassword string
host string
port int
baseDN string
ldap *ldap.Conn
verbose bool
}
func NewVulndap() Vulndap {
vulndap := Vulndap{}
return vulndap
}
func (v *Vulndap) close() {
v.ldap.Close()
if v.verbose {
clientLogger.Info("LDAP connection closed")
}
}
func (v *Vulndap) connect(config config.Config) {
v.bindusername = config.LDAPClient.BindUser
v.bindpassword = config.LDAPClient.BindPassword
v.host = config.LDAPClient.BindHost
v.port = config.LDAPClient.BindPort
v.baseDN = config.LDAPClient.BaseDN
host_port := fmt.Sprintf("%s:%d", v.host, v.port)
clientLogger.Info(fmt.Sprintf("Binding to %s", host_port))
l, err := ldap.Dial("tcp", host_port)
// Enable debugging, dumps load of useful info
// l.Debug = true
if err != nil {
clientLogger.Error("Failed to connect to LDAP server")
clientLogger.Fatal(err)
}
// Bind with user
err = l.Bind(v.bindusername, v.bindpassword)
if err != nil {
clientLogger.Error("Failed to bind using login credentials")
clientLogger.Fatal(err)
}
v.ldap = l
if v.verbose {
clientLogger.Fatal("Connected to LDAP server")
}
}
func (v *Vulndap) search(w http.ResponseWriter, filter string, attributes []string, numberOfResults int) (ldap.SearchResult, error) {
/*
From
https://godoc.org/gopkg.in/ldap.v2#NewSearchRequest
SizeLimit is the number that should be returned, if more come back
the search fails with an error, it doesn't truncate
func NewSearchRequest(
BaseDN string,
Scope int,
DerefAliases int,
SizeLimit int,
TimeLimit int,
TypesOnly bool,
Filter string,
Attributes []string,
Controls []Control,
) *SearchRequest
*/
clientLogger.Info(fmt.Sprintf("Search filter: %s", filter))
// Do the search
searchRequest := ldap.NewSearchRequest(
v.baseDN,
ldap.ScopeWholeSubtree,
ldap.NeverDerefAliases,
numberOfResults,
0,
false,
filter,
attributes,
nil,
)
sr, err := v.ldap.Search(searchRequest)
return *sr, err
}