Skip to content

Commit

Permalink
fix?
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Dec 19, 2024
1 parent dc25be3 commit bfa0def
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 23 deletions.
8 changes: 1 addition & 7 deletions bbot/core/helpers/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,13 +559,12 @@ def is_port(p):
return p and p.isdigit() and 0 <= int(p) <= 65535


def is_dns_name(d, include_local=True):
def is_dns_name(d):
"""
Determines if the given string is a valid DNS name.
Args:
d (str): The string to be checked.
include_local (bool): Consider local hostnames to be valid (hostnames without periods)
Returns:
bool: True if the string is a valid DNS name, False otherwise.
Expand All @@ -575,17 +574,12 @@ def is_dns_name(d, include_local=True):
True
>>> is_dns_name('localhost')
True
>>> is_dns_name('localhost', include_local=False)
False
>>> is_dns_name('192.168.1.1')
False
"""
if is_ip(d):
return False
d = smart_decode(d)
if include_local:
if bbot_regexes.hostname_regex.match(d):
return True
if bbot_regexes.dns_name_validation_regex.match(d):
return True
return False
Expand Down
11 changes: 1 addition & 10 deletions bbot/core/helpers/regexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@
dns_name_extraction_regex = re.compile(_dns_name_regex, re.I)
dns_name_validation_regex = re.compile(r"^" + _dns_name_regex + r"$", re.I)

# dns names without periods
_hostname_regex = r"(?!\w*\.\w+)\w(?:[\w-]{0,100}\w)?"
hostname_regex = re.compile(r"^" + _hostname_regex + r"$", re.I)

_email_regex = r"(?:[^\W_][\w\-\.\+']{,100})@" + _dns_name_regex
email_regex = re.compile(_email_regex, re.I)

Expand All @@ -61,14 +57,12 @@

_open_port_regexes = (
_dns_name_regex + r":[0-9]{1,5}",
_hostname_regex + r":[0-9]{1,5}",
r"\[" + _ipv6_regex + r"\]:[0-9]{1,5}",
)
open_port_regexes = [re.compile(r, re.I) for r in _open_port_regexes]

_url_regexes = (
r"https?://" + _dns_name_regex + r"(?::[0-9]{1,5})?(?:(?:/|\?).*)?",
r"https?://" + _hostname_regex + r"(?::[0-9]{1,5})?(?:(?:/|\?).*)?",
r"https?://\[" + _ipv6_regex + r"\](?::[0-9]{1,5})?(?:(?:/|\?).*)?",
)
url_regexes = [re.compile(r, re.I) for r in _url_regexes]
Expand All @@ -83,10 +77,7 @@
for k, regexes in (
(
"DNS_NAME",
(
r"^" + _dns_name_regex + r"$",
r"^" + _hostname_regex + r"$",
),
(r"^" + _dns_name_regex + r"$",),
),
(
"EMAIL_ADDRESS",
Expand Down
6 changes: 1 addition & 5 deletions bbot/modules/github_org.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,7 @@ async def validate_org(self, org):
for k, v in json.items():
if (
isinstance(v, str)
and (
self.helpers.is_dns_name(v, include_local=False)
or self.helpers.is_url(v)
or self.helpers.is_email(v)
)
and (self.helpers.is_dns_name(v) and "." in v or self.helpers.is_url(v) or self.helpers.is_email(v))
and self.scan.in_scope(v)
):
self.verbose(f'Found in-scope key "{k}": "{v}" for {org}, it appears to be in-scope')
Expand Down
2 changes: 1 addition & 1 deletion bbot/test/test_step_1/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ async def test_helpers_misc(helpers, scan, bbot_scanner, bbot_httpserver):
assert not helpers.is_dns_name("evilcorp.com:80")
assert not helpers.is_dns_name("http://evilcorp.com:80")
assert helpers.is_dns_name("evilcorp")
assert not helpers.is_dns_name("evilcorp", include_local=False)
assert helpers.is_dns_name("evilcorp.")
assert helpers.is_dns_name("ドメイン.テスト")
assert not helpers.is_dns_name("127.0.0.1")
assert not helpers.is_dns_name("dead::beef")
Expand Down

0 comments on commit bfa0def

Please sign in to comment.