Skip to content

Commit

Permalink
Only check domain if uri doesn't contain an IP
Browse files Browse the repository at this point in the history
  • Loading branch information
cccs-kevin committed Sep 14, 2021
1 parent 180c28f commit cea3128
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
20 changes: 11 additions & 9 deletions jsjaws.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,15 +505,17 @@ def _extract_iocs_from_text_blob(self, blob: str, result_section: ResultSection,
ioc_extracted = True
result_section.add_tag("network.dynamic.domain", safe_domain)
for uri in uris:
try:
if not any(protocol in uri for protocol in ["http", "ftp", "icmp", "ssh"]):
tld = get_tld(f"http://{uri}", fail_silently=True)
else:
tld = get_tld(uri, fail_silently=True)
except ValueError:
continue
if tld is None or f".{tld}" == file_ext:
continue
# If there is a domain in the uri, then do
if not any(ip in uri for ip in ips):
try:
if not any(protocol in uri for protocol in ["http", "ftp", "icmp", "ssh"]):
tld = get_tld(f"http://{uri}", fail_silently=True)
else:
tld = get_tld(uri, fail_silently=True)
except ValueError:
continue
if tld is None or f".{tld}" == file_ext:
continue
safe_uri = safe_str(uri)
ioc_extracted = True
result_section.add_tag("network.dynamic.uri", safe_uri)
Expand Down
1 change: 1 addition & 0 deletions test/test_jsjaws.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ def test_extract_supplementary(jsjaws_class_instance):
("evil.ca/some/thing/bad.exe", "", {"network.dynamic.domain": ["evil.ca"], "network.dynamic.uri": ["evil.ca/some/thing/bad.exe"], "network.dynamic.uri_path": ["/some/thing/bad.exe"]}),
("wscript.shell", "", {}),
("blah.ca", ".ca", {}),
("http://1.1.1.1/blah.exe", "", {'network.dynamic.ip': ['1.1.1.1'], 'network.dynamic.uri': ['http://1.1.1.1/blah.exe'], 'network.dynamic.uri_path': ['/blah.exe']}),
]
)
def test_extract_iocs_from_text_blob(blob, file_ext, correct_tags, jsjaws_class_instance):
Expand Down

0 comments on commit cea3128

Please sign in to comment.