Skip to content

Commit

Permalink
Added native Windows LDAP collection for Windows builds
Browse files Browse the repository at this point in the history
  • Loading branch information
lkarlslund committed Feb 14, 2024
1 parent c2c0dbc commit 3c5c054
Show file tree
Hide file tree
Showing 8 changed files with 1,130 additions and 47 deletions.
11 changes: 6 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ require (
github.com/go-ini/ini v1.67.0
github.com/gobwas/glob v0.2.3
github.com/gofrs/uuid v4.4.0+incompatible
github.com/gorilla/mux v1.8.1
github.com/gravwell/gravwell/v3 v3.8.13
github.com/icza/gox v0.0.0-20230924165045-adcb03233bb5
github.com/json-iterator/go v1.1.12
Expand Down Expand Up @@ -107,9 +106,12 @@ require (
github.com/elastic/go-windows v1.0.1
github.com/felixge/fgtrace v0.2.0
github.com/gammazero/deque v0.2.1
github.com/gin-contrib/pprof v1.4.0
github.com/gin-contrib/static v0.0.1
github.com/golang-auth/go-channelbinding v1.0.1
github.com/gorilla/websocket v1.5.1
github.com/jcmturner/gokrb5/v8 v8.4.4
github.com/lkarlslund/gonk v0.0.0-20231113084556-53a1781342e9
github.com/peterrk/slices v1.0.0
www.velocidex.com/golang/go-ese v0.2.1-0.20240207005444-85d57b555f8b
)

Expand All @@ -121,15 +123,13 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dchest/safefile v0.0.0-20151022103144-855e8d98f185 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gin-contrib/pprof v1.4.0 // indirect
github.com/gin-contrib/static v0.0.1 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/google/gopacket v1.1.19 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/gravwell/buffer v0.0.0-20220728204757-23339f4bab66 // indirect
github.com/gravwell/ipfix v1.4.5 // indirect
github.com/h2non/filetype v1.1.3 // indirect
github.com/hashicorp/go-uuid v1.0.3 // indirect
github.com/jake-scott/go-gssapi v0.2.2 // indirect
github.com/jcmturner/aescts/v2 v2.0.0 // indirect
github.com/jcmturner/dnsutils/v2 v2.0.0 // indirect
github.com/jcmturner/gofork v1.7.6 // indirect
Expand All @@ -141,6 +141,7 @@ require (
github.com/open-networks/go-msgraph v0.3.4 // indirect
github.com/open2b/scriggo v0.56.1 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/peterrk/slices v1.0.0 // indirect
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
github.com/shoenig/go-m1cpu v0.1.6 // indirect
github.com/tealeg/xlsx v1.0.5 // indirect
Expand Down
13 changes: 8 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw=
github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU=
github.com/gofrs/uuid v4.4.0+incompatible h1:3qXRTX8/NbyulANqlc0lchS1gqAVxRgsuW1YrTJupqA=
github.com/gofrs/uuid v4.4.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/golang-auth/go-channelbinding v1.0.1 h1:Sc60eXHEyLxKS0BWaM6FtmhVE+stTyTUxp1cLQaGgY0=
github.com/golang-auth/go-channelbinding v1.0.1/go.mod h1:tWhkagITD+NfomCcnMM/de/ddpxO5dbDTFsgGfQSHhk=
github.com/golang-jwt/jwt v3.2.1+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
Expand Down Expand Up @@ -307,8 +309,6 @@ github.com/gookit/color v1.4.2/go.mod h1:fqRyamkC1W8uxl+lxCQxOT09l/vYfZ+QeiX3rKQ
github.com/gookit/color v1.5.0/go.mod h1:43aQb+Zerm/BWh2GnrgOQm7ffz7tvQXEKV6BFMl7wAo=
github.com/gookit/color v1.5.3 h1:twfIhZs4QLCtimkP7MOxlF3A0U/5cDPseRT9M/+2SCE=
github.com/gookit/color v1.5.3/go.mod h1:NUzwzeehUfl7GIb36pqId+UGmRfQcU/WiiyTTeNjHtE=
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ=
github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
github.com/gorilla/sessions v1.2.1 h1:DHd3rPN5lE3Ts3D8rKkQ8x/0kqfeNmBAaiSi+o7FsgI=
Expand Down Expand Up @@ -345,6 +345,8 @@ github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLf
github.com/inhies/go-bytesize v0.0.0-20201103132853-d0aed0d254f8/go.mod h1:KrtyD5PFj++GKkFS/7/RRrfnRhAMGQwy75GLCHWrCNs=
github.com/inhies/go-bytesize v0.0.0-20220417184213-4913239db9cf h1:FtEj8sfIcaaBfAKrE1Cwb61YDtYq9JxChK1c7AKce7s=
github.com/inhies/go-bytesize v0.0.0-20220417184213-4913239db9cf/go.mod h1:yrqSXGoD/4EKfF26AOGzscPOgTTJcyAwM2rpixWT+t4=
github.com/jake-scott/go-gssapi v0.2.2 h1:25Ri4inVUqynNf3ktySSvJIFmgdYUzBgfJ0UF4Hta+Y=
github.com/jake-scott/go-gssapi v0.2.2/go.mod h1:0jkvPgty8wGjbwQ+CznXRjhqJjBPu3zRuPNgUXfmZd4=
github.com/jcmturner/aescts/v2 v2.0.0 h1:9YKLH6ey7H4eDBXW8khjYslgyqG2xZikXP0EQFKrle8=
github.com/jcmturner/aescts/v2 v2.0.0/go.mod h1:AiaICIRyfYg35RUkr8yESTqvSy7csK90qZ5xfvvsoNs=
github.com/jcmturner/dnsutils/v2 v2.0.0 h1:lltnkeZGL0wILNvrNiVCR6Ro5PGU/SeBvVO/8c/iPbo=
Expand Down Expand Up @@ -388,10 +390,11 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxv
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
Expand Down Expand Up @@ -449,7 +452,6 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/56bj7Y/xa04UccTW04VP0Qed4vnQ=
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U=
Expand Down Expand Up @@ -517,6 +519,7 @@ github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUc
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.31.0 h1:FcTR3NnLWW+NnTwwhFWiJSZr4ECLpqCm6QsEnyvbV4A=
Expand Down Expand Up @@ -900,8 +903,8 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/check.v1 v1.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
Expand Down
27 changes: 14 additions & 13 deletions modules/integrations/activedirectory/collect/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ var (
user = Command.Flags().String("username", "", "username to connect with")
pass = Command.Flags().String("password", "", "password to connect with (use ! for blank password)")

tlsmodeString = Command.Flags().String("tlsmode", "NoTLS", "Transport mode (TLS, StartTLS, NoTLS)")

ignoreCert = Command.Flags().Bool("ignorecert", false, "Disable certificate checks")
tlsmodeString = Command.Flags().String("tlsmode", "NoTLS", "Transport mode (TLS, StartTLS, NoTLS)")
channelbinding = Command.Flags().Bool("channelbinding", true, "Enable channel binding when connecting to LDAP")
ignoreCert = Command.Flags().Bool("ignorecert", false, "Disable certificate checks")

ldapdebug = Command.Flags().Bool("ldapdebug", false, "Enable LDAP debugging")

Expand All @@ -64,7 +64,7 @@ var (
collectobjects = Command.Flags().String("objects", "auto", "Collect Active Directory Objects (users, groups etc)")
collectgpos = Command.Flags().String("gpos", "auto", "Collect Group Policy file contents")
gpopath = Command.Flags().String("gpopath", "", "Override path to GPOs, useful for non Windows OS'es with mounted drive (/mnt/policies/ or similar), but will break ACL feature")
AuthmodeString = Command.Flags().String("authmode", "ntlm", "Bind mode: unauth/anonymous, basic/simple, digest/md5, kerberoscache, ntlm, ntlmpth (password is hash), negotiate/sspi")
AuthmodeString = Command.Flags().String("authmode", "ntlm", "Bind mode: unauth/anonymous, basic/simple, digest/md5, kerberoscache, ntlm, ntlmpth (password is hash)")

purgeolddata = Command.Flags().Bool("purgeolddata", false, "Purge existing data from the datapath if connection to DC is successfull")

Expand Down Expand Up @@ -294,15 +294,16 @@ func Execute(cmd *cobra.Command, args []string) error {
} else {
// Active Directory dump directly from AD controller
options := LDAPOptions{
Domain: *domain,
Port: uint16(*port),
AuthMode: authmode,
User: *user,
Password: *pass,
AuthDomain: *authdomain,
TLSMode: tlsmode,
IgnoreCert: *ignoreCert,
Debug: *ldapdebug,
Domain: *domain,
Port: uint16(*port),
AuthMode: authmode,
User: *user,
Password: *pass,
AuthDomain: *authdomain,
TLSMode: tlsmode,
IgnoreCert: *ignoreCert,
Debug: *ldapdebug,
Channelbinding: *channelbinding,
}
var ad LDAPDumper

Expand Down
19 changes: 10 additions & 9 deletions modules/integrations/activedirectory/collect/ldap_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,16 @@ const (
)

type LDAPOptions struct {
Domain string
Server string
Port uint16
User string
Password string
AuthDomain string
AuthMode AuthMode
TLSMode TLSmode
SizeLimit int
Domain string
Server string
Port uint16
User string
Password string
AuthDomain string
AuthMode AuthMode
TLSMode TLSmode
Channelbinding bool
SizeLimit int

IgnoreCert bool

Expand Down
24 changes: 22 additions & 2 deletions modules/integrations/activedirectory/collect/ldap_multiplatform.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
osuser "os/user"

ber "github.com/go-asn1-ber/asn1-ber"
cb "github.com/golang-auth/go-channelbinding"
"github.com/jcmturner/gokrb5/v8/client"
"github.com/jcmturner/gokrb5/v8/config"
"github.com/jcmturner/gokrb5/v8/credentials"
Expand All @@ -29,6 +30,9 @@ type AD struct {
}

func (ad *AD) Connect() error {
var cbData []byte
_ = cbData // for later

if ad.AuthDomain == "" {
ad.AuthDomain = ad.Domain
}
Expand All @@ -52,17 +56,33 @@ func (ad *AD) Connect() error {
if err != nil {
return err
}

ad.conn = conn
case TLS:
config := &tls.Config{
ServerName: ad.Server,
InsecureSkipVerify: ad.IgnoreCert,
MaxVersion: tls.VersionTLS12,
}
conn, err := ldap.DialTLS("tcp", fmt.Sprintf("%s:%d", ad.Server, ad.Port), config)

conn, err := tls.Dial("tcp", fmt.Sprintf("%s:%d", ad.Server, ad.Port), config)
if err != nil {
return err
}
ad.conn = conn

if ad.Channelbinding {
tlsState := conn.ConnectionState()
if len(tlsState.PeerCertificates) == 0 {
return errors.New("no peer certificates for channel binding")
}
cbData, err = cb.MakeTLSChannelBinding(tlsState, tlsState.PeerCertificates[0], cb.TLSChannelBindingEndpoint)
if err != nil {
return err
}
}

ad.conn = ldap.NewConn(conn, true)
ad.conn.Start()
default:
return errors.New("unknown transport mode")
}
Expand Down
Loading

0 comments on commit 3c5c054

Please sign in to comment.