SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.
Python attacksurfacecticybersecurityfootprintinghackinginformation-gatheringinformation-securityinfosecintelligence-gatheringosintosint-frameworkosint-reconnaissanceosint-toolpentestingpythonreconsecurity-toolsthreat-intelligencethreatintel
Search bug fixes and false positive flagging support.
smicallefc47ac3568f71
diff --git a/dyn/scaninfo.tmpl b/dyn/scaninfo.tmplindex 6e1ade7b..99fcb69f 100644--- a/dyn/scaninfo.tmpl+++ b/dyn/scaninfo.tmpl@@ -34,6 +34,13 @@<a id='btn-forceatlas' rel="tooltip" data-title="Force Layout" class="btn-inverse btn" onClick='vizUpdate("force")'><b>F</b></a><a id='btn-saveimage' rel="tooltip" data-title="Save Image" class="btn-inverse btn dropdown-toggle" onClick='vizUpdate("download")'><i class='icon-picture icon-white'></i></a></div>+ <div id='modifyactions' class="btn-group pull-right">+ <a id='btn-setfp' rel="tooltip" data-title="Set/Unset False Positive flag" class="btn-warning btn dropdown-toggle" data-toggle="dropdown"><i class='icon-ban-circle icon-white'></i></a>+ <ul class="dropdown-menu">+ <li><a href='#' class='link' onClick='setFp(1)'>Set False Positive flag</a></li>+ <li><a href='#' class='link' onClick='setFp(0)'>Unset False Positive flag</a></li>+ </ul>+ </div></div><script src="/static/js/sigma.min.js"></script><script src="/static/js/sigma.parsers.json.min.js"></script>@@ -57,6 +64,49 @@}});+ function switchSelectAll() {+ if (!$("#checkall")[0].checked) {+ $("input[id*=cb_]").prop('checked', false);+ } else {+ $("input[id*=cb_]").prop('checked', true);+ }+ }++ function getSelected() {+ ids = [];+ $("input[id*=cb_]").each(function(i, obj) {+ if (obj.checked) {+ ids[ids.length] = obj.id.replace("cb_", "");+ }+ });++ return ids;+ }++ function setFp(flag) {+ sel = getSelected();+ if (sel.length == 0) {+ alert("You need to select at least one record.");+ return false;+ }+ data = JSON.stringify(sel);+ $("#loader").show();+ sf.fetchData('${docroot}/resultsetfp', {'id': '${id}', 'fp': flag, 'resultids': data }, function(ret) {+ $("#loader").hide();+ if (ret[0] == "SUCCESS") {+ refresh();+ return;+ }+ if (ret[0] == "WARNING") {+ alert(ret[1]);+ return;+ }+ if (ret[0] == "ERROR") {+ alert("There was an error setting false positives because: " + ret[1] + "\nIf you believe this to be an error, please log out and log back in, and if the problem repeats, report this as a bug.");+ }+ });+ }+function navTo(target) {var targets = [ "btn-browse", "btn-info", "btn-log","btn-export", "btn-viz", "btn-status", "btn-graph" ]@@ -71,6 +121,7 @@$("#breadcrumbs").remove();$("#customtabview").hide();$("#customvizview").hide();+ $("#modifyactions").hide();currentSection = targetdataloaders = []}@@ -88,6 +139,7 @@// Remove pre-existing tables if they exist$("#scansummary-content").remove();navTo("btn-search");+ $("#modifyactions").hide();$("#loader").show();$("#btn-export").show();$("#btn-refresh").show();@@ -104,7 +156,7 @@crumbs += "'browseEventData(\"" + instanceId + "\",\"" + currentTypeName + "\",\"" + typeName + "\",\"full\");'>";crumbs += unescape(currentTypeName) + "</a><span class='divider'>></span></li>";}- crumbs += "<li>Search results for '" + $(query).text() + "'";+ crumbs += "<li>Search results";crumbs += " (" + data.length + " records)</li></ul>";if (data.length == 0) {@@ -127,7 +179,8 @@//table += "</pre></td><td><pre style='border: 0px; background-color: inherit'>" + data[i][7];//table += "</pre></td><td><pre style='border: 0px; background-color: inherit'>" + data[i][5];//table += "</pre></td><td><pre style='border: 0px; background-color: inherit'>" + data[i][6];- table += "</pre></td><td><pre style='border: 0px; background-color: inherit'>" + data[i][2];+ table += "</pre></td><td><pre style='border: 0px; background-color: inherit'>";+ table += sf.replace_sfurltag(data[i][2]);table += "</pre></td><td><pre style='border: 0px; background-color: inherit'>" + data[i][3];table += "</pre></td><td><pre style='border: 0px; background-color: inherit'>" + data[i][0];table += "</pre></td>";@@ -380,7 +433,7 @@}// Detailed view of data for an event type for a scan- function browseEventData(instanceId, eventTypeLabel, eventType, format) {+ function browseEventData(instanceId, eventTypeLabel, eventType, format, filterFP=false) {$("#scansummary-content").remove();$("#breadcrumbs").remove();$("#loader").show();@@ -392,31 +445,69 @@$("#scanreminder").hide();currentType = eventType;currentTypeName = eventTypeLabel;- refresh = function() { browseEventData(instanceId, eventTypeLabel, eventType, format); }- browseUpdate = function(newformat) { browseEventData(instanceId, eventTypeLabel, eventType, newformat); }+ refresh = function() { browseEventData(instanceId, eventTypeLabel, eventType, format, filterFP); }+ browseUpdate = function(newformat) { browseEventData(instanceId, eventTypeLabel, eventType, newformat, filterFP); }if (format == 'full') {$("#btn-fullview").addClass("active");$("#btn-uniqueview").removeClass("active");$("#btn-vizview").removeClass("active");+ $("#modifyactions").show();sf.fetchData('${docroot}/scaneventresults', {'id': instanceId, 'eventType': eventType }, function(data) {+ totalcount = 0;+ fpcount = 0;+ for (var i = 0; i < data.length; i++) {+ totalcount++;+ if (data[i][8] == "1") {+ fpcount++;+ }+ }var crumbs = " <ul class='breadcrumb' id='breadcrumbs'> <li><a class='link' onClick='browseEventList(\"" + instanceId + "\");'>Browse</a>";crumbs += " <span class='divider'>></span></li> <li><a class='link' onClick=";- crumbs += "'browseEventData(\"" + instanceId + "\",\"" + eventTypeLabel + "\",\"" + eventType + "\",\"" + format + "\");'>";- crumbs += unescape(eventTypeLabel) + "</a></li></ul>";+ crumbs += "'browseEventData(\"" + instanceId + "\",\"" + eventTypeLabel + "\",\"" + eventType + "\",\"";+ crumbs += format + "\", " + filterFP + ");'>";+ crumbs += unescape(eventTypeLabel) + "</a></li>";+ if (fpcount > 0) {+ crumbs += "<li class='pull-right' style='text-align: center'><i class='icon-ban-circle' /> Hide " + fpcount + " False Positives: ";+ crumbs += "<input style='vertical-align: top' type='checkbox' ";+ crumbs += "onClick=\"browseEventData('" + instanceId + "', '" + eventTypeLabel +"', '" + eventType + "'";+ crumbs += ",'" + format + "', ";+ if (!filterFP) {+ fp = 1;+ ch = "";+ } else {+ fp = 0;+ ch = "checked";+ }+ crumbs += fp + ")\" " + ch + "></input></li>";+ }+ crumbs += "</ul>";var table = "<table id='scansummary-content' class='table table-bordered table-striped small'>";- table += "<thead><tr> <th>Data Element</th></th>";+ table += "<thead><tr>";+ table += "<th style='text-align: center'><input id='checkall' type='checkbox' onClick='switchSelectAll()'>";+ table += "</th>";+ table += "<th>Data Element</th></th>";table += "<th>Source Data Element</th><th>Source Module</th><th>Identified</th></tr></thead><tbody>";for (var i = 0; i < data.length; i++) {- table += "<tr><td><pre style='border: 0px; background-color: inherit'>";+ if (filterFP && data[i][8] == "1") {+ continue;+ }+ table += "<tr>";+ table += "<td style='text-align: center'><input type='checkbox' id='cb_" + data[i][7] + "'>";+ if (data[i][8] == "1") {+ table += "<br><i class='icon-ban-circle' style='vertical-align: bottom' />";+ }+ table += "</td>";+ table += "<td><pre style='border: 0px; background-color: inherit'>";//table += "<a href='${docroot}/entityinfo?id=" + data[i][7] + "'>" + data[i][1] + "</a>";table += sf.replace_sfurltag(data[i][1]);// for debug//table += "</pre></td><td><pre style='border: 0px; background-color: inherit'>" + data[i][7];//table += "</pre></td><td><pre style='border: 0px; background-color: inherit'>" + data[i][5];//table += "</pre></td><td><pre style='border: 0px; background-color: inherit'>" + data[i][6];- table += "</pre></td><td><pre style='border: 0px; background-color: inherit'>" + data[i][2];+ table += "</pre></td><td><pre style='border: 0px; background-color: inherit'>";+ table += sf.replace_sfurltag(data[i][2]);table += "</pre></td><td><pre style='border: 0px; background-color: inherit'>" + data[i][3];table += "</pre></td><td><pre style='border: 0px; background-color: inherit'>" + data[i][0];table += "</pre></td>";@@ -425,6 +516,25 @@table += "</tbody></table>"$("#loader").fadeOut(500);$("#mainbody").append(crumbs + table);+ lastChecked = null;+ var chkboxes = $('input[id*=cb_]');+ chkboxes.click(function(e) {+ if(!lastChecked) {+ lastChecked = this;+ return;+ }++ if(e.shiftKey) {+ var start = chkboxes.index(this);+ var end = chkboxes.index(lastChecked);++ chkboxes.slice(Math.min(start,end), Math.max(start,end)+ 1).prop('checked', lastChecked.checked);++ }++ lastChecked = this;+ });+});}@@ -432,11 +542,28 @@$("#btn-uniqueview").addClass("active");$("#btn-fullview").removeClass("active");$("#btn-vizview").removeClass("active");- sf.fetchData('${docroot}/scaneventresultsunique', {'id': instanceId, 'eventType': eventType }, function(data) {+ if (filterFP == "0") {+ filterFP = null;+ }+ sf.fetchData('${docroot}/scaneventresultsunique', {'id': instanceId, 'eventType': eventType, 'filterfp': filterFP }, function(data) {var crumbs = " <ul class='breadcrumb' id='breadcrumbs'> <li><a class='link' onClick='browseEventList(\"" + instanceId + "\");'>Browse</a>";crumbs += " <span class='divider'>></span></li> <li><a class='link' onClick=";- crumbs += "'browseEventData(\"" + instanceId + "\",\"" + eventTypeLabel + "\",\"" + eventType + "\",\"" + format + "\");'>";- crumbs += unescape(eventTypeLabel) + "</a></li></ul>";+ crumbs += "'browseEventData(\"" + instanceId + "\",\"" + eventTypeLabel + "\",\"" + eventType + "\",\"" + format;+ crumbs += "\", " + filterFP + ");'>";+ crumbs += unescape(eventTypeLabel) + "</a></li>";+ crumbs += "<li class='pull-right' style='text-align: center'><i class='icon-ban-circle' /> Hide False Positives: ";+ crumbs += "<input style='vertical-align: top' type='checkbox' ";+ crumbs += "onClick=\"browseEventData('" + instanceId + "', '" + eventTypeLabel +"', '" + eventType + "'";+ crumbs += ",'" + format + "', ";+ if (!filterFP) {+ fp = 1;+ ch = "";+ } else {+ fp = 0;+ ch = "checked";+ }+ crumbs += fp + ")\" " + ch + "></input></li>";+ crumbs += "</ul>";var table = "<table id='scansummary-content' class='table table-bordered table-striped small'>";table += "<thead><tr> <th>Unique Data Element</th><th>Occurrences</th></tr></thead><tbody>";diff --git a/sfdb.py b/sfdb.pyindex e4595ed6..79a5fa2a 100644--- a/sfdb.py+++ b/sfdb.py@@ -15,10 +15,14 @@ import reimport timefrom sflib import SpiderFoot-+# SQLite doesn't support regex queries, so we create+# a custom function to do so..def __dbregex__(qry, data):- rx = re.compile(qry, re.IGNORECASE)- ret = rx.search(data)+ try:+ rx = re.compile(qry, re.IGNORECASE|re.DOTALL)+ ret = rx.match(data)+ except BaseException as e:+ return Falsereturn ret is not None@@ -74,6 +78,7 @@ class SpiderFootDb:risk INT NOT NULL DEFAULT 0, \module VARCHAR NOT NULL, \data VARCHAR, \+ false_positive INT NOT NULL DEFAULT 0, \source_event_hash VARCHAR DEFAULT 'ROOT' \)","CREATE INDEX idx_scan_results_id ON tbl_scan_results (scan_instance_id)",@@ -240,7 +245,7 @@ class SpiderFootDb:# - value (search values for a specific string, if omitted search all)# - regex (search values for a regular expression)# ** at least two criteria must be set **- def search(self, criteria):+ def search(self, criteria, filterFp=False):if criteria.values().count(None) == 3:return False@@ -248,11 +253,15 @@ class SpiderFootDb:qry = "SELECT ROUND(c.generated) AS generated, c.data, \s.data as 'source_data', \c.module, c.type, c.confidence, c.visibility, c.risk, c.hash, \- c.source_event_hash, t.event_descr, c.scan_instance_id \+ c.source_event_hash, t.event_descr, t.event_type, c.scan_instance_id, \+ c.false_positive as 'fp', s.false_positive as 'parent_fp' \FROM tbl_scan_results c, tbl_scan_results s, tbl_event_types t \WHERE s.scan_instance_id = c.scan_instance_id AND \t.event = c.type AND c.source_event_hash = s.hash "+ if filterFp:+ qry += " AND c.false_positive <> 1 "+if criteria.get('scan_id') is not None:qry += "AND c.scan_instance_id = ? "qvars.append(criteria['scan_id'])@@ -274,6 +283,8 @@ class SpiderFootDb:qry += " ORDER BY c.data"try:+ #print qry+ #print str(qvars)self.dbh.execute(qry, qvars)return self.dbh.fetchall()except sqlite3.Error as e:@@ -378,31 +389,13 @@ class SpiderFootDb:except sqlite3.Error as e:self.sf.error("SQL error encountered when fetching result summary: " + e.args[0])- # Obtain the ROOT event for a scan: Must be same output as scanResultEvent!- def scanRootEvent(self, instanceId):- qry = "SELECT ROUND(c.generated) AS generated, c.data, \- s.data as 'source_data', \- c.module, c.type, c.confidence, c.visibility, c.risk, c.hash, \- c.source_event_hash, t.event_descr, t.event_type, s.scan_instance_id \- FROM tbl_scan_results c, tbl_scan_results s, tbl_event_types t \- WHERE c.scan_instance_id = ? AND c.source_event_hash = s.hash AND \- s.scan_instance_id = c.scan_instance_id AND \- t.event = c.type AND c.source_event_hash = 'ROOT'"-- qvars = [instanceId]-- try:- self.dbh.execute(qry, qvars)- return self.dbh.fetchone()- except sqlite3.Error as e:- self.sf.error("SQL error encountered when fetching ROOT event: " + e.args[0])-# Obtain the data for a scan and event type- def scanResultEvent(self, instanceId, eventType='ALL'):+ def scanResultEvent(self, instanceId, eventType='ALL', filterFp=False):qry = "SELECT ROUND(c.generated) AS generated, c.data, \s.data as 'source_data', \c.module, c.type, c.confidence, c.visibility, c.risk, c.hash, \- c.source_event_hash, t.event_descr, t.event_type, s.scan_instance_id \+ c.source_event_hash, t.event_descr, t.event_type, s.scan_instance_id, \+ c.false_positive as 'fp', s.false_positive as 'parent_fp' \FROM tbl_scan_results c, tbl_scan_results s, tbl_event_types t \WHERE c.scan_instance_id = ? AND c.source_event_hash = s.hash AND \s.scan_instance_id = c.scan_instance_id AND \@@ -414,6 +407,9 @@ class SpiderFootDb:qry += " AND c.type = ?"qvars.append(eventType)+ if filterFp:+ qry += " AND c.false_positive <> 1"+qry += " ORDER BY c.data"try:@@ -423,7 +419,7 @@ class SpiderFootDb:self.sf.error("SQL error encountered when fetching result events: " + e.args[0])# Obtain a unique list of elements- def scanResultEventUnique(self, instanceId, eventType='ALL'):+ def scanResultEventUnique(self, instanceId, eventType='ALL', filterFp=False):qry = "SELECT DISTINCT data, type, COUNT(*) FROM tbl_scan_results \WHERE scan_instance_id = ?"qvars = [instanceId]@@ -432,6 +428,9 @@ class SpiderFootDb:qry += " AND type = ?"qvars.append(eventType)+ if filterFp:+ qry += " AND false_positive <> 1"+qry += " GROUP BY type, data ORDER BY COUNT(*)"try:@@ -490,6 +489,21 @@ class SpiderFootDb:except sqlite3.Error as e:self.sf.error("SQL error encountered when deleting scan: " + e.args[0])+ # Set the false positive flag for a result+ def scanResultsUpdateFP(self, instanceId, resultHashes, fpFlag):+ for resultHash in resultHashes:+ qry = "UPDATE tbl_scan_results SET false_positive = ? WHERE \+ scan_instance_id = ? AND hash = ?"+ qvars = [fpFlag, instanceId, resultHash]+ try:+ self.dbh.execute(qry, qvars)+ except sqlite3.Error as e:+ self.sf.error("SQL error encountered when updating F/P: " + e.args[0], False)+ return False++ self.conn.commit()+ return True+# Store the default configurationdef configSet(self, optMap=dict()):qry = "REPLACE INTO tbl_config (scope, opt, val) VALUES (?, ?, ?)"@@ -658,13 +672,14 @@ class SpiderFootDb:# Get the source IDs, types and data for a set of IDs- def scanElementSources(self, instanceId, elementIdList):+ def scanElementSourcesDirect(self, instanceId, elementIdList):# the output of this needs to be aligned with scanResultEvent,# as other functions call both expecting the same output.qry = "SELECT ROUND(c.generated) AS generated, c.data, \s.data as 'source_data', \c.module, c.type, c.confidence, c.visibility, c.risk, c.hash, \- c.source_event_hash, t.event_descr, t.event_type, s.scan_instance_id \+ c.source_event_hash, t.event_descr, t.event_type, s.scan_instance_id, \+ c.false_positive as 'fp', s.false_positive as 'parent_fp' \FROM tbl_scan_results c, tbl_scan_results s, tbl_event_types t \WHERE c.scan_instance_id = ? AND c.source_event_hash = s.hash AND \s.scan_instance_id = c.scan_instance_id AND \@@ -680,3 +695,111 @@ class SpiderFootDb:return self.dbh.fetchall()except sqlite3.Error as e:self.sf.error("SQL error encountered when getting source element IDs: " + e.args[0])++ # Get the child IDs, types and data for a set of IDs+ def scanElementChildrenDirect(self, instanceId, elementIdList):+ # the output of this needs to be aligned with scanResultEvent,+ # as other functions call both expecting the same output.+ qry = "SELECT ROUND(c.generated) AS generated, c.data, \+ s.data as 'source_data', \+ c.module, c.type, c.confidence, c.visibility, c.risk, c.hash, \+ c.source_event_hash, t.event_descr, t.event_type, s.scan_instance_id, \+ c.false_positive as 'fp', s.false_positive as 'parent_fp' \+ FROM tbl_scan_results c, tbl_scan_results s, tbl_event_types t \+ WHERE c.scan_instance_id = ? AND c.source_event_hash = s.hash AND \+ s.scan_instance_id = c.scan_instance_id AND \+ t.event = c.type AND s.hash in ("+ qvars = [instanceId]++ for hashId in elementIdList:+ qry = qry + "'" + hashId + "',"+ qry += "'')"++ try:+ self.dbh.execute(qry, qvars)+ return self.dbh.fetchall()+ except sqlite3.Error as e:+ self.sf.error("SQL error encountered when getting child element IDs: " + e.args[0])++ # Get the full set of upstream IDs which are parents to the+ # supplied set of IDs.+ # Data has to be in the format of output from scanElementSourcesDirect+ # and produce output in the same format.+ def scanElementSourcesAll(self, instanceId, childData):+ # Get the first round of source IDs for the leafs+ keepGoing = True+ nextIds = list()+ datamap = dict()+ pc = dict()++ for row in childData:+ # these must be unique values!+ parentId = row[9]+ childId = row[8]+ datamap[childId] = row++ if parentId in pc:+ if childId not in pc[parentId]:+ pc[parentId].append(childId)+ else:+ pc[parentId] = [childId]++ # parents of the leaf set+ if parentId not in nextIds:+ nextIds.append(parentId)++ while keepGoing:+ parentSet = self.scanElementSourcesDirect(instanceId, nextIds)+ nextIds = list()+ keepGoing = False++ for row in parentSet:+ parentId = row[9]+ childId = row[8]+ datamap[childId] = row+ #print childId + " = " + str(row)++ if parentId in pc:+ if childId not in pc[parentId]:+ pc[parentId].append(childId)+ else:+ pc[parentId] = [childId]+ if parentId not in nextIds:+ nextIds.append(parentId)++ # Prevent us from looping at root+ if parentId != "ROOT":+ keepGoing = True++ datamap[parentId] = row+ return [datamap, pc]++ # Get the full set of downstream IDs which are children of the+ # supplied set of IDs+ # NOTE FOR NOW THE BEHAVIOR IS NOT THE SAME AS THE scanElementParent*+ # FUNCTIONS - THIS ONLY RETURNS IDS!!+ def scanElementChildrenAll(self, instanceId, parentIds):+ datamap = list()+ keepGoing = True+ nextIds = list()++ nextSet = self.scanElementChildrenDirect(instanceId, parentIds)+ for row in nextSet:+ datamap.append(row[8])++ for row in nextSet:+ if row[8] not in nextIds:+ nextIds.append(row[8])++ while keepGoing:+ nextSet = self.scanElementChildrenDirect(instanceId, nextIds)+ if nextSet == None or len(nextSet) == 0:+ keepGoing = False+ break++ for row in nextSet:+ datamap.append(row[8])+ nextIds = list()+ nextIds.append(row[8])++ return datamapdiff --git a/sfwebui.py b/sfwebui.pyindex 2258c921..da6e3dba 100644--- a/sfwebui.py+++ b/sfwebui.py@@ -93,6 +93,7 @@ class SpiderFootWebUi:'value': None if value == '' else value,'regex': None if regex == '' else regex}+data = dbh.search(criteria)retdata = []for row in data:@@ -100,7 +101,8 @@ class SpiderFootWebUi:escapeddata = cgi.escape(row[1])escapedsrc = cgi.escape(row[2])retdata.append([lastseen, escapeddata, escapedsrc,- row[3], row[5], row[6], row[7], row[8], row[10], row[11], row[4]])+ row[3], row[5], row[6], row[7], row[8], row[10],+ row[11], row[4], row[13], row[14]])return retdata@@ -114,13 +116,13 @@ class SpiderFootWebUi:data = dbh.scanResultEvent(id, type)fileobj = StringIO()parser = csv.writer(fileobj, dialect=dialect)- parser.writerow(["Updated", "Type", "Module", "Source", "Data"])+ parser.writerow(["Updated", "Type", "Module", "Source", "F/P", "Data"])for row in data:if row[4] == "ROOT":continuelastseen = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(row[0]))datafield = str(row[1]).replace("<SFURL>", "").replace("</SFURL>", "")- parser.writerow([lastseen, str(row[4]), str(row[3]), str(row[2]), datafield])+ parser.writerow([lastseen, str(row[4]), str(row[3]), str(row[2]), row[13], datafield])cherrypy.response.headers['Content-Disposition'] = "attachment; filename=SpiderFoot.csv"cherrypy.response.headers['Content-Type'] = "application/csv"cherrypy.response.headers['Pragma'] = "no-cache"@@ -139,13 +141,14 @@ class SpiderFootWebUi:fileobj = StringIO()parser = csv.writer(fileobj, dialect=dialect)- parser.writerow(["Scan Name", "Updated", "Type", "Module", "Source", "Data"])+ parser.writerow(["Scan Name", "Updated", "Type", "Module", "Source", "F/P", "Data"])for row in data:if row[4] == "ROOT":continuelastseen = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(row[0]))datafield = str(row[1]).replace("<SFURL>", "").replace("</SFURL>", "")- parser.writerow([scaninfo[row[12]][0], lastseen, str(row[4]), str(row[3]), str(row[2]), datafield])+ parser.writerow([scaninfo[row[12]][0], lastseen, str(row[4]), str(row[3]),+ str(row[2]), row[13], datafield])cherrypy.response.headers['Content-Disposition'] = "attachment; filename=SpiderFoot.csv"cherrypy.response.headers['Content-Type'] = "application/csv"cherrypy.response.headers['Pragma'] = "no-cache"@@ -158,12 +161,12 @@ class SpiderFootWebUi:data = self.searchBase(id, eventType, value)fileobj = StringIO()parser = csv.writer(fileobj, dialect=dialect)- parser.writerow(["Updated", "Type", "Module", "Source", "Data"])+ parser.writerow(["Updated", "Type", "Module", "Source", "F/P", "Data"])for row in data:if row[10] == "ROOT":continuedatafield = str(row[1]).replace("<SFURL>", "").replace("</SFURL>", "")- parser.writerow([row[0], str(row[10]), str(row[3]), str(row[2]), datafield])+ parser.writerow([row[0], str(row[10]), str(row[3]), str(row[2]), row[13], datafield])cherrypy.response.headers['Content-Disposition'] = "attachment; filename=SpiderFoot.csv"cherrypy.response.headers['Content-Type'] = "application/csv"cherrypy.response.headers['Pragma'] = "no-cache"@@ -176,7 +179,7 @@ class SpiderFootWebUi:types = list()dbh = SpiderFootDb(self.config)sf = SpiderFoot(self.config)- data = dbh.scanResultEvent(id)+ data = dbh.scanResultEvent(id, filterFp=True)scan = dbh.scanInstanceGet(id)root = scan[1]if gexf != "0":@@ -197,7 +200,7 @@ class SpiderFootWebUi:data = list()roots = list()for id in ids.split(','):- data = data + dbh.scanResultEvent(id)+ data = data + dbh.scanResultEvent(id, filterFp=True)roots.append(dbh.scanInstanceGet(id)[1])if gexf != "0":@@ -476,6 +479,44 @@ class SpiderFootWebUi:savesettings.exposed = True+ # Set a bunch of results (hashes) as false positive+ def resultsetfp(self, id, resultids, fp):+ dbh = SpiderFootDb(self.config)+ if fp not in ["0", "1"]:+ return json.dumps(["ERROR", "No FP flag set or not set correctly."])++ ids = json.loads(resultids)+ if not ids:+ return json.dumps(["ERROR", "No IDs supplied."])++ # Cannot set FPs if a scan is not completed+ status = dbh.scanInstanceGet(id)+ if status[5] not in [ "ABORTED", "FINISHED", "ERROR-FAILED" ]:+ return json.dumps(["WARNING", "Scan must be in a finished state when " + \+ "setting False Positives."])++ # Make sure the user doesn't set something as non-FP when the+ # parent is set as an FP.+ if fp == "0":+ data = dbh.scanElementSourcesDirect(id, ids)+ for row in data:+ if str(row[14]) == "1":+ return json.dumps(["WARNING",+ "You cannot unset an element as False Positive " + \+ "if a parent element is still False Positive."]);++ # Set all the children as FPs too.. it's only logical afterall, right?+ childs = dbh.scanElementChildrenAll(id, ids)+ allIds = ids + childs++ ret = dbh.scanResultsUpdateFP(id, allIds, fp)+ if not ret:+ return json.dumps(["ERROR", "Exception encountered."])+ else:+ return json.dumps(["SUCCESS", ""])++ resultsetfp.exposed = True+# Initiate a scandef startscan(self, scanname, scantarget, modulelist, typelist):global globalScanStatus@@ -681,24 +722,25 @@ class SpiderFootWebUi:scansummary.exposed = True# Event results for a scan- def scaneventresults(self, id, eventType):+ def scaneventresults(self, id, eventType, filterfp=False):dbh = SpiderFootDb(self.config)- data = dbh.scanResultEvent(id, eventType)+ data = dbh.scanResultEvent(id, eventType, filterfp)retdata = []for row in data:lastseen = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(row[0]))escapeddata = cgi.escape(row[1])escapedsrc = cgi.escape(row[2])retdata.append([lastseen, escapeddata, escapedsrc,- row[3], row[5], row[6], row[7], row[8]])+ row[3], row[5], row[6], row[7], row[8],+ row[13], row[14]])return json.dumps(retdata, ensure_ascii=False)scaneventresults.exposed = True# Unique event results for a scan- def scaneventresultsunique(self, id, eventType):+ def scaneventresultsunique(self, id, eventType, filterfp=False):dbh = SpiderFootDb(self.config)- data = dbh.scanResultEventUnique(id, eventType)+ data = dbh.scanResultEventUnique(id, eventType, filterfp)retdata = []for row in data:escaped = cgi.escape(row[0])@@ -723,7 +765,6 @@ class SpiderFootWebUi:scanhistory.exposed = Truedef scanelementtypediscovery(self, id, eventType):- keepGoing = Truesf = SpiderFoot(self.config)dbh = SpiderFootDb(self.config)pc = dict()@@ -731,54 +772,14 @@ class SpiderFootWebUi:# Get the events we will be tracing back fromleafSet = dbh.scanResultEvent(id, eventType)+ [datamap, pc] = dbh.scanElementSourcesAll(id, leafSet)- # Get the first round of source IDs for the leafs- nextIds = list()- for row in leafSet:- # these must be unique values!- parentId = row[9]- childId = row[8]- datamap[childId] = row-- if parentId in pc:- if childId not in pc[parentId]:- pc[parentId].append(childId)- else:- pc[parentId] = [childId]-- # parents of the leaf set- if parentId not in nextIds:- nextIds.append(parentId)-- while keepGoing:- parentSet = dbh.scanElementSources(id, nextIds)- nextIds = list()- keepGoing = False-- for row in parentSet:- parentId = row[9]- childId = row[8]- datamap[childId] = row- #print childId + " = " + str(row)-- if parentId in pc:- if childId not in pc[parentId]:- pc[parentId].append(childId)- else:- pc[parentId] = [childId]- if parentId not in nextIds:- nextIds.append(parentId)-- # Prevent us from looping at root- if parentId != "ROOT":- keepGoing = True-- datamap[parentId] = row# Delete the ROOT key as it adds no value from a viz perspectivedel pc['ROOT']retdata = dict()retdata['tree'] = sf.dataParentChildToTree(pc)retdata['data'] = datamap+return json.dumps(retdata, ensure_ascii=False)scanelementtypediscovery.exposed = True