53 lines
1.7 KiB
Go
53 lines
1.7 KiB
Go
package ipv4
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
cuej "git.loafle.net/commons/util-go/encoding/json"
|
|
occu "git.loafle.net/overflow/commons-go/core/util"
|
|
ocmd "git.loafle.net/overflow/commons-go/model/discovery"
|
|
ocmm "git.loafle.net/overflow/commons-go/model/meta"
|
|
"github.com/google/gopacket/layers"
|
|
)
|
|
|
|
func ScanService(port *ocmd.Port, ds *ocmd.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 ocmm.ToMetaPortTypeEnum(port.MetaPortType) {
|
|
case ocmm.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 := &ocmd.Service{
|
|
Key: ocmm.MetaTargetServiceTypeEnumUNKNOWN.String(),
|
|
Description: description,
|
|
DiscoveredDate: occu.NowPtr(),
|
|
Port: port,
|
|
MetaCryptoType: ocmm.ToMetaCryptoType(ocmm.MetaCryptoTypeEnumUNKNOWN),
|
|
}
|
|
resultChan <- s
|
|
}
|
|
}
|
|
|
|
case ocmm.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 := &ocmd.Service{
|
|
Key: ocmm.MetaTargetServiceTypeEnumUNKNOWN.String(),
|
|
Description: description,
|
|
DiscoveredDate: occu.NowPtr(),
|
|
Port: port,
|
|
MetaCryptoType: ocmm.ToMetaCryptoType(ocmm.MetaCryptoTypeEnumUNKNOWN),
|
|
}
|
|
resultChan <- s
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|