Skip to content

SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.

Add support for JSON exports

Brendan Coles34ac76e5e54c
diff --git a/dyn/scanlist.tmpl b/dyn/scanlist.tmpl
index da6da8ff..840b3603 100644
--- a/dyn/scanlist.tmpl
+++ b/dyn/scanlist.tmpl
@@ -117,8 +117,12 @@
var efr = document.getElementById('exportframe');
if (type == "gexf") {
efr.src = '${docroot}/scanvizmulti?ids=' + ids.join(',');
- } else {
+ } else if (type == "csv") {
efr.src = '${docroot}/scaneventresultexportmulti?ids=' + ids.join(',');
+ } else if (type == "json") {
+ efr.src = '${docroot}/scanexportjsonmulti?ids=' + ids.join(',');
+ } else {
+ console.log("Invalid export type");
}
$("#loader").fadeOut(500);
}
@@ -168,7 +172,9 @@
buttons += "<button class='btn dropdown-toggle btn-success' data-toggle='dropdown'><span class='caret'></span></button>";
buttons += "<ul class='dropdown-menu'>";
buttons += "<li><a href='javascript:exportSelected(\"csv\")'>CSV</a></li>";
- buttons += "<li><a href='javascript:exportSelected(\"gexf\")'>GEXF</a></li></ul>";
+ buttons += "<li><a href='javascript:exportSelected(\"gexf\")'>GEXF</a></li>";
+ buttons += "<li><a href='javascript:exportSelected(\"json\")'>JSON</a></li>";
+ buttons += "</ul>";
buttons += "</div>";
buttons += "<div class='btn-group pull-right'>";
diff --git a/sfwebui.py b/sfwebui.py
index a98dd2de..0973a56f 100644
--- a/sfwebui.py
+++ b/sfwebui.py
@@ -175,6 +175,45 @@ class SpiderFootWebUi:
scansearchresultexport.exposed = True
+ # Export results from multiple scans in JSON format
+ def scanexportjsonmulti(self, ids):
+ dbh = SpiderFootDb(self.config)
+ scaninfo = dict()
+
+ for id in ids.split(','):
+ scan_name = dbh.scanInstanceGet(id)[0]
+
+ if scan_name not in scaninfo:
+ scaninfo[scan_name] = []
+
+ for row in dbh.scanResultEvent(id):
+ lastseen = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(row[0]))
+ event_data = str(row[1]).replace("<SFURL>", "").replace("</SFURL>", "")
+ source_data = str(row[2])
+ source_module = str(row[3])
+ event_type = row[4]
+ false_positive = row[13]
+
+ if event_type == "ROOT":
+ continue
+
+ scaninfo[scan_name].append({
+ "data": event_data,
+ "type": event_type,
+ "source_module": source_module,
+ "source_data": source_data,
+ "false_positive": false_positive,
+ "lastseen": lastseen
+ })
+
+ cherrypy.response.headers['Content-Disposition'] = "attachment; filename=SpiderFoot.json"
+ cherrypy.response.headers['Content-Type'] = "application/json; charset=utf-8"
+ cherrypy.response.headers['Pragma'] = "no-cache"
+
+ return json.dumps(scaninfo)
+
+ scanexportjsonmulti.exposed = True
+
# Export entities from scan results for visualising
def scanviz(self, id, gexf="0"):
types = list()