2018-08-31 14:00:08 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2018-09-04 18:58:33 +00:00
|
|
|
if nil != discoverySession.PCapScanner() {
|
2018-08-31 14:00:08 +00:00
|
|
|
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
|
|
|
|
}
|