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 package icmp
import ( 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/discovery/session"
"git.loafle.net/overflow_scanner/probe/internal/pcap"
) )
func Scan(discoverySession session.DiscoverySession) error { func Scan(discoverySession session.DiscoverySession) error {
metaIPTypeEnum := omm.ToMetaIPTypeEnum(discoverySession.Zone().MetaIPType) zone := discoverySession.Zone()
switch metaIPTypeEnum { var _privileged bool
case omm.MetaIPTypeEnumV4:
return scanV4(discoverySession) _, err := pcap.RetainScanner(zone)
case omm.MetaIPTypeEnumV6: if nil == err {
return scanV4(discoverySession) 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 ( import (
"fmt" "fmt"

View File

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

View File

@ -1,4 +1,4 @@
package icmp package privileged
import ( import (
"fmt" "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() meta[val.Oid.String()] = val.Variable.String()
} }
log.Print(meta)
h := discoverySession.AddHost(&omd.Host{ h := discoverySession.AddHost(&omd.Host{
MetaIPType: discoverySession.Zone().MetaIPType, MetaIPType: discoverySession.Zone().MetaIPType,
Name: "", Name: "",
@ -151,12 +149,14 @@ func scanV2(target net.IP, discoverySession session.DiscoverySession, credential
Host: h, Host: h,
}) })
discoverySession.AddService(&omd.Service{ s := discoverySession.AddService(&omd.Service{
MetaCryptoType: omm.ToMetaCryptoType(omm.MetaCryptoTypeEnumNONE), MetaCryptoType: omm.ToMetaCryptoType(omm.MetaCryptoTypeEnumNONE),
Key: "SNMP", Key: "SNMP",
Name: "SNMP V2c", Name: "SNMP V2c",
Port: p, Port: p,
}) })
log.Printf("Host: %v, Port: %v, Service: %v", h, p, s)
return true return true
} }

View File

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

View File

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