unprivileged icmp added

This commit is contained in:
crusader 2018-09-01 11:19:03 +09:00
parent 99166af860
commit 5956cae93f
9 changed files with 56 additions and 17 deletions

View File

@ -1,19 +1,26 @@
package icmp
import (
omm "git.loafle.net/overflow/model/meta"
"git.loafle.net/overflow_scanner/probe/discovery/protocol/icmp/privileged"
"git.loafle.net/overflow_scanner/probe/discovery/protocol/icmp/unprivileged"
"git.loafle.net/overflow_scanner/probe/discovery/session"
"git.loafle.net/overflow_scanner/probe/internal/pcap"
)
func Scan(discoverySession session.DiscoverySession) error {
metaIPTypeEnum := omm.ToMetaIPTypeEnum(discoverySession.Zone().MetaIPType)
zone := discoverySession.Zone()
switch metaIPTypeEnum {
case omm.MetaIPTypeEnumV4:
return scanV4(discoverySession)
case omm.MetaIPTypeEnumV6:
return scanV4(discoverySession)
var _privileged bool
_, err := pcap.RetainScanner(zone)
if nil == err {
pcap.ReleaseScanner(zone)
_privileged = true
}
return nil
if _privileged {
return privileged.Scan(discoverySession)
}
return unprivileged.Scan(discoverySession)
}

View File

@ -0,0 +1,19 @@
package privileged
import (
omm "git.loafle.net/overflow/model/meta"
"git.loafle.net/overflow_scanner/probe/discovery/session"
)
func Scan(discoverySession session.DiscoverySession) error {
metaIPTypeEnum := omm.ToMetaIPTypeEnum(discoverySession.Zone().MetaIPType)
switch metaIPTypeEnum {
case omm.MetaIPTypeEnumV4:
return scanV4(discoverySession)
case omm.MetaIPTypeEnumV6:
return scanV4(discoverySession)
}
return nil
}

View File

@ -1,4 +1,4 @@
package icmp
package privileged
import (
"fmt"

View File

@ -1,4 +1,4 @@
package icmp
package privileged
import (
"net"

View File

@ -1,4 +1,4 @@
package icmp
package privileged
import (
"fmt"

View File

@ -0,0 +1,10 @@
package unprivileged
import (
"git.loafle.net/overflow_scanner/probe/discovery/session"
)
func Scan(discoverySession session.DiscoverySession) error {
return nil
}

View File

@ -133,8 +133,6 @@ func scanV2(target net.IP, discoverySession session.DiscoverySession, credential
meta[val.Oid.String()] = val.Variable.String()
}
log.Print(meta)
h := discoverySession.AddHost(&omd.Host{
MetaIPType: discoverySession.Zone().MetaIPType,
Name: "",
@ -151,12 +149,14 @@ func scanV2(target net.IP, discoverySession session.DiscoverySession, credential
Host: h,
})
discoverySession.AddService(&omd.Service{
s := discoverySession.AddService(&omd.Service{
MetaCryptoType: omm.ToMetaCryptoType(omm.MetaCryptoTypeEnumNONE),
Key: "SNMP",
Name: "SNMP V2c",
Port: p,
})
log.Printf("Host: %v, Port: %v, Service: %v", h, p, s)
return true
}

View File

@ -53,7 +53,7 @@ Loop:
wg.Done()
}()
scanPort(discoverySession, ports, targetHost, port, timeout)
tryConnect(discoverySession, ports, targetHost, port, timeout)
}(portNumber)
timer := time.NewTimer(time.Microsecond * 100)
@ -68,7 +68,7 @@ Loop:
return nil
}
func scanPort(discoverySession session.DiscoverySession, ports map[int]*omd.Port, targetHost *omd.Host, port int, timeout time.Duration) {
func tryConnect(discoverySession session.DiscoverySession, ports map[int]*omd.Port, targetHost *omd.Host, port int, timeout time.Duration) {
addr := net.JoinHostPort(targetHost.Address, strconv.Itoa(port))
conn, err := net.DialTimeout("tcp", addr, timeout)
dp := discoverySession.DiscoverPort()
@ -76,7 +76,7 @@ func scanPort(discoverySession session.DiscoverySession, ports map[int]*omd.Port
if err != nil {
if strings.Contains(err.Error(), "too many open files") {
time.Sleep(timeout)
scanPort(discoverySession, ports, targetHost, port, timeout)
tryConnect(discoverySession, ports, targetHost, port, timeout)
}
return
}

View File

@ -2,6 +2,7 @@ package upnp
import (
"fmt"
"log"
omd "git.loafle.net/overflow/model/discovery"
omu "git.loafle.net/overflow/model/util"
@ -28,6 +29,8 @@ LOOP:
continue LOOP
}
log.Print(rd)
discoverySession.AddHost(&omd.Host{
MetaIPType: discoverySession.Zone().MetaIPType,
Name: rd.FriendlyName,