No longer import hosts using their MAC addresses
This commit is contained in:
committed by
Brendan LE GLAUNEC
parent
541d64168d
commit
456f7fffc5
+9
-1
@@ -114,13 +114,21 @@ func NmapParseResults(nmapResultFilePath string) ([]Stream, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, addr := range host.Addresses {
|
||||||
|
err = validate.Struct(addr)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
streams = append(streams, Stream{
|
streams = append(streams, Stream{
|
||||||
Device: port.Service.Product,
|
Device: port.Service.Product,
|
||||||
Address: host.Address.Addr,
|
Address: addr.Addr,
|
||||||
Port: port.PortID,
|
Port: port.PortID,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return streams, nil
|
return streams, nil
|
||||||
}
|
}
|
||||||
|
|||||||
+89
-16
@@ -107,6 +107,12 @@ func TestNmapParseResults(t *testing.T) {
|
|||||||
Port: 1337,
|
Port: 1337,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
invalidStreamMACAddress := Stream{
|
||||||
|
Device: "invalidDevice",
|
||||||
|
Address: "00:12:16:FB:02:17",
|
||||||
|
Port: 1337,
|
||||||
|
}
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
fileExists bool
|
fileExists bool
|
||||||
streamsXML *nmapResult
|
streamsXML *nmapResult
|
||||||
@@ -121,10 +127,12 @@ func TestNmapParseResults(t *testing.T) {
|
|||||||
streamsXML: &nmapResult{
|
streamsXML: &nmapResult{
|
||||||
Hosts: []host{
|
Hosts: []host{
|
||||||
{
|
{
|
||||||
Address: address{
|
Addresses: []address{
|
||||||
|
address{
|
||||||
Addr: validStream1.Address,
|
Addr: validStream1.Address,
|
||||||
AddrType: "ipv4",
|
AddrType: "ipv4",
|
||||||
},
|
},
|
||||||
|
},
|
||||||
Ports: ports{
|
Ports: ports{
|
||||||
Ports: []port{
|
Ports: []port{
|
||||||
{
|
{
|
||||||
@@ -141,10 +149,12 @@ func TestNmapParseResults(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Address: address{
|
Addresses: []address{
|
||||||
|
address{
|
||||||
Addr: validStream2.Address,
|
Addr: validStream2.Address,
|
||||||
AddrType: "ipv4",
|
AddrType: "ipv4",
|
||||||
},
|
},
|
||||||
|
},
|
||||||
Ports: ports{
|
Ports: ports{
|
||||||
Ports: []port{
|
Ports: []port{
|
||||||
{
|
{
|
||||||
@@ -165,6 +175,38 @@ func TestNmapParseResults(t *testing.T) {
|
|||||||
fileExists: true,
|
fileExists: true,
|
||||||
},
|
},
|
||||||
// File exists
|
// File exists
|
||||||
|
// Invalid stream, only a mac address
|
||||||
|
{
|
||||||
|
fileExists: true,
|
||||||
|
expectedStreams: []Stream{},
|
||||||
|
streamsXML: &nmapResult{
|
||||||
|
Hosts: []host{
|
||||||
|
{
|
||||||
|
Addresses: []address{
|
||||||
|
address{
|
||||||
|
Addr: invalidStreamMACAddress.Address,
|
||||||
|
AddrType: "mac",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Ports: ports{
|
||||||
|
Ports: []port{
|
||||||
|
{
|
||||||
|
PortID: invalidStreamMACAddress.Port,
|
||||||
|
State: state{
|
||||||
|
State: "open",
|
||||||
|
},
|
||||||
|
Service: service{
|
||||||
|
Name: "rtsp",
|
||||||
|
Product: invalidStreamMACAddress.Device,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// File exists
|
||||||
// Two invalid targets, no error
|
// Two invalid targets, no error
|
||||||
{
|
{
|
||||||
fileExists: true,
|
fileExists: true,
|
||||||
@@ -172,10 +214,12 @@ func TestNmapParseResults(t *testing.T) {
|
|||||||
streamsXML: &nmapResult{
|
streamsXML: &nmapResult{
|
||||||
Hosts: []host{
|
Hosts: []host{
|
||||||
{
|
{
|
||||||
Address: address{
|
Addresses: []address{
|
||||||
|
address{
|
||||||
Addr: invalidStreamNoAddress.Address,
|
Addr: invalidStreamNoAddress.Address,
|
||||||
AddrType: "ipv4",
|
AddrType: "ipv4",
|
||||||
},
|
},
|
||||||
|
},
|
||||||
Ports: ports{
|
Ports: ports{
|
||||||
Ports: []port{
|
Ports: []port{
|
||||||
{
|
{
|
||||||
@@ -192,10 +236,12 @@ func TestNmapParseResults(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Address: address{
|
Addresses: []address{
|
||||||
|
address{
|
||||||
Addr: invalidStreamNoPort.Address,
|
Addr: invalidStreamNoPort.Address,
|
||||||
AddrType: "ipv4",
|
AddrType: "ipv4",
|
||||||
},
|
},
|
||||||
|
},
|
||||||
Ports: ports{
|
Ports: ports{
|
||||||
Ports: []port{
|
Ports: []port{
|
||||||
{
|
{
|
||||||
@@ -226,10 +272,12 @@ func TestNmapParseResults(t *testing.T) {
|
|||||||
streamsXML: &nmapResult{
|
streamsXML: &nmapResult{
|
||||||
Hosts: []host{
|
Hosts: []host{
|
||||||
{
|
{
|
||||||
Address: address{
|
Addresses: []address{
|
||||||
|
address{
|
||||||
Addr: "Camera with closed ports",
|
Addr: "Camera with closed ports",
|
||||||
AddrType: "ipv4",
|
AddrType: "ipv4",
|
||||||
},
|
},
|
||||||
|
},
|
||||||
Ports: ports{
|
Ports: ports{
|
||||||
Ports: []port{
|
Ports: []port{
|
||||||
{
|
{
|
||||||
@@ -246,7 +294,8 @@ func TestNmapParseResults(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Address: address{
|
Addresses: []address{
|
||||||
|
address{
|
||||||
Addr: "Camera with closed ports",
|
Addr: "Camera with closed ports",
|
||||||
AddrType: "ipv4",
|
AddrType: "ipv4",
|
||||||
},
|
},
|
||||||
@@ -254,6 +303,7 @@ func TestNmapParseResults(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
},
|
||||||
// XML Unmarshal error
|
// XML Unmarshal error
|
||||||
{
|
{
|
||||||
fileExists: true,
|
fileExists: true,
|
||||||
@@ -314,6 +364,9 @@ func TestNmapParseResults(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert.Equal(t, true, foundStream, "wrong streams parsed")
|
assert.Equal(t, true, foundStream, "wrong streams parsed")
|
||||||
|
if foundStream == false {
|
||||||
|
fmt.Printf("%+v\n", results)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert.Equal(t, len(test.expectedStreams), len(results), "wrong streams parsed")
|
assert.Equal(t, len(test.expectedStreams), len(results), "wrong streams parsed")
|
||||||
@@ -366,10 +419,12 @@ func TestDiscover(t *testing.T) {
|
|||||||
streamsXML: &nmapResult{
|
streamsXML: &nmapResult{
|
||||||
Hosts: []host{
|
Hosts: []host{
|
||||||
{
|
{
|
||||||
Address: address{
|
Addresses: []address{
|
||||||
|
address{
|
||||||
Addr: validStream1.Address,
|
Addr: validStream1.Address,
|
||||||
AddrType: "ipv4",
|
AddrType: "ipv4",
|
||||||
},
|
},
|
||||||
|
},
|
||||||
Ports: ports{
|
Ports: ports{
|
||||||
Ports: []port{
|
Ports: []port{
|
||||||
{
|
{
|
||||||
@@ -386,10 +441,12 @@ func TestDiscover(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Address: address{
|
Addresses: []address{
|
||||||
|
address{
|
||||||
Addr: validStream2.Address,
|
Addr: validStream2.Address,
|
||||||
AddrType: "ipv4",
|
AddrType: "ipv4",
|
||||||
},
|
},
|
||||||
|
},
|
||||||
Ports: ports{
|
Ports: ports{
|
||||||
Ports: []port{
|
Ports: []port{
|
||||||
{
|
{
|
||||||
@@ -420,10 +477,12 @@ func TestDiscover(t *testing.T) {
|
|||||||
streamsXML: &nmapResult{
|
streamsXML: &nmapResult{
|
||||||
Hosts: []host{
|
Hosts: []host{
|
||||||
{
|
{
|
||||||
Address: address{
|
Addresses: []address{
|
||||||
|
address{
|
||||||
Addr: validStream1.Address,
|
Addr: validStream1.Address,
|
||||||
AddrType: "ipv4",
|
AddrType: "ipv4",
|
||||||
},
|
},
|
||||||
|
},
|
||||||
Ports: ports{
|
Ports: ports{
|
||||||
Ports: []port{
|
Ports: []port{
|
||||||
{
|
{
|
||||||
@@ -440,10 +499,12 @@ func TestDiscover(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Address: address{
|
Addresses: []address{
|
||||||
|
address{
|
||||||
Addr: validStream2.Address,
|
Addr: validStream2.Address,
|
||||||
AddrType: "ipv4",
|
AddrType: "ipv4",
|
||||||
},
|
},
|
||||||
|
},
|
||||||
Ports: ports{
|
Ports: ports{
|
||||||
Ports: []port{
|
Ports: []port{
|
||||||
{
|
{
|
||||||
@@ -477,10 +538,12 @@ func TestDiscover(t *testing.T) {
|
|||||||
streamsXML: &nmapResult{
|
streamsXML: &nmapResult{
|
||||||
Hosts: []host{
|
Hosts: []host{
|
||||||
{
|
{
|
||||||
Address: address{
|
Addresses: []address{
|
||||||
|
address{
|
||||||
Addr: validStream1.Address,
|
Addr: validStream1.Address,
|
||||||
AddrType: "ipv4",
|
AddrType: "ipv4",
|
||||||
},
|
},
|
||||||
|
},
|
||||||
Ports: ports{
|
Ports: ports{
|
||||||
Ports: []port{
|
Ports: []port{
|
||||||
{
|
{
|
||||||
@@ -497,10 +560,12 @@ func TestDiscover(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Address: address{
|
Addresses: []address{
|
||||||
|
address{
|
||||||
Addr: validStream2.Address,
|
Addr: validStream2.Address,
|
||||||
AddrType: "ipv4",
|
AddrType: "ipv4",
|
||||||
},
|
},
|
||||||
|
},
|
||||||
Ports: ports{
|
Ports: ports{
|
||||||
Ports: []port{
|
Ports: []port{
|
||||||
{
|
{
|
||||||
@@ -533,10 +598,12 @@ func TestDiscover(t *testing.T) {
|
|||||||
streamsXML: &nmapResult{
|
streamsXML: &nmapResult{
|
||||||
Hosts: []host{
|
Hosts: []host{
|
||||||
{
|
{
|
||||||
Address: address{
|
Addresses: []address{
|
||||||
|
address{
|
||||||
Addr: invalidStreamNoAddress.Address,
|
Addr: invalidStreamNoAddress.Address,
|
||||||
AddrType: "ipv4",
|
AddrType: "ipv4",
|
||||||
},
|
},
|
||||||
|
},
|
||||||
Ports: ports{
|
Ports: ports{
|
||||||
Ports: []port{
|
Ports: []port{
|
||||||
{
|
{
|
||||||
@@ -553,10 +620,12 @@ func TestDiscover(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Address: address{
|
Addresses: []address{
|
||||||
|
address{
|
||||||
Addr: invalidStreamNoPort.Address,
|
Addr: invalidStreamNoPort.Address,
|
||||||
AddrType: "ipv4",
|
AddrType: "ipv4",
|
||||||
},
|
},
|
||||||
|
},
|
||||||
Ports: ports{
|
Ports: ports{
|
||||||
Ports: []port{
|
Ports: []port{
|
||||||
{
|
{
|
||||||
@@ -597,10 +666,12 @@ func TestDiscover(t *testing.T) {
|
|||||||
streamsXML: &nmapResult{
|
streamsXML: &nmapResult{
|
||||||
Hosts: []host{
|
Hosts: []host{
|
||||||
{
|
{
|
||||||
Address: address{
|
Addresses: []address{
|
||||||
|
address{
|
||||||
Addr: "Camera with closed ports",
|
Addr: "Camera with closed ports",
|
||||||
AddrType: "ipv4",
|
AddrType: "ipv4",
|
||||||
},
|
},
|
||||||
|
},
|
||||||
Ports: ports{
|
Ports: ports{
|
||||||
Ports: []port{
|
Ports: []port{
|
||||||
{
|
{
|
||||||
@@ -617,13 +688,15 @@ func TestDiscover(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Address: address{
|
Addresses: []address{
|
||||||
|
address{
|
||||||
Addr: "Camera with closed ports",
|
Addr: "Camera with closed ports",
|
||||||
AddrType: "ipv4",
|
AddrType: "ipv4",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
},
|
||||||
targets: "localhost",
|
targets: "localhost",
|
||||||
ports: "554",
|
ports: "554",
|
||||||
resultFilePath: "/tmp/results.xml",
|
resultFilePath: "/tmp/results.xml",
|
||||||
|
|||||||
+2
-2
@@ -11,7 +11,7 @@ type nmapResult struct {
|
|||||||
// Host represents a host discovered during a scan
|
// Host represents a host discovered during a scan
|
||||||
type host struct {
|
type host struct {
|
||||||
XMLName xml.Name `xml:"host"`
|
XMLName xml.Name `xml:"host"`
|
||||||
Address address `xml:"address"`
|
Addresses []address `xml:"address"`
|
||||||
Ports ports `xml:"ports"`
|
Ports ports `xml:"ports"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ type host struct {
|
|||||||
type address struct {
|
type address struct {
|
||||||
XMLName xml.Name `xml:"address"`
|
XMLName xml.Name `xml:"address"`
|
||||||
Addr string `xml:"addr,attr"`
|
Addr string `xml:"addr,attr"`
|
||||||
AddrType string `xml:"addrType,attr"`
|
AddrType string `xml:"addrType,attr" validate:"eq=ipv4|eq=ipv6"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ports is the list of openned ports on a host
|
// Ports is the list of openned ports on a host
|
||||||
|
|||||||
Reference in New Issue
Block a user