Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add custom uri on body checks #172

Merged
merged 2 commits into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 39 additions & 37 deletions signatures/checks/WEB.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
from domain import Domain
from math import floor
import logging


def string_in_body(domain: Domain, string: str, https: bool) -> bool:
if string in domain.fetch_web(https=https).body:
logging.info(f"Message observed in response for '{domain}'")
return True
logging.debug(f"Message not found in response for '{domain}'")
return False


def string_in_body_http(domain: Domain, string: str) -> bool:
return string_in_body(domain, string, False)


def string_in_body_https(domain: Domain, string: str) -> bool:
return string_in_body(domain, string, True)


def status_code_match(domain: Domain, status_code: int, https: bool) -> bool:
response_code = domain.fetch_web(https=https).status_code
if status_code < 10: # match the first int
if floor(response_code / 100) == status_code:
logging.info(f"Response code {response_code} observed for '{domain}'")
return True
else:
if response_code == status_code:
logging.info(f"Response code {response_code} observed for '{domain}'")
return True
logging.debug(f"Response code {response_code} observed for '{domain}'")
return False


def status_code_404(domain: Domain, https: bool) -> bool:
return status_code_match(domain, 404, https)
from domain import Domain
from math import floor
import logging


def string_in_body(
domain: Domain, string: str, https: bool, custom_uri: str = ""
) -> bool:
if string in domain.fetch_web(https=https, uri=custom_uri).body:
logging.info(f"Message observed in response for '{domain}'")
return True
logging.debug(f"Message not found in response for '{domain}'")
return False


def string_in_body_http(domain: Domain, string: str, custom_uri: str = "") -> bool:
return string_in_body(domain, string, False, custom_uri)


def string_in_body_https(domain: Domain, string: str, custom_uri: str = "") -> bool:
return string_in_body(domain, string, True, custom_uri)


def status_code_match(domain: Domain, status_code: int, https: bool) -> bool:
response_code = domain.fetch_web(https=https).status_code
if status_code < 10: # match the first int
if floor(response_code / 100) == status_code:
logging.info(f"Response code {response_code} observed for '{domain}'")
return True
else:
if response_code == status_code:
logging.info(f"Response code {response_code} observed for '{domain}'")
return True
logging.debug(f"Response code {response_code} observed for '{domain}'")
return False


def status_code_404(domain: Domain, https: bool) -> bool:
return status_code_match(domain, 404, https)
16 changes: 9 additions & 7 deletions signatures/teamwork.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from .templates.cname_found_but_string_in_body import cname_found_but_string_in_body

test = cname_found_but_string_in_body(
cname=".teamwork.com",
domain_not_configured_message="""<title>Teamwork Projects</title>""",
service="teamwork",
)
from .templates.cname_found_but_string_in_body import cname_found_but_string_in_body

test = cname_found_but_string_in_body(
cname=".teamwork.com",
domain_not_configured_message="""Unable to determine installationID from domain""",
service="teamwork",
custom_uri="launchpad/v1/info.json",
https=True,
)
6 changes: 4 additions & 2 deletions signatures/templates/cname_found_but_string_in_body.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ def potential(self, domain, **kwargs) -> bool:
def check(self, domain, **kwargs) -> bool:
if self.https:
return signatures.checks.WEB.string_in_body_https(
domain, self.domain_not_configured_message
domain, self.domain_not_configured_message, custom_uri=self.custom_uri
)
return signatures.checks.WEB.string_in_body_http(
domain, self.domain_not_configured_message
domain, self.domain_not_configured_message, custom_uri=self.custom_uri
)

def __init__(
Expand All @@ -30,10 +30,12 @@ def __init__(
service,
info=None,
https=False,
custom_uri="",
**kwargs,
):
self.cname = cname
self.domain_not_configured_message = domain_not_configured_message
self.https = https
self.custom_uri = custom_uri
info = info if info else INFO
super().__init__(info.format(service=service), **kwargs)
6 changes: 4 additions & 2 deletions signatures/templates/cname_or_ip_found_but_string_in_body.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ def potential(self, domain, **kwargs) -> bool:
def check(self, domain, **kwargs) -> bool:
if self.https:
return signatures.checks.WEB.string_in_body_https(
domain, self.domain_not_configured_message
domain, self.domain_not_configured_message, custom_uri=self.custom_uri
)
return signatures.checks.WEB.string_in_body_http(
domain, self.domain_not_configured_message
domain, self.domain_not_configured_message, custom_uri=self.custom_uri
)

def __init__(
Expand All @@ -33,11 +33,13 @@ def __init__(
service,
info=None,
https=False,
custom_uri="",
**kwargs
):
self.cname = cname
self.ips = ips
self.domain_not_configured_message = domain_not_configured_message
self.https = https
self.custom_uri = custom_uri
info = info if info else INFO
super().__init__(info.format(service=service), **kwargs)
6 changes: 4 additions & 2 deletions signatures/templates/ip_found_but_string_in_body.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ def potential(self, domain, **kwargs) -> bool:
def check(self, domain, **kwargs) -> bool:
if self.https:
return signatures.checks.WEB.string_in_body_https(
domain, self.domain_not_configured_message
domain, self.domain_not_configured_message, custom_uri=self.custom_uri
)
return signatures.checks.WEB.string_in_body_http(
domain, self.domain_not_configured_message
domain, self.domain_not_configured_message, custom_uri=self.custom_uri
)

def __init__(
Expand All @@ -32,10 +32,12 @@ def __init__(
service,
info=None,
https=False,
custom_uri="",
**kwargs
):
self.ips = ips
self.domain_not_configured_message = domain_not_configured_message
self.https = https
self.custom_uri = custom_uri
info = info if info else INFO
super().__init__(info.format(service=service), **kwargs)
Loading