Skip to content

Commit bba7896

Browse files
authored
Merge pull request #7 from ropnop/feature/socksproxy
add socks proxy support
2 parents 43041b1 + 73cdd1a commit bba7896

File tree

5 files changed

+35
-10
lines changed

5 files changed

+35
-10
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ $ ./windapsearch --version
3030
`windapsearch` is a standalone binary with multiple modules for various common LDAP queries
3131

3232
```
33+
$ ./windapsearch -h
3334
windapsearch: a tool to perform Windows domain enumeration through LDAP queries
34-
Version: dev (131fd6d) | Built: 06/10/20 (go1.14.3) | Ronnie Flathers @ropnop
35+
Version: dev (f78ee36) | Built: 06/23/20 (go1.14.3) | Ronnie Flathers @ropnop
3536
3637
Usage: ./windapsearch [options] -m [module] [module options]
3738
@@ -45,6 +46,7 @@ Options:
4546
--ntlm Use NTLM auth (automatic if hash is set)
4647
--port int Port to connect to (if non standard)
4748
--secure Use LDAPS. This will not verify TLS certs, however. (default: false)
49+
--proxy string SOCKS5 Proxy to use (e.g. 127.0.0.1:9050)
4850
--full Output all attributes from LDAP
4951
-o, --output string Save results to file
5052
-j, --json Convert LDAP output to JSON

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/ropnop/go-windapsearch
33
go 1.13
44

55
require (
6+
github.com/Azure/go-ntlmssp v0.0.0-20200615164410-66371956d46c
67
github.com/audibleblink/msldapuac v0.2.0
78
github.com/bwmarrin/go-objectsid v0.0.0-20191126144531-5fee401a2f37
89
github.com/go-ldap/ldap/v3 v3.2.1
@@ -13,5 +14,6 @@ require (
1314
github.com/spf13/pflag v1.0.5
1415
github.com/tcnksm/go-input v0.0.0-20180404061846-548a7d7a8ee8
1516
golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9
17+
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3
1618
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd // indirect
1719
)

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
2929
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
3030
github.com/magefile/mage v1.9.0 h1:t3AU2wNwehMCW97vuqQLtw6puppWXHO+O2MHo5a50XE=
3131
github.com/magefile/mage v1.9.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
32-
github.com/mitchellh/gox v1.0.1 h1:x0jD3dcHk9a9xPSDN6YEL4xL6Qz0dvNYm8yZqui5chI=
3332
github.com/mitchellh/gox v1.0.1/go.mod h1:ED6BioOGXMswlXa2zxfh/xdd5QhwYliBFn9V18Ap4z4=
34-
github.com/mitchellh/iochan v1.0.0 h1:C+X3KsSTLFVBr/tK1eYN/vs4rJcvsiLU338UhYPJWeY=
3533
github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY=
3634
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
3735
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=

pkg/ldapsession/session.go

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ package ldapsession
22

33
import (
44
"context"
5-
"crypto/tls"
65
"fmt"
6+
"golang.org/x/net/proxy"
7+
"net"
78
"strings"
89

910
"github.com/ropnop/go-windapsearch/pkg/dns"
@@ -20,6 +21,7 @@ type LDAPSessionOptions struct {
2021
UseNTLM bool
2122
Port int
2223
Secure bool
24+
Proxy string
2325
PageSize int
2426
Logger *logrus.Logger
2527
}
@@ -81,13 +83,31 @@ func NewLDAPSession(options *LDAPSessionOptions, ctx context.Context) (sess *LDA
8183
url = fmt.Sprintf("ldap://%s:%d", dc, port)
8284
}
8385

84-
lConn, err := ldap.DialURL(url)
85-
if err != nil {
86-
return
87-
}
88-
if options.Secure {
89-
lConn.StartTLS(&tls.Config{InsecureSkipVerify: true})
86+
var conn net.Conn
87+
defaultDailer := &net.Dialer{Timeout: ldap.DefaultTimeout}
88+
89+
// Use socks proxy if specified
90+
if options.Proxy != "" {
91+
pDialer, err := proxy.SOCKS5("tcp", options.Proxy, nil, defaultDailer)
92+
if err != nil {
93+
return nil, err
94+
}
95+
conn, err = pDialer.Dial("tcp", fmt.Sprintf("%s:%d", dc, port))
96+
if err != nil {
97+
return nil, err
98+
}
99+
sess.Log.Debugf("establishing connection through socks proxy at %s", options.Proxy)
100+
} else {
101+
conn, err = defaultDailer.Dial("tcp", fmt.Sprintf("%s:%d", dc, port))
102+
if err != nil {
103+
return
104+
}
90105
}
106+
sess.Log.Debugf("tcp connection established to %s:%d", dc, port)
107+
108+
lConn := ldap.NewConn(conn, options.Secure)
109+
lConn.Start()
110+
91111
sess.LConn = lConn
92112
sess.PageSize = uint32(options.PageSize)
93113

pkg/windapsearch/windapsearch.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type CommandLineOptions struct {
4040
NTLMHash string
4141
UseNTLM bool
4242
Port int
43+
Proxy string
4344
Secure bool
4445
ResolveHosts bool
4546
Attributes []string
@@ -68,6 +69,7 @@ func NewSession() *WindapSearchSession {
6869
wFlags.BoolVar(&w.Options.UseNTLM, "ntlm", false, "Use NTLM auth (automatic if hash is set)")
6970
wFlags.IntVar(&w.Options.Port, "port", 0, "Port to connect to (if non standard)")
7071
wFlags.BoolVar(&w.Options.Secure, "secure", false, "Use LDAPS. This will not verify TLS certs, however. (default: false)")
72+
wFlags.StringVar(&w.Options.Proxy, "proxy", "", "SOCKS5 Proxy to use (e.g. 127.0.0.1:9050)")
7173
wFlags.BoolVar(&w.Options.FullAttributes, "full", false, "Output all attributes from LDAP")
7274
wFlags.StringVarP(&w.Options.Output, "output", "o", "", "Save results to file")
7375
wFlags.BoolVarP(&w.Options.JSON, "json", "j", false, "Convert LDAP output to JSON")
@@ -250,6 +252,7 @@ func (w *WindapSearchSession) Run() (err error) {
250252
Hash: w.Options.NTLMHash,
251253
UseNTLM: w.Options.UseNTLM,
252254
Port: w.Options.Port,
255+
Proxy: w.Options.Proxy,
253256
Secure: w.Options.Secure,
254257
PageSize: w.Options.PageSize,
255258
Logger: w.Log.Logger,

0 commit comments

Comments
 (0)