probe/discoverer/ipv4/service.go
2018-08-13 17:16:28 +09:00

55 lines
1.7 KiB
Go

package ipv4
import (
"fmt"
cuej "git.loafle.net/commons/util-go/encoding/json"
omd "git.loafle.net/overflow/model/discovery"
omm "git.loafle.net/overflow/model/meta"
omu "git.loafle.net/overflow/model/util"
"github.com/google/gopacket/layers"
)
func ScanService(port *omd.Port, ds *omd.DiscoverService, resultChan chan interface{}, errChan chan error, stopChan chan struct{}) {
portNumber, err := cuej.NumberToInt(port.PortNumber)
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),
Metadata: nil,
}
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),
Metadata: nil,
}
resultChan <- s
}
}
}
}