-
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.
- Loading branch information
Showing
9 changed files
with
216 additions
and
2 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,40 @@ | ||
from pathlib import Path | ||
from typing import Any, Dict, List | ||
|
||
from artemis.reporting.base.language import Language | ||
from artemis.reporting.base.report import Report | ||
from artemis.reporting.base.report_type import ReportType | ||
from artemis.reporting.base.reporter import Reporter | ||
from artemis.reporting.base.templating import ReportEmailTemplateFragment | ||
from artemis.reporting.utils import get_top_level_target | ||
|
||
|
||
class FortiVulnReporter(Reporter): # type: ignore | ||
VULNERABLE_FORTIOS = ReportType("forti_vuln") | ||
|
||
@staticmethod | ||
def create_reports(task_result: Dict[str, Any], language: Language) -> List[Report]: | ||
|
||
if task_result["headers"]["receiver"] != "forti_vuln": | ||
return [] | ||
|
||
if not task_result["status"] == "INTERESTING": | ||
return [] | ||
|
||
return [ | ||
Report( | ||
top_level_target=get_top_level_target(task_result), | ||
target=f"https://{task_result['target_string']}", | ||
report_type=FortiVulnReporter.VULNERABLE_FORTIOS, | ||
timestamp=task_result["created_at"], | ||
additional_data={"vuln": task_result["result"]}, | ||
) | ||
] | ||
|
||
@staticmethod | ||
def get_email_template_fragments() -> List[ReportEmailTemplateFragment]: | ||
return [ | ||
ReportEmailTemplateFragment.from_file( | ||
str(Path(__file__).parents[0] / "template_vulnerable_fortios.jinja2"), priority=10 | ||
), | ||
] |
14 changes: 14 additions & 0 deletions
14
autoreporter_addons/forti_vuln/template_vulnerable_fortios.jinja2
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,14 @@ | ||
{% if "forti_vuln" in data.contains_type %} | ||
<li>{% trans %}We have identified that the following Fortinet VPN gateways are affected by the critical CVE-2024-21762 vulnerability, which allows remote code execution without authentication:{% endtrans %} | ||
<ul> | ||
{% for report in data.reports %} | ||
{% if report.report_type == "forti_vuln" %} | ||
<li> | ||
{{ report.target }} | ||
{{ report_meta(report) }} | ||
</li> | ||
{% endif %} | ||
{% endfor %} | ||
</ul> | ||
</li> | ||
{% endif %} |
6 changes: 6 additions & 0 deletions
6
autoreporter_addons/forti_vuln/translations/en_US/LC_MESSAGES/messages.po
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,6 @@ | ||
#: autoreporter_addons/forti_vuln/template_vulnerable_fortios.jinja2:2 | ||
msgid "" | ||
"We have identified that the following Fortinet VPN gateways are affected " | ||
"by the critical CVE-2024-21762 vulnerability, which allows remote code " | ||
"execution without authentication:" | ||
msgstr "" |
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,6 @@ | ||
#: autoreporter_addons/forti_vuln/template_vulnerable_fortios.jinja2:2 | ||
msgid "" | ||
"We have identified that the following Fortinet VPN gateways are affected " | ||
"by the critical CVE-2024-21762 vulnerability, which allows remote code " | ||
"execution without authentication:" | ||
msgstr "" |
9 changes: 9 additions & 0 deletions
9
autoreporter_addons/forti_vuln/translations/pl_PL/LC_MESSAGES/messages.po
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,9 @@ | ||
#: autoreporter_addons/forti_vuln/template_vulnerable_fortios.jinja2:2 | ||
msgid "" | ||
"We have identified that the following Fortinet VPN gateways are affected " | ||
"by the critical CVE-2024-21762 vulnerability, which allows remote code " | ||
"execution without authentication:" | ||
msgstr "" | ||
"Wykryto, że następujące bramy Fortinet VPN są dotknięte krytyczną " | ||
"podatnością CVE-2024-21762, która umożliwia zdalne wykonanie kodu bez " | ||
"uwierzytelnienia:" |
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,5 @@ | ||
FROM certpl/artemis:latest | ||
|
||
WORKDIR /opt/ | ||
|
||
COPY forti_vuln/forti_vuln.py /opt/artemis/modules/ |
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,117 @@ | ||
#!/usr/bin/env python3 | ||
import socket | ||
import ssl | ||
from typing import Optional, Tuple | ||
|
||
from artemis.binds import Device, TaskStatus, TaskType | ||
from artemis.config import Config | ||
from artemis.module_base import ArtemisBase | ||
from artemis.task_utils import get_target_host | ||
from artemis.utils import throttle_request | ||
from karton.core import Task | ||
|
||
CONTROL_REQUEST = """POST /remote/VULNCHECK HTTP/1.1\r | ||
Host: {}\r | ||
User-Agent: {}\r | ||
Transfer-Encoding: chunked\r | ||
\r | ||
0\r | ||
\r | ||
\r | ||
""" | ||
|
||
VULN_CHECK_REQUEST = """POST /remote/VULNCHECK HTTP/1.1\r | ||
Host: {}\r | ||
User-Agent: {}\r | ||
Transfer-Encoding: chunked\r | ||
\r | ||
0000000000000000FF\r | ||
\r | ||
""" | ||
|
||
|
||
class FortiVuln(ArtemisBase): # type: ignore | ||
""" | ||
Checks FortiOS instance for CVE-2024-21762 vulnerability | ||
source: https://github.com/BishopFox/CVE-2024-21762-check | ||
""" | ||
|
||
identity = "forti_vuln" | ||
filters = [ | ||
{"type": TaskType.DEVICE.value, "device": Device.FORTIOS.value}, | ||
] | ||
|
||
@staticmethod | ||
def _send_req(ssl_context: Optional[ssl.SSLContext], address: Tuple[str, int], req: bytes) -> int: | ||
try: | ||
s = socket.create_connection(address, timeout=5) | ||
except Exception: | ||
return -1 | ||
|
||
if ssl_context is not None: | ||
ss = ssl_context.wrap_socket(s) | ||
ss.send(req) | ||
else: | ||
s.send(req) | ||
|
||
try: | ||
if ssl_context is not None: | ||
ss.read(2048) | ||
else: | ||
s.recv(2048) | ||
return 1 | ||
except socket.timeout: | ||
return 0 | ||
|
||
def vuln_check(self, host: str, port: int, is_ssl: bool) -> int: | ||
ssl_context = None | ||
if is_ssl: | ||
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) | ||
ssl_context.check_hostname = False | ||
ssl_context.verify_mode = ssl.CERT_NONE | ||
|
||
http_host = f"{host}:{port}" | ||
self.log.info(f"forti vuln scanning {http_host}") | ||
|
||
user_agent = "FortiOS vulnerability scanner" | ||
if Config.Miscellaneous.CUSTOM_USER_AGENT: | ||
user_agent = Config.Miscellaneous.CUSTOM_USER_AGENT | ||
|
||
r1 = throttle_request( | ||
lambda: self._send_req(ssl_context, (host, port), CONTROL_REQUEST.format(http_host, user_agent).encode()) | ||
) | ||
if r1 in [-1, 0]: | ||
return -1 | ||
else: | ||
r2 = throttle_request( | ||
lambda: self._send_req( | ||
ssl_context, (host, port), VULN_CHECK_REQUEST.format(http_host, user_agent).encode() | ||
) | ||
) | ||
if r2 == 0: | ||
return 1 | ||
return 0 | ||
|
||
def run(self, current_task: Task) -> None: | ||
result = [] | ||
status = TaskStatus.OK | ||
status_reason = None | ||
|
||
ssl = current_task.get_payload("ssl") | ||
host = get_target_host(current_task) | ||
port = current_task.get_payload("port") | ||
check = self.vuln_check(host, port, ssl) | ||
|
||
if check == -1: | ||
status = TaskStatus.ERROR | ||
status_reason = "Could not send control request" | ||
elif check == 1: | ||
result.append("CVE-2024-21762") | ||
status = TaskStatus.INTERESTING | ||
status_reason = "Detected CVE-2024-21762 vulnerability" | ||
|
||
self.db.save_task_result(task=current_task, status=status, status_reason=status_reason, data=result) | ||
|
||
|
||
if __name__ == "__main__": | ||
FortiVuln().loop() |