From 7f83f720d80cb210a513e5455242ec92290d5b33 Mon Sep 17 00:00:00 2001 From: Christopher Talib Date: Wed, 10 Jun 2020 12:31:07 +0200 Subject: [PATCH] save --- matcher/main.go | 4 +- plugins/shodan.go | 110 +++++++++++++++++++++++----------------------- 2 files changed, 57 insertions(+), 57 deletions(-) diff --git a/matcher/main.go b/matcher/main.go index 508d7ac..ac2b6ea 100644 --- a/matcher/main.go +++ b/matcher/main.go @@ -200,7 +200,7 @@ Node(func: allofterms(full, $a)) { } if len(n.Result) != 0 { time.Sleep(time.Duration(2) * time.Second) - logrus.Info("Found match for ", target) + logrus.Info("Found paste match for ", target) // TODO: review time and id to be updated on new resulsts for _, res := range n.Result { @@ -372,7 +372,7 @@ func runShodanMatcher(target string, graphClient *dgo.Dgraph) { } if len(n.Result) != 0 { time.Sleep(time.Duration(2) * time.Second) - logrus.Info("Found match for ", target) + logrus.Info("Found shodan match for ", target) // TODO: review time and id to be updated on new resulsts for _, res := range n.Result { diff --git a/plugins/shodan.go b/plugins/shodan.go index 9decda4..1579951 100644 --- a/plugins/shodan.go +++ b/plugins/shodan.go @@ -72,66 +72,66 @@ func (s *ShodanPlugin) doRun(graphClient *dgo.Dgraph) { shodanNode := models.BuildShodanNode(banner) // first filter poc - // if shodanNode.Data.HTML != "" { - if !filters.RunIPFilters(shodanNode.HostData.IP) { - hostnames := shodanNode.HostData.Hostnames - var hostNotInFilters, domainNotInFilters bool - if len(hostnames) != 0 { - for _, hostname := range hostnames { - hostNotInFilters = filters.RunDomainFilters(hostname) - if hostNotInFilters { - // logrus.Info("host", hostname " not in filters") - // keep track of new hostnames - // saveSingleValues(conn, "shodan_stream", "hostname", shodanNode.ID, hostname) + if shodanNode.HostData.HTML != "" { + if !filters.RunIPFilters(shodanNode.HostData.IP) { + hostnames := shodanNode.HostData.Hostnames + var hostNotInFilters, domainNotInFilters bool + if len(hostnames) != 0 { + for _, hostname := range hostnames { + hostNotInFilters = filters.RunDomainFilters(hostname) + if hostNotInFilters { + logrus.Info("host", hostname, " not in filters") + // keep track of new hostnames + // saveSingleValues(conn, "shodan_stream", "hostname", shodanNode.ID, hostname) + } } } + domains := shodanNode.HostData.Domains + if len(domains) != 0 { + for _, domain := range domains { + domainNotInFilters = filters.RunDomainFilters(domain) + logrus.Info("domain", domain, "not in filters") + // keep trakc of new domains + // saveSingleValues(conn, "shodan_stream", "domain", shodanNode.ID, domain) + } + } + if domainNotInFilters && hostNotInFilters { + // models.SaveShodanNode("raw_shodan.json", shodanNode) + mainNode := models.BuildNode("shodan", "shodan_stream", shodanNode.ID) + models.SaveNode("nodes.json", mainNode) + // edge := models.BuildEdge("shodan", structs.Map(shodanNode), structs.Map(mainNode)) + // models.SaveEdge(edge) + e := models.Node{ + ID: mainNode.ID, + Type: mainNode.Type, + NData: mainNode.NData, + Created: mainNode.Created, + Modified: mainNode.Modified, + ShodanNode: *shodanNode, + } + + ctx := context.Background() + mu := &api.Mutation{ + CommitNow: true, + } + + pb, err := json.Marshal(e) + if err != nil { + logrus.Fatal(err) + } + + mu.SetJson = pb + + _, err = graphClient.NewTxn().Mutate(ctx, mu) + if err != nil { + logrus.Error(err) + } + } + } else { + logrus.Info(shodanNode.HostData.IP, "is akamain") } - domains := shodanNode.HostData.Domains - if len(domains) != 0 { - for _, domain := range domains { - domainNotInFilters = filters.RunDomainFilters(domain) - // logrus.Info("domain", domain, "not in filters") - // keep trakc of new domains - // saveSingleValues(conn, "shodan_stream", "domain", shodanNode.ID, domain) - } - } - if domainNotInFilters && hostNotInFilters { - // models.SaveShodanNode("raw_shodan.json", shodanNode) - mainNode := models.BuildNode("shodan", "shodan_stream", shodanNode.ID) - models.SaveNode("nodes.json", mainNode) - // edge := models.BuildEdge("shodan", structs.Map(shodanNode), structs.Map(mainNode)) - // models.SaveEdge(edge) - e := models.Node{ - ID: mainNode.ID, - Type: mainNode.Type, - NData: mainNode.NData, - Created: mainNode.Created, - Modified: mainNode.Modified, - ShodanNode: *shodanNode, - } - - ctx := context.Background() - mu := &api.Mutation{ - CommitNow: true, - } - - pb, err := json.Marshal(e) - if err != nil { - logrus.Fatal(err) - } - - mu.SetJson = pb - - _, err = graphClient.NewTxn().Mutate(ctx, mu) - if err != nil { - logrus.Error(err) - } - } - } else { - logrus.Info(shodanNode.HostData.IP, "is akamain") } } - // } } }