55 lines
1.7 KiB
Go
55 lines
1.7 KiB
Go
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"
|
|
ouej "git.loafle.net/overflow/util-go/encoding/json"
|
|
"github.com/google/gopacket/layers"
|
|
)
|
|
|
|
func ScanService(port *omd.Port, ds *omd.DiscoverService, resultChan chan interface{}, errChan chan error, stopChan chan struct{}) {
|
|
portNumber, err := ouej.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
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|