diff --git a/shadycompass/facts/__init__.py b/shadycompass/facts/__init__.py index 83574eb..5a671e3 100644 --- a/shadycompass/facts/__init__.py +++ b/shadycompass/facts/__init__.py @@ -54,11 +54,17 @@ def check_file_signature(file_path: str, *signatures) -> bool: elif isinstance(sig, dict): # jsonl lines = content.split('\n') + while len(lines) > 0 and len(lines[-1]) == 0: + lines.pop(-1) if len(lines) == 0: return False try: # ignore the last line, it's likely cut off - for line in lines[0:-1]: + if len(content) > 4000: + lines_to_check = lines[0:-1] + else: + lines_to_check = lines + for line in lines_to_check: jsonschema.validate(instance=json.loads(line), schema=sig) except (ValueError, jsonschema.exceptions.ValidationError): return False @@ -1110,10 +1116,10 @@ def parse_cpe(value: str) -> Union[Fact, None]: assert cpe_parts.pop(0) == 'cpe' cpe_type = cpe_parts.pop(0) # [/a,/o,/h] or float version try: - cpe_version = float(cpe_type) + float(cpe_type) # check if version is a valid float cpe_type = cpe_parts.pop(0) except ValueError: - cpe_version = 1.0 + pass kwargs['vendor'] = cpe_parts.pop(0) kwargs['product'] = cpe_parts.pop(0) diff --git a/tests/facts/http_spider/test_facts_gospider.py b/tests/facts/http_spider/test_facts_gospider.py index 7007795..ebaa0e7 100644 --- a/tests/facts/http_spider/test_facts_gospider.py +++ b/tests/facts/http_spider/test_facts_gospider.py @@ -29,3 +29,7 @@ def test_facts(self): assertFactIn(VirtualHostname(hostname='ir.shadycompass.test'), facts) assertFactIn(VirtualHostname(hostname='footer-ir.shadycompass.test'), facts) assertFactIn(VirtualHostname(hostname='footer-store.shadycompass.test'), facts) + + def test_facts_not_gospider_output(self): + facts = self.reader.read_facts('tests/fixtures/shadycompass.ini') + self.assertEqual(0, len(facts)) diff --git a/tests/facts/http_spider/test_facts_katana.py b/tests/facts/http_spider/test_facts_katana.py index 5a1f57d..ddf2c3c 100644 --- a/tests/facts/http_spider/test_facts_katana.py +++ b/tests/facts/http_spider/test_facts_katana.py @@ -40,3 +40,7 @@ def test_facts_passive(self): assertFactIn(VirtualHostname(hostname='www.vpn.shadycompass.test', port=443, secure=True), facts) assertFactIn(VirtualHostname(hostname='click.e.shadycompass.test', port=443, secure=True), facts) assertFactIn(VirtualHostname(hostname='techinfo.shadycompass.test', port=443, secure=True), facts) + + def test_facts_not_katana_output(self): + facts = self.reader.read_facts('tests/fixtures/shadycompass.ini') + self.assertEqual(0, len(facts))