Skip to content

Commit

Permalink
implement network discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
5amu committed Feb 18, 2024
1 parent 95a41fa commit bddeb59
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
20 changes: 16 additions & 4 deletions internal/goad/ldap.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,20 @@ func (o *LdapOptions) Run() (err error) {

o.targets = utils.ExtractTargets(o.Targets.TARGETS)
o.target2SMBInfo = make(map[string]*smb.SMBInfo)
var wg sync.WaitGroup
var mutex sync.Mutex
for _, t := range o.targets {
o.target2SMBInfo[t] = getSMBInfo(t)
wg.Add(1)
go func(s string) {
v := getSMBInfo(s)
mutex.Lock()
o.target2SMBInfo[s] = v
mutex.Unlock()
wg.Done()

}(t)
}
wg.Wait()

var f func(string) error

Expand Down Expand Up @@ -147,12 +158,13 @@ func (o *LdapOptions) Run() (err error) {
return nil
}

var wg sync.WaitGroup
for _, target := range o.targets {
wg.Add(1)
go func(t string) {
if err := f(t); err != nil {
fmt.Println(err)
if ldap.IsLDAP(t, o.Connection.Port) {
if err := f(t); err != nil {
fmt.Println(err)
}
}
wg.Done()
}(target)
Expand Down
16 changes: 16 additions & 0 deletions pkg/ldap/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ package ldap

import (
"fmt"
"net"
"strconv"
"strings"
"time"

ldapfingerprint "github.com/praetorian-inc/fingerprintx/pkg/plugins/services/ldap"
)

func DecodeSID(s string) string {
Expand Down Expand Up @@ -56,3 +59,16 @@ func DecodeZuluTimestamp(timestamp string) string {
}
return zulu.Format("2006-01-02 3:4:5 pm")
}

func IsLDAP(host string, port int) bool {
timeout := 2 * time.Second
conn, err := net.DialTimeout("tcp", fmt.Sprintf("%s:%d", host, port), timeout)
if err != nil {
return false
}
res, err := ldapfingerprint.DetectLDAP(conn, timeout)
if err != nil {
return false
}
return res
}
9 changes: 5 additions & 4 deletions pkg/smb/smb.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"time"

"github.com/praetorian-inc/fingerprintx/pkg/plugins"
"github.com/praetorian-inc/fingerprintx/pkg/plugins/services/smb"
smbfingerprint "github.com/praetorian-inc/fingerprintx/pkg/plugins/services/smb"
zgrabsmb "github.com/zmap/zgrab2/lib/smb/smb"
)

Expand All @@ -34,15 +34,16 @@ func (i *SMBInfo) String() string {

func GatherSMBInfo(host string) (*SMBInfo, error) {
var info SMBInfo
timeout := 2 * time.Second
conn, err := net.Dial("tcp", net.JoinHostPort(host, fmt.Sprintf("%d", 445)))
timeout := 3 * time.Second

conn, err := net.DialTimeout("tcp", net.JoinHostPort(host, fmt.Sprintf("%d", 445)), timeout)
if err != nil {
return nil, err
}

var metadata *plugins.ServiceSMB

metadata, err = smb.DetectSMBv2(conn, timeout)
metadata, err = smbfingerprint.DetectSMBv2(conn, timeout)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit bddeb59

Please sign in to comment.