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

dev to main push #100

Merged
merged 3 commits into from
Nov 28, 2023
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
10 changes: 7 additions & 3 deletions badsecrets/examples/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,17 @@ def report(self):
elif severity == "INFO":
severity_color = Fore.BLUE
print_status(f"Severity: {self.x['description']['severity']}", color=severity_color)
print(f"Details: {self.x['details']}")
print(f"Details: {self.x['details']}\n")


class ReportIdentify(BaseReport):
def report(self):
self.print_report(
print_status("Cryptographic Product Identified (no vulnerability)\n", color=Fore.YELLOW, passthru=True)
print_status(
"Cryptographic Product Identified (no vulnerability, or not confirmed vulnerable)\n",
color=Fore.YELLOW,
passthru=True,
)
)
if self.x["hashcat"] is not None:
print_hashcat_results(self.x["hashcat"])
Expand Down Expand Up @@ -117,7 +121,7 @@ def validate_file(file):
def print_hashcat_results(hashcat_candidates):
print_status("\nPotential matching hashcat commands:\n", color=Fore.YELLOW)
for hc in hashcat_candidates:
print(f"Module: [{hc['detecting_module']}] {hc['hashcat_description']} Command: [{hc['hashcat_command']}]")
print(f"Module: [{hc['detecting_module']}] {hc['hashcat_description']} Command: [{hc['hashcat_command']}]\n")


def main():
Expand Down
11 changes: 8 additions & 3 deletions badsecrets/modules/aspnet_vstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@
from badsecrets.base import BadsecretsBase
from badsecrets.modules.aspnet_viewstate import ASPNET_Viewstate

# Reference: https://www.graa.nl/articles/2010.html
# Reference: https://blog.sorcery.ie/posts/higherlogic_rce/


class ASPNET_vstate(BadsecretsBase):
identify_regex = re.compile(r"^H4sI.+$")
description = {"product": "ASP.NET Compressed Vstate", "secret": "unprotected", "severity": "CRITICAL"}

def carve_regex(self):
return re.compile(r"<input.+__VSTATE\"\svalue=\"(H4sI.+)\"")
return re.compile(r"<input.+__VSTATE\"\svalue=\"(.*)\"")

def get_product_from_carve(self, regex_search):
product = regex_search.groups()[0]
if len(product) == 0:
return "EMPTY '__VSTATE' FORM FIELD"
return product

def check_secret(self, compressed_vstate):
if not self.identify(compressed_vstate):
Expand All @@ -21,4 +27,3 @@ def check_secret(self, compressed_vstate):
if uncompressed and ASPNET_Viewstate.valid_preamble(uncompressed):
r = {"source": compressed_vstate, "info": "ASP.NET Vstate (Unprotected, Compressed)"}
return {"secret": "UNPROTECTED (compressed)", "details": r}
return None
40 changes: 40 additions & 0 deletions tests/all_modules_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,43 @@ def test_carve_all_cookies():
res = requests.get(f"http://cookies.carve-all.badsecrets.com/")
r_list = carve_all_modules(requests_response=res)
assert len(r_list) == 7


def test_carve_multiple_vulns():
multiple_vuln_html = """
<div class="aspNetHidden">
<input type="hidden" name="__VSTATE" id="__VSTATE" value="H4sIAAAAAAAA/81VXW/TMBRNltZNsnVsCBCMFwvxAFrVde3G2EORpo6PagJNZOJlqpib3LURiT0cRyg888p/4Q/xW4Zv6w6GG" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="jxwpcd5AwfMUcwXM5rJFA9dtrSgoT3ezfxneYLjsXW7pB/TjlgNbzsx3dY/P+FlXTZReIQ==" />
<input type="hidden" name="__VIEWSTATEGENERATOR" value="AAAAAAAA" />
"""

with requests_mock.Mocker() as m:
m.get(
f"http://multiplevulns.carve-all.badsecrets.com/",
status_code=200,
text=multiple_vuln_html,
)

res = requests.get(f"http://multiplevulns.carve-all.badsecrets.com/")
r_list = carve_all_modules(requests_response=res)
assert len(r_list) == 2


def test_carve_empty_vstate():
empty_vstate_html = """
<div class="aspNetHidden">
<input type="hidden" name="__VSTATE" id="__VSTATE" value="" />

"""

with requests_mock.Mocker() as m:
m.get(
f"http://emptyvstate.carve-all.badsecrets.com/",
status_code=200,
text=empty_vstate_html,
)

res = requests.get(f"http://emptyvstate.carve-all.badsecrets.com/")
r_list = carve_all_modules(requests_response=res)
assert r_list
assert r_list[0]["product"] == "EMPTY '__VSTATE' FORM FIELD"
4 changes: 2 additions & 2 deletions tests/examples_cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def test_example_cli_vulnerable_headersidentifyonly(monkeypatch, capsys):
"Data Cookie: [session=eyJ1c2VybmFtZSI6IkJib3RJc0xpZmUifQ==] Signature Cookie: [8BrG9wzvqxuPCtKmfgdyXXGGqA7]"
in captured.out
)
assert "Cryptographic Product Identified (no vulnerability)" in captured.out
assert "Cryptographic Product Identified (no vulnerability, or not confirmed vulnerable)" in captured.out


def test_example_cli_not_vulnerable_url(monkeypatch, capsys):
Expand Down Expand Up @@ -213,7 +213,7 @@ def test_example_cli_identifyonly_url(monkeypatch, capsys):
cli.main()
captured = capsys.readouterr()
print(captured)
assert "Cryptographic Product Identified (no vulnerability)" in captured.out
assert "Cryptographic Product Identified (no vulnerability, or not confirmed vulnerable)" in captured.out


def test_example_cli_identifyonly_hashcat(monkeypatch, capsys):
Expand Down