No longer import hosts using their MAC addresses
This commit is contained in:
committed by
Brendan LE GLAUNEC
parent
541d64168d
commit
456f7fffc5
+13
-5
@@ -114,11 +114,19 @@ func NmapParseResults(nmapResultFilePath string) ([]Stream, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
streams = append(streams, Stream{
|
|
||||||
Device: port.Service.Product,
|
for _, addr := range host.Addresses {
|
||||||
Address: host.Address.Addr,
|
err = validate.Struct(addr)
|
||||||
Port: port.PortID,
|
if err != nil {
|
||||||
})
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
streams = append(streams, Stream{
|
||||||
|
Device: port.Service.Product,
|
||||||
|
Address: addr.Addr,
|
||||||
|
Port: port.PortID,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+121
-48
@@ -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,9 +127,11 @@ func TestNmapParseResults(t *testing.T) {
|
|||||||
streamsXML: &nmapResult{
|
streamsXML: &nmapResult{
|
||||||
Hosts: []host{
|
Hosts: []host{
|
||||||
{
|
{
|
||||||
Address: address{
|
Addresses: []address{
|
||||||
Addr: validStream1.Address,
|
address{
|
||||||
AddrType: "ipv4",
|
Addr: validStream1.Address,
|
||||||
|
AddrType: "ipv4",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Ports: ports{
|
Ports: ports{
|
||||||
Ports: []port{
|
Ports: []port{
|
||||||
@@ -141,9 +149,11 @@ func TestNmapParseResults(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Address: address{
|
Addresses: []address{
|
||||||
Addr: validStream2.Address,
|
address{
|
||||||
AddrType: "ipv4",
|
Addr: validStream2.Address,
|
||||||
|
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,9 +214,11 @@ func TestNmapParseResults(t *testing.T) {
|
|||||||
streamsXML: &nmapResult{
|
streamsXML: &nmapResult{
|
||||||
Hosts: []host{
|
Hosts: []host{
|
||||||
{
|
{
|
||||||
Address: address{
|
Addresses: []address{
|
||||||
Addr: invalidStreamNoAddress.Address,
|
address{
|
||||||
AddrType: "ipv4",
|
Addr: invalidStreamNoAddress.Address,
|
||||||
|
AddrType: "ipv4",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Ports: ports{
|
Ports: ports{
|
||||||
Ports: []port{
|
Ports: []port{
|
||||||
@@ -192,9 +236,11 @@ func TestNmapParseResults(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Address: address{
|
Addresses: []address{
|
||||||
Addr: invalidStreamNoPort.Address,
|
address{
|
||||||
AddrType: "ipv4",
|
Addr: invalidStreamNoPort.Address,
|
||||||
|
AddrType: "ipv4",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Ports: ports{
|
Ports: ports{
|
||||||
Ports: []port{
|
Ports: []port{
|
||||||
@@ -226,9 +272,11 @@ func TestNmapParseResults(t *testing.T) {
|
|||||||
streamsXML: &nmapResult{
|
streamsXML: &nmapResult{
|
||||||
Hosts: []host{
|
Hosts: []host{
|
||||||
{
|
{
|
||||||
Address: address{
|
Addresses: []address{
|
||||||
Addr: "Camera with closed ports",
|
address{
|
||||||
AddrType: "ipv4",
|
Addr: "Camera with closed ports",
|
||||||
|
AddrType: "ipv4",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Ports: ports{
|
Ports: ports{
|
||||||
Ports: []port{
|
Ports: []port{
|
||||||
@@ -246,9 +294,11 @@ func TestNmapParseResults(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Address: address{
|
Addresses: []address{
|
||||||
Addr: "Camera with closed ports",
|
address{
|
||||||
AddrType: "ipv4",
|
Addr: "Camera with closed ports",
|
||||||
|
AddrType: "ipv4",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -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,9 +419,11 @@ func TestDiscover(t *testing.T) {
|
|||||||
streamsXML: &nmapResult{
|
streamsXML: &nmapResult{
|
||||||
Hosts: []host{
|
Hosts: []host{
|
||||||
{
|
{
|
||||||
Address: address{
|
Addresses: []address{
|
||||||
Addr: validStream1.Address,
|
address{
|
||||||
AddrType: "ipv4",
|
Addr: validStream1.Address,
|
||||||
|
AddrType: "ipv4",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Ports: ports{
|
Ports: ports{
|
||||||
Ports: []port{
|
Ports: []port{
|
||||||
@@ -386,9 +441,11 @@ func TestDiscover(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Address: address{
|
Addresses: []address{
|
||||||
Addr: validStream2.Address,
|
address{
|
||||||
AddrType: "ipv4",
|
Addr: validStream2.Address,
|
||||||
|
AddrType: "ipv4",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Ports: ports{
|
Ports: ports{
|
||||||
Ports: []port{
|
Ports: []port{
|
||||||
@@ -420,9 +477,11 @@ func TestDiscover(t *testing.T) {
|
|||||||
streamsXML: &nmapResult{
|
streamsXML: &nmapResult{
|
||||||
Hosts: []host{
|
Hosts: []host{
|
||||||
{
|
{
|
||||||
Address: address{
|
Addresses: []address{
|
||||||
Addr: validStream1.Address,
|
address{
|
||||||
AddrType: "ipv4",
|
Addr: validStream1.Address,
|
||||||
|
AddrType: "ipv4",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Ports: ports{
|
Ports: ports{
|
||||||
Ports: []port{
|
Ports: []port{
|
||||||
@@ -440,9 +499,11 @@ func TestDiscover(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Address: address{
|
Addresses: []address{
|
||||||
Addr: validStream2.Address,
|
address{
|
||||||
AddrType: "ipv4",
|
Addr: validStream2.Address,
|
||||||
|
AddrType: "ipv4",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Ports: ports{
|
Ports: ports{
|
||||||
Ports: []port{
|
Ports: []port{
|
||||||
@@ -477,9 +538,11 @@ func TestDiscover(t *testing.T) {
|
|||||||
streamsXML: &nmapResult{
|
streamsXML: &nmapResult{
|
||||||
Hosts: []host{
|
Hosts: []host{
|
||||||
{
|
{
|
||||||
Address: address{
|
Addresses: []address{
|
||||||
Addr: validStream1.Address,
|
address{
|
||||||
AddrType: "ipv4",
|
Addr: validStream1.Address,
|
||||||
|
AddrType: "ipv4",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Ports: ports{
|
Ports: ports{
|
||||||
Ports: []port{
|
Ports: []port{
|
||||||
@@ -497,9 +560,11 @@ func TestDiscover(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Address: address{
|
Addresses: []address{
|
||||||
Addr: validStream2.Address,
|
address{
|
||||||
AddrType: "ipv4",
|
Addr: validStream2.Address,
|
||||||
|
AddrType: "ipv4",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Ports: ports{
|
Ports: ports{
|
||||||
Ports: []port{
|
Ports: []port{
|
||||||
@@ -533,9 +598,11 @@ func TestDiscover(t *testing.T) {
|
|||||||
streamsXML: &nmapResult{
|
streamsXML: &nmapResult{
|
||||||
Hosts: []host{
|
Hosts: []host{
|
||||||
{
|
{
|
||||||
Address: address{
|
Addresses: []address{
|
||||||
Addr: invalidStreamNoAddress.Address,
|
address{
|
||||||
AddrType: "ipv4",
|
Addr: invalidStreamNoAddress.Address,
|
||||||
|
AddrType: "ipv4",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Ports: ports{
|
Ports: ports{
|
||||||
Ports: []port{
|
Ports: []port{
|
||||||
@@ -553,9 +620,11 @@ func TestDiscover(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Address: address{
|
Addresses: []address{
|
||||||
Addr: invalidStreamNoPort.Address,
|
address{
|
||||||
AddrType: "ipv4",
|
Addr: invalidStreamNoPort.Address,
|
||||||
|
AddrType: "ipv4",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Ports: ports{
|
Ports: ports{
|
||||||
Ports: []port{
|
Ports: []port{
|
||||||
@@ -597,9 +666,11 @@ func TestDiscover(t *testing.T) {
|
|||||||
streamsXML: &nmapResult{
|
streamsXML: &nmapResult{
|
||||||
Hosts: []host{
|
Hosts: []host{
|
||||||
{
|
{
|
||||||
Address: address{
|
Addresses: []address{
|
||||||
Addr: "Camera with closed ports",
|
address{
|
||||||
AddrType: "ipv4",
|
Addr: "Camera with closed ports",
|
||||||
|
AddrType: "ipv4",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Ports: ports{
|
Ports: ports{
|
||||||
Ports: []port{
|
Ports: []port{
|
||||||
@@ -617,9 +688,11 @@ func TestDiscover(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Address: address{
|
Addresses: []address{
|
||||||
Addr: "Camera with closed ports",
|
address{
|
||||||
AddrType: "ipv4",
|
Addr: "Camera with closed ports",
|
||||||
|
AddrType: "ipv4",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
+4
-4
@@ -10,16 +10,16 @@ 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"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Address is a host's address discovered during a scan
|
// Address is a host's address discovered during a scan
|
||||||
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