probe/discovery/target/port/port.go
2018-08-31 23:00:08 +09:00

62 lines
1.2 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"
"git.loafle.net/overflow_scanner/probe/internal/pcap"
)
func Scan(discoverySession session.DiscoverySession, targetHost *omd.Host) error {
if nil == targetHost || nil == discoverySession.DiscoverPort() {
return nil
}
zone := discoverySession.Zone()
var privileged bool
_, err := pcap.RetainScanner(zone)
if nil == err {
pcap.ReleaseScanner(zone)
privileged = true
}
if privileged {
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
}