probe/discovery/target/port/port.go
crusader 7535e7ffc1 ing
2018-09-05 03:58:33 +09:00

51 lines
1.1 KiB
Go

package port
import (
"sync"
omd "git.loafle.net/overflow/model/discovery"
"git.loafle.net/overflow_scanner/probe/discovery/protocol/tcp/connection"
"git.loafle.net/overflow_scanner/probe/discovery/protocol/tcp/syn"
"git.loafle.net/overflow_scanner/probe/discovery/session"
)
func Scan(discoverySession session.DiscoverySession, targetHost *omd.Host) error {
if nil == targetHost || nil == discoverySession.DiscoverPort() {
return nil
}
if nil != discoverySession.PCapScanner() {
return privilegedScan(discoverySession, targetHost)
}
return unprivilegedScan(discoverySession, targetHost)
}
func privilegedScan(discoverySession session.DiscoverySession, targetHost *omd.Host) error {
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
syn.Scan(discoverySession, targetHost)
}()
wg.Wait()
return nil
}
func unprivilegedScan(discoverySession session.DiscoverySession, targetHost *omd.Host) error {
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
connection.Scan(discoverySession, targetHost)
}()
wg.Wait()
return nil
}