60 lines
1.1 KiB
Go
60 lines
1.1 KiB
Go
package host
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"git.loafle.net/overflow_scanner/probe/discovery/protocol/arp"
|
|
"git.loafle.net/overflow_scanner/probe/discovery/protocol/icmp"
|
|
"git.loafle.net/overflow_scanner/probe/discovery/session"
|
|
"git.loafle.net/overflow_scanner/probe/internal/pcap"
|
|
)
|
|
|
|
func Scan(discoverySession session.DiscoverySession) error {
|
|
targetHosts := discoverySession.TargetHosts()
|
|
if nil == targetHosts || 0 == len(targetHosts) || nil == discoverySession.DiscoverHost() {
|
|
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)
|
|
}
|
|
|
|
return unprivilegedScan(discoverySession)
|
|
}
|
|
|
|
func privilegedScan(discoverySession session.DiscoverySession) error {
|
|
var wg sync.WaitGroup
|
|
|
|
wg.Add(1)
|
|
go func() {
|
|
defer wg.Done()
|
|
|
|
arp.Scan(discoverySession)
|
|
}()
|
|
|
|
wg.Add(1)
|
|
go func() {
|
|
defer wg.Done()
|
|
|
|
icmp.Scan(discoverySession)
|
|
}()
|
|
|
|
wg.Wait()
|
|
return nil
|
|
}
|
|
|
|
func unprivilegedScan(discoverySession session.DiscoverySession) error {
|
|
|
|
return nil
|
|
}
|