SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.
Python attacksurfacecticybersecurityfootprintinghackinginformation-gatheringinformation-securityinfosecintelligence-gatheringosintosint-frameworkosint-reconnaissanceosint-toolpentestingpythonreconsecurity-toolsthreat-intelligencethreatintel
Use urllib for encoding URL query string params
Brendan Coles64dfe9f1a1c0
diff --git a/modules/sfp_hunter.py b/modules/sfp_hunter.pyindex 24350019..9ff27486 100644--- a/modules/sfp_hunter.py+++ b/modules/sfp_hunter.py@@ -10,6 +10,7 @@#-------------------------------------------------------------------------------import json+import urllib.request, urllib.parse, urllib.errorfrom sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEventclass sfp_hunter(SpiderFootPlugin):@@ -51,11 +52,17 @@ class sfp_hunter(SpiderFootPlugin):def producedEvents(self):return [ "EMAILADDR", "EMAILADDR_GENERIC", "RAW_RIR_DATA" ]- def query(self, t, offset=0, limit=10):+ def query(self, qry, offset=0, limit=10):+ params = {+ "domain": qry.encode('raw_unicode_escape').decode("ascii", errors='replace'),+ "api_key": self.opts['api_key'],+ "offset": str(offset),+ "limit": str(limit)+ }+ret = None- url = "https://api.hunter.io/v2/domain-search?domain=" + t + "&api_key=" + self.opts['api_key'] + \- "&offset=" + str(offset) + "&limit=" + str(limit)+ url = "https://api.hunter.io/v2/domain-search?%s" % urllib.parse.urlencode(params)res = self.sf.fetchUrl(url, timeout=self.opts['_fetchtimeout'],useragent="SpiderFoot")@@ -69,7 +76,7 @@ class sfp_hunter(SpiderFootPlugin):try:ret = json.loads(res['content'])except Exception as e:- self.sf.error("Error processing JSON response from hunter.io: " + str(e), False)+ self.sf.error("Error processing JSON response from hunter.io: %s" % e, False)return Nonereturn retdiff --git a/modules/sfp_wikipediaedits.py b/modules/sfp_wikipediaedits.pyindex d64c2670..e48ad016 100644--- a/modules/sfp_wikipediaedits.py+++ b/modules/sfp_wikipediaedits.py@@ -1,7 +1,7 @@#--------------------------------------------------------------------------------# Name: sfp_wikipediaedits-# Purpose: Identify edits to Wikipedia articles made from a given IP address-# or username.+# Name: sfp_wikipediaedits+# Purpose: Identify edits to Wikipedia articles made from a given IP address+# owned netblock or username.## Author: Steve Micallef <[email protected]>#@@ -12,13 +12,13 @@import datetimeimport re+import urllib.request, urllib.parse, urllib.errorfrom html.parser import HTMLParserfrom sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEventclass sfp_wikipediaedits(SpiderFootPlugin):"""Wikipedia Edits:Footprint,Investigate,Passive:Secondary Networks::Identify edits to Wikipedia articles made from a given IP address or username."""-# Default optionsopts = {"days_limit": "365"@@ -47,29 +47,39 @@ class sfp_wikipediaedits(SpiderFootPlugin):# What events is this module interested in for inputdef watchedEvents(self):- return ["IP_ADDRESS", "USERNAME"]+ return ["IP_ADDRESS", "USERNAME", "NETBLOCK_OWNER"]# What events this module producesdef producedEvents(self):return ["WIKIPEDIA_PAGE_EDIT"]def query(self, qry):- url = "https://en.wikipedia.org/w/api.php?action=feedcontributions&user=" + qry+ params = {+ "action": "feedcontributions",+ "user": qry.encode('raw_unicode_escape').decode("ascii", errors='replace')+ }+if self.opts['days_limit'] != "0":dt = datetime.datetime.now() - datetime.timedelta(days=int(self.opts['days_limit']))- y = dt.strftime("%Y")- m = dt.strftime("%m")- url += "&year=" + y + "&month=" + m- res = self.sf.fetchUrl(url, timeout=self.opts['_fetchtimeout'],- useragent="SpiderFoot")- if res['code'] in [ "404", "403", "500" ]:+ params["year"] = dt.strftime("%Y")+ params["month"] = dt.strftime("%m")++ res = self.sf.fetchUrl(+ "https://en.wikipedia.org/w/api.php?%s" % urllib.parse.urlencode(params),+ timeout=self.opts['_fetchtimeout'],+ useragent="SpiderFoot"+ )++ if res['code'] in ["404", "403", "500"]:+ return None++ if not res['content']:return Nonelinks = list()+try:parser = HTMLParser()- if not res['content']:- return Nonefor line in res['content'].split("\n"):matches = re.findall("<link>(.*?)</link>", line, re.IGNORECASE)@@ -78,9 +88,9 @@ class sfp_wikipediaedits(SpiderFootPlugin):continued = parser.unescape(m)links.append(d)- return links- except Exception as e:- self.sf.error("Error processing response from Wikipedia: " + str(e), False)+ return set(links)+ except BaseException as e:+ self.sf.error("Error processing response from Wikipedia: %s" % e, False)return None# Handle events sent to this module@@ -95,16 +105,16 @@ class sfp_wikipediaedits(SpiderFootPlugin):if eventData in self.results:self.sf.debug("Skipping " + eventData + " as already mapped.")return None- else:- self.results[eventData] = True++ self.results[eventData] = Truedata = self.query(eventData)- if data == None:++ if data is None:return None- for l in data:- e = SpiderFootEvent("WIKIPEDIA_PAGE_EDIT", l,- self.__name__, event)- self.notifyListeners(e)+ for link in data:+ evt = SpiderFootEvent("WIKIPEDIA_PAGE_EDIT", link, self.__name__, event)+ self.notifyListeners(evt)# End of sfp_wikipediaedits class