Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
PiranhaSa committed Jan 22, 2024
1 parent b3a55b0 commit 40d2729
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 9 additions & 7 deletions agent/exploits/cve_2023_49897.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import requests
from ostorlab.agent.kb import kb
from ostorlab.agent.mixins import agent_report_vulnerability_mixin
from packaging import version
from requests import exceptions as requests_exceptions

from agent import definitions
Expand All @@ -19,6 +20,7 @@

DEFAULT_TIMEOUT = 90
MAX_REDIRECTS = 2
UPPER_VULNERABLE_VERSION = version.parse("2.0.9")
HEADERS = {
"Content-Type": "application/x-www-form-urlencoded",
"Cookie": "cookieno=489646; username=admin; password=admin",
Expand All @@ -37,7 +39,6 @@ def __init__(self) -> None:
self.session.verify = False

def accept(self, target: definitions.Target) -> bool:
target_uri = f"{target.scheme}://{target.host}:{target.port}"
data = {
"username_input": "admin",
"password_input": "admin",
Expand All @@ -48,32 +49,33 @@ def accept(self, target: definitions.Target) -> bool:
}
try:
self.session.post(
target_uri + "/cgi-bin/login.apply",
target.origin + "/cgi-bin/login.apply",
headers=HEADERS,
data=data,
timeout=DEFAULT_TIMEOUT,
)
response = self.session.get(
target_uri + "/main_top.htm", headers=HEADERS, timeout=DEFAULT_TIMEOUT
target.origin + "/main_top.htm",
headers=HEADERS,
timeout=DEFAULT_TIMEOUT,
)
return response.status_code == 200 and "logout" in response.text
except requests_exceptions.RequestException:
return False

def check(self, target: definitions.Target) -> list[definitions.Vulnerability]:
target_uri = f"{target.scheme}://{target.host}:{target.port}"
try:
response = self.session.get(
target_uri + "/cgi-bin/runtime?system_status",
target.origin + "/cgi-bin/runtime?system_status",
headers=HEADERS,
timeout=DEFAULT_TIMEOUT,
)
if response.status_code == 200:
pattern = re.compile(r"firmware_version=(\d+\.\d+\.\d+)")
match = pattern.search(response.text)
if match is not None:
firmware_version = match.group(1)
if firmware_version <= "2.0.9":
firmware_version = version.parse(match.group(1))
if firmware_version <= UPPER_VULNERABLE_VERSION:
vulnerability = self._create_vulnerability(target)
return [vulnerability]
except requests.exceptions.RequestException:
Expand Down
2 changes: 1 addition & 1 deletion tests/exploits/cve_2023_49897_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
system.general.hardware.version=R01
bootcode_info=U-Boot_1.1.4_1.2
version_bootcode=1.2
firmware_version=2.0.10
firmware_version=2.0.9
system.general.model_name=AE1021PE
system.general.mode=bridge
wifi.general.CountryCode=JP
Expand Down

0 comments on commit 40d2729

Please sign in to comment.