2018-08-13 07:19:59 +00:00
|
|
|
package ipv4
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
omd "git.loafle.net/overflow/model/discovery"
|
|
|
|
omm "git.loafle.net/overflow/model/meta"
|
|
|
|
omu "git.loafle.net/overflow/model/util"
|
2018-08-23 09:21:48 +00:00
|
|
|
ouej "git.loafle.net/overflow/util-go/encoding/json"
|
2018-08-13 07:19:59 +00:00
|
|
|
"github.com/google/gopacket/layers"
|
|
|
|
)
|
|
|
|
|
|
|
|
func ScanService(port *omd.Port, ds *omd.DiscoverService, resultChan chan interface{}, errChan chan error, stopChan chan struct{}) {
|
2018-08-23 09:21:48 +00:00
|
|
|
portNumber, err := ouej.NumberToInt(port.PortNumber)
|
2018-08-13 07:19:59 +00:00
|
|
|
if err != nil {
|
|
|
|
errChan <- fmt.Errorf("Discovery: Service scan port[%s] error %v ", port.PortNumber, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
switch omm.ToMetaPortTypeEnum(port.MetaPortType) {
|
|
|
|
case omm.MetaPortTypeEnumTCP:
|
|
|
|
if !scanServiceTCP(port, ds, resultChan, errChan, stopChan) {
|
|
|
|
if dName, ok := layers.TCPPortNames[layers.TCPPort(portNumber)]; ok {
|
|
|
|
description := fmt.Sprintf("Not Supported Service. Perhaps %s[%d]", dName, portNumber)
|
|
|
|
s := &omd.Service{
|
|
|
|
Key: omm.MetaTargetServiceTypeEnumUNKNOWN.String(),
|
|
|
|
Description: description,
|
|
|
|
DiscoveredDate: omu.NowPtr(),
|
|
|
|
Port: port,
|
|
|
|
MetaCryptoType: omm.ToMetaCryptoType(omm.MetaCryptoTypeEnumUNKNOWN),
|
2018-08-13 08:16:28 +00:00
|
|
|
Metadata: nil,
|
2018-08-13 07:19:59 +00:00
|
|
|
}
|
|
|
|
resultChan <- s
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
case omm.MetaPortTypeEnumUDP:
|
|
|
|
if !scanServiceUDP(port, ds, resultChan, errChan, stopChan) {
|
|
|
|
if dName, ok := layers.UDPPortNames[layers.UDPPort(portNumber)]; ok {
|
|
|
|
description := fmt.Sprintf("Not Supported Service. Perhaps %s[%d]", dName, portNumber)
|
|
|
|
s := &omd.Service{
|
|
|
|
Key: omm.MetaTargetServiceTypeEnumUNKNOWN.String(),
|
|
|
|
Description: description,
|
|
|
|
DiscoveredDate: omu.NowPtr(),
|
|
|
|
Port: port,
|
|
|
|
MetaCryptoType: omm.ToMetaCryptoType(omm.MetaCryptoTypeEnumUNKNOWN),
|
2018-08-13 08:16:28 +00:00
|
|
|
Metadata: nil,
|
2018-08-13 07:19:59 +00:00
|
|
|
}
|
|
|
|
resultChan <- s
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|