2018-04-19 11:36:56 +00:00
|
|
|
package ipv4
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
cuej "git.loafle.net/commons/util-go/encoding/json"
|
2018-05-11 02:44:47 +00:00
|
|
|
occu "git.loafle.net/overflow/commons-go/core/util"
|
2018-04-26 09:00:24 +00:00
|
|
|
ocmd "git.loafle.net/overflow/commons-go/model/discovery"
|
2018-06-13 10:20:14 +00:00
|
|
|
ocmm "git.loafle.net/overflow/commons-go/model/meta"
|
2018-04-19 11:36:56 +00:00
|
|
|
"github.com/google/gopacket/layers"
|
|
|
|
)
|
|
|
|
|
2018-04-27 16:20:01 +00:00
|
|
|
func ScanService(port *ocmd.Port, ds *ocmd.DiscoverService, resultChan chan interface{}, errChan chan error, stopChan chan struct{}) {
|
2018-04-19 11:36:56 +00:00
|
|
|
portNumber, err := cuej.NumberToInt(port.PortNumber)
|
|
|
|
if err != nil {
|
|
|
|
errChan <- fmt.Errorf("Discovery: Service scan port[%s] error %v ", port.PortNumber, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-06-13 10:20:14 +00:00
|
|
|
switch ocmm.ToMetaPortTypeEnum(port.MetaPortType) {
|
|
|
|
case ocmm.MetaPortTypeEnumTCP:
|
2018-04-19 11:36:56 +00:00
|
|
|
if !scanServiceTCP(port, ds, resultChan, errChan, stopChan) {
|
|
|
|
if dName, ok := layers.TCPPortNames[layers.TCPPort(portNumber)]; ok {
|
2018-06-21 10:54:31 +00:00
|
|
|
description := fmt.Sprintf("Not Supported Service. Perhaps %s[%d]", dName, portNumber)
|
2018-04-26 09:00:24 +00:00
|
|
|
s := &ocmd.Service{
|
2018-06-21 10:54:31 +00:00
|
|
|
Key: ocmm.MetaTargetServiceTypeEnumUNKNOWN.String(),
|
|
|
|
Description: description,
|
2018-05-11 02:44:47 +00:00
|
|
|
DiscoveredDate: occu.NowPtr(),
|
|
|
|
Port: port,
|
2018-06-20 12:38:25 +00:00
|
|
|
MetaCryptoType: ocmm.ToMetaCryptoType(ocmm.MetaCryptoTypeEnumUNKNOWN),
|
2018-04-19 11:36:56 +00:00
|
|
|
}
|
|
|
|
resultChan <- s
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-13 10:20:14 +00:00
|
|
|
case ocmm.MetaPortTypeEnumUDP:
|
2018-04-19 11:36:56 +00:00
|
|
|
if !scanServiceUDP(port, ds, resultChan, errChan, stopChan) {
|
|
|
|
if dName, ok := layers.UDPPortNames[layers.UDPPort(portNumber)]; ok {
|
2018-06-21 10:54:31 +00:00
|
|
|
description := fmt.Sprintf("Not Supported Service. Perhaps %s[%d]", dName, portNumber)
|
2018-04-26 09:00:24 +00:00
|
|
|
s := &ocmd.Service{
|
2018-06-21 10:54:31 +00:00
|
|
|
Key: ocmm.MetaTargetServiceTypeEnumUNKNOWN.String(),
|
|
|
|
Description: description,
|
2018-05-11 02:44:47 +00:00
|
|
|
DiscoveredDate: occu.NowPtr(),
|
|
|
|
Port: port,
|
2018-06-20 12:38:25 +00:00
|
|
|
MetaCryptoType: ocmm.ToMetaCryptoType(ocmm.MetaCryptoTypeEnumUNKNOWN),
|
2018-04-19 11:36:56 +00:00
|
|
|
}
|
|
|
|
resultChan <- s
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|