SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.
Python attacksurfacecticybersecurityfootprintinghackinginformation-gatheringinformation-securityinfosecintelligence-gatheringosintosint-frameworkosint-reconnaissanceosint-toolpentestingpythonreconsecurity-toolsthreat-intelligencethreatintel
tests: resolve darglint violations
Brendan Colesfe7bceb63718
diff --git a/setup.cfg b/setup.cfgindex 56124295..21fb640e 100644--- a/setup.cfg+++ b/setup.cfg@@ -6,9 +6,6 @@ ignore = E501 W503 B006 DUO130 E800 R501 R502per-file-ignores =spiderfoot/__init__.py:F401sfcli.py:D- sflib.py:D- sfscan.py:D- sfwebui.py:Dmodules/*:R[darglint]diff --git a/sflib.py b/sflib.pyindex 3b6aca52..fd36167b 100644--- a/sflib.py+++ b/sflib.py@@ -69,6 +69,9 @@ class SpiderFoot:Args:options (dict): dictionary of configuration options.++ Raises:+ TypeError: options argument was invalid type"""if not isinstance(options, dict):raise TypeError("options is %s; expected dict()" % type(options))@@ -116,12 +119,19 @@ class SpiderFoot:"""Called usually some time after instantiationto set up a database handle and scan ID, usedfor logging events to the database about a scan.++ Args:+ dbh (SpiderFootDB): database handle"""self._dbh = dbh@scanId.setterdef scanId(self, scanId):- """Set the scan ID this instance of SpiderFoot is being used in."""+ """Set the scan ID this instance of SpiderFoot is being used in.++ Args:+ scanId: scan instance ID+ """self._scanId = scanId@socksProxy.setter@@ -131,6 +141,9 @@ class SpiderFoot:Bit of a hack to support SOCKS because of the loading order ofmodules. sfscan will call this to update the socket referenceto the SOCKS one.++ Args:+ socksProxy (str): SOCKS proxy"""self._socksProxy = socksProxy@@ -138,7 +151,7 @@ class SpiderFoot:"""Tell TOR to re-circuit.Returns:- None+ None: success"""if self.opts['_socks1type'] != "TOR":@@ -163,11 +176,10 @@ class SpiderFoot:and if a string it will simply be returned back.Args:- val (str): TBD- fatal (bool): TBD+ val (str): option nameReturns:- str: TBD+ str: option data"""if not isinstance(val, str):@@ -203,7 +215,7 @@ class SpiderFoot:basis for building graphs in various formats.Args:- root (str): TBD+ data (str): TBDflt (list): TBDReturns:@@ -401,6 +413,9 @@ class SpiderFoot:Returns:bool: scan event logged successfully++ Raises:+ BaseException: internal error encountered attempting to access the database handler"""if not self.dbh:@@ -433,9 +448,6 @@ class SpiderFoot:Args:error (str): error message-- Returns:- None"""if self.dbh:@@ -644,6 +656,9 @@ class SpiderFoot:Returns:dict: config options++ Raises:+ TypeError: arg type was invalid"""if not isinstance(opts, dict):@@ -710,6 +725,9 @@ class SpiderFoot:Returns:dict: TBD++ Raises:+ TypeError: arg type was invalid"""if not isinstance(opts, dict):@@ -724,26 +742,29 @@ class SpiderFoot:if opt.startswith('__') and filterSystem:# Leave out system variablescontinue- if opt in opts:- if isinstance(referencePoint[opt], bool):- if opts[opt] == "1":- returnOpts[opt] = True- else:- returnOpts[opt] = False- if isinstance(referencePoint[opt], str):- returnOpts[opt] = str(opts[opt])+ if opt not in opts:+ continue++ if isinstance(referencePoint[opt], bool):+ if opts[opt] == "1":+ returnOpts[opt] = True+ else:+ returnOpts[opt] = False++ if isinstance(referencePoint[opt], str):+ returnOpts[opt] = str(opts[opt])- if isinstance(referencePoint[opt], int):- returnOpts[opt] = int(opts[opt])+ if isinstance(referencePoint[opt], int):+ returnOpts[opt] = int(opts[opt])- if isinstance(referencePoint[opt], list):- if isinstance(referencePoint[opt][0], int):- returnOpts[opt] = list()- for x in str(opts[opt]).split(","):- returnOpts[opt].append(int(x))- else:- returnOpts[opt] = str(opts[opt]).split(",")+ if isinstance(referencePoint[opt], list):+ if isinstance(referencePoint[opt][0], int):+ returnOpts[opt] = list()+ for x in str(opts[opt]).split(","):+ returnOpts[opt].append(int(x))+ else:+ returnOpts[opt] = str(opts[opt]).split(",")if '__modules__' not in referencePoint:return returnOpts@@ -1528,7 +1549,15 @@ class SpiderFoot:return list(set(addrs))def validateIP(self, host, ip):- """Verify a host resolves to a given IP."""+ """Verify a host resolves to a given IP.++ Args:+ host (str): host+ ip (str): IP address++ Returns:+ bool: host resolves to the given IP address+ """addrs = self.resolveHost(host)@@ -1590,13 +1619,31 @@ class SpiderFoot:return list(set(ret))def safeSocket(self, host, port, timeout):- """Create a safe socket that's using SOCKS/TOR if it was enabled."""+ """Create a safe socket that's using SOCKS/TOR if it was enabled.++ Args:+ host (str): host+ port (str): port+ timeout (int): timeout++ Returns:+ sock+ """sock = socket.create_connection((host, int(port)), int(timeout))sock.settimeout(int(timeout))return sockdef safeSSLSocket(self, host, port, timeout):- """Create a safe SSL connection that's using SOCKs/TOR if it was enabled."""+ """Create a safe SSL connection that's using SOCKs/TOR if it was enabled.++ Args:+ host (str): host+ port (str): port+ timeout (int): timeout++ Returns:+ sock+ """s = socket.socket()s.settimeout(int(timeout))s.connect((host, int(port)))@@ -2148,6 +2195,9 @@ class SpiderFoot:Returns:str: PEM-encoded certificate as a byte string++ Raises:+ TypeError: arg type was invalid"""if not isinstance(der_cert, bytes):@@ -2293,6 +2343,9 @@ class SpiderFoot:url (str): TBDdata (str): data to examine for linksdomains: TBD++ Returns:+ list: links"""returnLinks = dict()@@ -2407,7 +2460,14 @@ class SpiderFoot:return sessiondef removeUrlCreds(self, url):- """Remove key= and others from URLs to avoid credentials in logs."""+ """Remove key= and others from URLs to avoid credentials in logs.++ Args:+ url (str): URL++ Returns:+ str: URL+ """pats = {r'key=\S+': "key=XXX",@@ -2469,11 +2529,43 @@ class SpiderFoot:return True- def fetchUrl(self, url, fatal=False, cookies=None, timeout=30,- useragent="SpiderFoot", headers=None, noLog=False,- postData=None, dontMangle=False, sizeLimit=None,- headOnly=False, verify=True):- """Fetch a URL, return the response object."""+ def fetchUrl(+ self,+ url,+ fatal=False,+ cookies=None,+ timeout=30,+ useragent="SpiderFoot",+ headers=None,+ noLog=False,+ postData=None,+ dontMangle=False,+ sizeLimit=None,+ headOnly=False,+ verify=True+ ):+ """Fetch a URL, return the response object.++ Args:+ url (str): URL to fetch+ fatal (bool): raise an exception upon request error+ cookies (str): cookies+ timeout (int): timeout+ useragent (str): user agent header+ headers (str): headers+ noLog (bool): do not log+ postData (str): HTTP POST data+ dontMangle (bool): do not mangle+ sizeLimit (int): size threshold+ headOnly (bool): use HTTP HEAD method+ verify (bool): use HTTPS SSL/TLS verification++ Returns:+ dict: HTTP response++ Raises:+ Exception: request error+ """if not url:return None@@ -2658,6 +2750,9 @@ class SpiderFoot:Args:target (str): TBD++ Returns:+ bool: wildcard DNS"""if not target:@@ -2687,6 +2782,9 @@ class SpiderFoot:Args:searchString (str) :TBDopts (dict): TBD++ Returns:+ dict: TBD"""endpoint = "https://www.googleapis.com/customsearch/v1?q={search_string}&".format(@@ -2751,6 +2849,8 @@ class SpiderFoot:searchString (str): TBDopts (dict): TBD+ Returns:+ dict: TBD"""endpoint = "https://api.cognitive.microsoft.com/bing/v7.0/search?q={search_string}&".format(diff --git a/sfwebui.py b/sfwebui.pyindex 6178b0da..24cd313a 100644--- a/sfwebui.py+++ b/sfwebui.py@@ -47,6 +47,10 @@ class SpiderFootWebUi:Args:web_config: config settings for web interface (interface, port, root path)config: SpiderFoot config++ Raises:+ TypeError: arg type is invalid+ ValueError: arg value is invalid"""if not isinstance(config, dict):@@ -102,6 +106,9 @@ class SpiderFootWebUi:message: TBDtraceback: TBDversion: TBD++ Returns:+ str: HTTP response template"""templ = Template(filename='dyn/error.tmpl', lookup=self.lookup)@@ -364,6 +371,9 @@ class SpiderFootWebUi:Args:id: scan ID++ Returns:+ str: options as JSON string"""ret = dict()@@ -406,6 +416,12 @@ class SpiderFootWebUi:Args:id (str): scan ID++ Returns:+ None++ Raises:+ HTTPRedirect: redirect to info page for new scan"""# Snapshot the current configuration to be used by the scan@@ -463,6 +479,9 @@ class SpiderFootWebUi:Args:ids (str): comma separated list of scan IDs++ Returns:+ None"""# Snapshot the current configuration to be used by the scan@@ -511,8 +530,10 @@ class SpiderFootWebUi:rerunscanmulti.exposed = Truedef newscan(self):- """- Configure a new scan+ """Configure a new scan++ Returns:+ None"""dbh = SpiderFootDb(self.config)@@ -530,6 +551,9 @@ class SpiderFootWebUi:Args:id (str): scan ID to clone++ Returns:+ None"""sf = SpiderFoot(self.config)@@ -564,8 +588,10 @@ class SpiderFootWebUi:clonescan.exposed = Truedef index(self):- """- Main page listing scans available+ """Main page listing scans available++ Returns:+ None"""templ = Template(filename='dyn/scanlist.tmpl', lookup=self.lookup)@@ -578,7 +604,11 @@ class SpiderFootWebUi:Args:id (str): scan id++ Returns:+ None"""+dbh = SpiderFootDb(self.config)res = dbh.scanInstanceGet(id)if res is None:@@ -595,6 +625,9 @@ class SpiderFootWebUi:Args:updated: TBD++ Returns:+ None"""templ = Template(filename='dyn/opts.tmpl', lookup=self.lookup)@@ -609,6 +642,9 @@ class SpiderFootWebUi:Args:pattern: TBD++ Returns:+ None"""sf = SpiderFoot(self.config)@@ -632,7 +668,11 @@ class SpiderFootWebUi:optsexport.exposed = Truedef optsraw(self):- """Settings"""+ """Settings++ Returns:+ str: settings as JSON+ """cherrypy.response.headers['Content-Type'] = "application/json; charset=utf-8"@@ -659,6 +699,9 @@ class SpiderFootWebUi:Args:message (str): error message++ Returns:+ None"""templ = Template(filename='dyn/error.tmpl', lookup=self.lookup)@@ -670,6 +713,12 @@ class SpiderFootWebUi:Args:id (str): scan IDconfirm (str): specify any value (except None) to confirm deletion of the scan++ Returns:+ None++ Raises:+ HTTPRedirect: redirect to scan list page"""dbh = SpiderFootDb(self.config)@@ -704,6 +753,12 @@ class SpiderFootWebUi:Args:ids (str): comma separated list of scan IDsconfirm: TBD++ Returns:+ None++ Raises:+ HTTPRedirect: redirect to scan list page"""dbh = SpiderFootDb(self.config)@@ -734,8 +789,14 @@ class SpiderFootWebUi:Args:allopts: TBD- token: TBD+ token: CSRF tokenconfigFile: TBD++ Returns:+ None++ Raises:+ HTTPRedirect: redirect to scan settings"""if str(token) != str(self.token):@@ -798,7 +859,10 @@ class SpiderFootWebUi:Args:allopts: TBD- token: TBD+ token: CSRF token++ Returns:+ str: save success as JSON"""cherrypy.response.headers['Content-Type'] = "application/json; charset=utf-8"@@ -836,7 +900,11 @@ class SpiderFootWebUi:savesettingsraw.exposed = Truedef reset_settings(self):- """Reset settings to default"""+ """Reset settings to default.++ Returns:+ bool: success+ """try:dbh = SpiderFootDb(self.config)@@ -854,6 +922,9 @@ class SpiderFootWebUi:id (str): scan IDresultids (str): comma separated list of result IDsfp (str): 0 or 1++ Returns:+ str: set false positive status as JSON"""cherrypy.response.headers['Content-Type'] = "application/json; charset=utf-8"@@ -942,7 +1013,11 @@ class SpiderFootWebUi:modules.exposed = Truedef ping(self):- """For the CLI to test connectivity to this server."""+ """For the CLI to test connectivity to this server.++ Returns:+ str: SpiderFoot version as JSON+ """cherrypy.response.headers['Content-Type'] = "application/json; charset=utf-8"@@ -951,7 +1026,14 @@ class SpiderFootWebUi:ping.exposed = Truedef query(self, query):- """For the CLI to run queries against the database."""+ """For the CLI to run queries against the database.++ Args:+ query (str): SQL query++ Returns:+ str: query results as JSON+ """cherrypy.response.headers['Content-Type'] = "application/json; charset=utf-8"@@ -984,7 +1066,13 @@ class SpiderFootWebUi:scantarget (str): scan targetmodulelist (str): TBDtypelist (str): TBD- usecase (str): TBD+ usecase (str): module group (passive, investigate, footprint, all)++ Returns:+ str: start scan status as JSON++ Raises:+ HTTPRedirect: redirect to new scan info page"""# Swap the globalscantable for the database handler@@ -1096,6 +1184,12 @@ class SpiderFootWebUi:Note:Unnecessary for now given that only one simultaneous scan is permitted++ Returns:+ str: stop scan status as JSON++ Raises:+ HTTPRedirect: redirect to home page"""dbh = SpiderFootDb(self.config)@@ -1129,6 +1223,12 @@ class SpiderFootWebUi:Args:id (str): scan ID++ Returns:+ str: stop scan status as JSON++ Raises:+ HTTPRedirect: redirect to home page"""dbh = SpiderFootDb(self.config)@@ -1179,6 +1279,9 @@ class SpiderFootWebUi:limit: TBDrowId: TBDreverse: TBD++ Returns:+ str: JSON"""cherrypy.response.headers['Content-Type'] = "application/json; charset=utf-8"@@ -1205,6 +1308,9 @@ class SpiderFootWebUi:Args:id (str): scan IDlimit: TBD++ Returns:+ str: scan errors as JSON"""cherrypy.response.headers['Content-Type'] = "application/json; charset=utf-8"@@ -1226,7 +1332,11 @@ class SpiderFootWebUi:scanerrors.exposed = Truedef scanlist(self):- """Produce a list of scans"""+ """Produce a list of scans.++ Returns:+ str: scan list as JSON+ """cherrypy.response.headers['Content-Type'] = "application/json; charset=utf-8"@@ -1257,6 +1367,9 @@ class SpiderFootWebUi:Args:id (str): scan ID++ Returns:+ str: scan status as JSON"""cherrypy.response.headers['Content-Type'] = "application/json; charset=utf-8"@@ -1282,6 +1395,9 @@ class SpiderFootWebUi:Args:id (str): scan IDby: TBD++ Returns:+ scan summary as JSON"""cherrypy.response.headers['Content-Type'] = "application/json; charset=utf-8"@@ -1316,6 +1432,9 @@ class SpiderFootWebUi:id (str): scan IDeventType (str): filter by event typefilterfp: TBD++ Returns:+ str: scan results as JSON"""cherrypy.response.headers['Content-Type'] = "application/json; charset=utf-8"@@ -1347,6 +1466,9 @@ class SpiderFootWebUi:id (str): scan IDeventType (str): filter by event typefilterfp: TBD++ Returns:+ str: unique results as JSON"""cherrypy.response.headers['Content-Type'] = "application/json; charset=utf-8"@@ -1373,6 +1495,9 @@ class SpiderFootWebUi:id: TBDeventType (str): filter by event typevalue: TBD++ Returns:+ str: search results as JSON"""cherrypy.response.headers['Content-Type'] = "application/json; charset=utf-8"@@ -1391,6 +1516,9 @@ class SpiderFootWebUi:Args:id (str): scan ID++ Returns:+ str: scan history as JSON"""cherrypy.response.headers['Content-Type'] = "application/json; charset=utf-8"@@ -1412,6 +1540,9 @@ class SpiderFootWebUi:Args:id: TBDeventType (str): filter by event type++ Returns:+ str: JSON"""cherrypy.response.headers['Content-Type'] = "application/json; charset=utf-8"