Refactoring saving single value into a helper, adding meta names to main nodes and edges

This commit is contained in:
Christopher Talib 2020-02-07 15:27:14 +01:00
parent 93f577cae9
commit c7a52c527a
2 changed files with 24 additions and 11 deletions

33
main.go
View file

@ -50,18 +50,12 @@ func main() {
certNode := models.BuildCertNode(rawNode)
models.SaveCertNode("cert_nodes.json", certNode)
mainNode := models.BuildNode("certstream", "certstream", certNode.ID)
mainNode := models.BuildNode("node", "certstream", certNode.ID)
models.SaveNode("nodes.json", mainNode)
models.BuildEdge("certstream", rawNode.ID, mainNode.ID)
models.BuildEdge("certstream", mainNode.ID, certNode.ID)
allDomains := data.Data.LeafCert.AllDomains
var edge *models.Edge
for _, domain := range allDomains {
domainNode := models.BuildNode("certstream", "domain", domain)
models.SaveNode("nodes.json", domainNode)
edge = models.BuildEdge("certstream", certNode.ID, domainNode.ID)
models.SaveEdge(edge)
}
saveSingleValues("certstream", "domain", certNode.ID, allDomains)
// broker.SendEventToKafka(Conn, *fingerprintNode)
}
@ -75,7 +69,7 @@ func main() {
}()
// pastebin
// // pastebin
go func() {
for {
select {
@ -111,7 +105,7 @@ func main() {
ch := make(chan *shodan.HostData)
err := client.GetBannersByPorts(context.Background(), []int{80, 443, 8443, 53}, ch)
if err != nil {
logrus.Error(err)
logrus.Panic(err)
}
go func() {
@ -125,6 +119,14 @@ func main() {
}
shodanNode := models.BuildShodanNode(banner)
hostnames := shodanNode.Data.Hostnames
if len(hostnames) != 0 {
saveSingleValues("shodan_stream", "hostname", shodanNode.ID, hostnames)
}
domains := shodanNode.Data.Domains
if len(domains) != 0 {
saveSingleValues("shodan_stream", "domain", shodanNode.ID, domains)
}
models.SaveShodanNode("shodan_raw.json", shodanNode)
node := models.BuildNode("shodan", "shodan_stream", shodanNode.ID)
models.SaveNode("nodes.json", node)
@ -139,3 +141,14 @@ func main() {
wg.Wait()
}
// helpers
func saveSingleValues(source string, datatype string, originNodeID string, values []string) {
for _, value := range values {
domainNode := models.BuildNode(source, datatype, value)
models.SaveNode("nodes.json", domainNode)
edge := models.BuildEdge(source, originNodeID, domainNode.ID)
models.SaveEdge(edge)
}
}

View file

@ -87,7 +87,7 @@ func BuildEdge(source string, nodeOneUUID string, nodeTwoUUID string) *Edge {
t := time.Now()
rfc3339time := t.Format(time.RFC3339)
return &Edge{
ID: uuid.New().String(),
ID: "edge--" + uuid.New().String(),
Source: source,
NodeOneID: nodeOneUUID,
NodeTwoID: nodeTwoUUID,