SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.
Python attacksurfacecticybersecurityfootprintinghackinginformation-gatheringinformation-securityinfosecintelligence-gatheringosintosint-frameworkosint-reconnaissanceosint-toolpentestingpythonreconsecurity-toolsthreat-intelligencethreatintel
sfp_cookie: Cleanup (#1335)
bcoles30e2b0381aad
diff --git a/modules/sfp_cookie.py b/modules/sfp_cookie.pyindex 1c4bde38..66ff3a7f 100644--- a/modules/sfp_cookie.py+++ b/modules/sfp_cookie.py@@ -25,7 +25,6 @@ class sfp_cookie(SpiderFootPlugin):'categories': ["Content Analysis"]}- # Default optionsopts = {}optdescs = {}@@ -44,8 +43,6 @@ class sfp_cookie(SpiderFootPlugin):return ["WEBSERVER_HTTPHEADERS"]# What events this module produces- # This is to support the end user in selecting modules based on events- # produced.def producedEvents(self):return ["TARGET_WEB_COOKIE"]@@ -57,26 +54,26 @@ class sfp_cookie(SpiderFootPlugin):eventSource = event.actualSourceself.sf.debug(f"Received event, {eventName}, from {srcModuleName}")+if eventSource in self.results:return- else:- self.results[eventSource] = True- if not self.getTarget().matches(self.sf.urlFQDN(eventSource)):- self.sf.debug("Not collecting cookies from external sites.")+ self.results[eventSource] = True++ fqdn = self.sf.urlFQDN(eventSource)+ if not self.getTarget().matches(fqdn):+ self.sf.debug(f"Not collecting cookies from external sites. Ignoring HTTP headers from {fqdn}")returntry:- jdata = json.loads(eventData)- if jdata is None:- return+ data = json.loads(eventData)except Exception:self.sf.error("Received HTTP headers from another module in an unexpected format.")return- if 'set-cookie' in jdata:- evt = SpiderFootEvent("TARGET_WEB_COOKIE", jdata['set-cookie'],- self.__name__, event)+ cookie = data.get('cookie')+ if cookie:+ evt = SpiderFootEvent("TARGET_WEB_COOKIE", cookie, self.__name__, event)self.notifyListeners(evt)# End of sfp_cookie classdiff --git a/test/unit/modules/test_sfp_cookie.py b/test/unit/modules/test_sfp_cookie.pyindex 88d597cc..0a389467 100644--- a/test/unit/modules/test_sfp_cookie.py+++ b/test/unit/modules/test_sfp_cookie.py@@ -34,26 +34,77 @@ class TestModuleCookie(unittest.TestCase):module = sfp_cookie()self.assertIsInstance(module.producedEvents(), list)- def test_handleEvent(self):- """- Test handleEvent(self, event)- """+ def test_handleEvent_event_data_containing_cookie_should_return_event(self):+ sf = SpiderFoot(self.default_options)++ module = sfp_cookie()+ module.setup(sf, dict())++ target_value = 'spiderfoot.net'+ target_type = 'INTERNET_NAME'+ target = SpiderFootTarget(target_value, target_type)+ module.setTarget(target)++ def new_notifyListeners(self, event):+ expected = 'TARGET_WEB_COOKIE'+ if str(event.eventType) != expected:+ raise Exception(f"{event.eventType} != {expected}")++ expected = 'example cookie'+ if str(event.data) != expected:+ raise Exception(f"{event.data} != {expected}")++ raise Exception("OK")++ module.notifyListeners = new_notifyListeners.__get__(module, sfp_cookie)++ event_type = 'ROOT'+ event_data = 'example data'+ event_module = ''+ source_event = ''+ evt = SpiderFootEvent(event_type, event_data, event_module, source_event)++ event_type = 'WEBSERVER_HTTPHEADERS'+ event_data = '{"cookie": "example cookie"}'+ event_module = 'sfp_spider'+ source_event = evt+ evt = SpiderFootEvent(event_type, event_data, event_module, source_event)+ evt.actualSource = "https://spiderfoot.net/example"++ with self.assertRaises(Exception) as cm:+ module.handleEvent(evt)++ self.assertEqual("OK", str(cm.exception))++ def test_handleEvent_event_data_not_containing_cookie_should_not_return_event(self):sf = SpiderFoot(self.default_options)module = sfp_cookie()module.setup(sf, dict())- target_value = 'example target value'- target_type = 'IP_ADDRESS'+ target_value = 'spiderfoot.net'+ target_type = 'INTERNET_NAME'target = SpiderFootTarget(target_value, target_type)module.setTarget(target)+ def new_notifyListeners(self, event):+ raise Exception(f"Raised event {event.eventType}: {event.data}")++ module.notifyListeners = new_notifyListeners.__get__(module, sfp_cookie)+event_type = 'ROOT'event_data = 'example data'event_module = ''source_event = ''evt = SpiderFootEvent(event_type, event_data, event_module, source_event)+ event_type = 'WEBSERVER_HTTPHEADERS'+ event_data = '{"not cookie": "example cookie"}'+ event_module = 'sfp_spider'+ source_event = evt+ evt = SpiderFootEvent(event_type, event_data, event_module, source_event)+ evt.actualSource = "https://spiderfoot.net/example"+result = module.handleEvent(evt)self.assertIsNone(result)