Skip to content

armgit / ARES

Public Imported from GitHub
0

ARES - authorized red-team engagement automation with dashboard, campaign scope, module orchestration, OPSEC controls, encrypted vault, and reporting.

fix(security): harden scheduled tasks xml parsing, prevent dpapi fd leaks, and modernize vnc registry cipher

Mafifrizia2ec917bd797
diff --git a/ares/modules/windows/dpapi.py b/ares/modules/windows/dpapi.py
index b30d4db..1079185 100644
--- a/ares/modules/windows/dpapi.py
+++ b/ares/modules/windows/dpapi.py
@@ -498,14 +498,18 @@ class DPAPIModule(BaseModule):
if not nt_bytes:
return []
- sha1_key = hashlib.sha1(nt_bytes).digest()
+ try:
+ sha1_key = hashlib.sha1(nt_bytes, usedforsecurity=False).digest()
+ except TypeError:
+ sha1_key = hashlib.sha1(nt_bytes).digest() # nosec: B324
creds: list[dict] = []
# Try to decrypt Windows Credential files
cred_path = local_files.get("credentials_dir", "")
if cred_path and os.path.isfile(cred_path):
try:
- cred_obj = Credential(open(cred_path, "rb").read())
+ with open(cred_path, "rb") as cred_fh:
+ cred_obj = Credential(cred_fh.read())
# decryption would go here with derived key
creds.append({
"source": "credential_manager",
diff --git a/ares/modules/windows/registry_enum.py b/ares/modules/windows/registry_enum.py
index 7df934f..02baa4c 100644
--- a/ares/modules/windows/registry_enum.py
+++ b/ares/modules/windows/registry_enum.py
@@ -60,16 +60,30 @@ def _decode_vnc_password(enc: bytes) -> str:
This decodes the raw registry bytes back to a 8-char password.
Key is publicly documented at: https://github.com/frizb/PasswordDecrypts
"""
+ vnc_key = b"\x17\x52\x6b\x06\x23\x4e\x58\x07"
+ padded = (enc + b"\x00" * 8)[:8]
try:
- from Crypto.Cipher import DES # type: ignore[import]
- vnc_key = b"\x17\x52\x6b\x06\x23\x4e\x58\x07"
- # Registry stores as REG_BINARY — pad to 8 bytes
- padded = (enc + b"\x00" * 8)[:8]
- cipher = DES.new(vnc_key, DES.MODE_ECB)
+ try:
+ from cryptography.hazmat.decrepit.ciphers.algorithms import TripleDES
+ except ImportError:
+ from cryptography.hazmat.primitives.ciphers.algorithms import TripleDES # type: ignore[no-redef]
+ from cryptography.hazmat.primitives.ciphers import Cipher, modes
+ cipher = Cipher(TripleDES(vnc_key * 3), modes.ECB()) # nosec: B304
+ decryptor = cipher.decryptor()
+ decoded = decryptor.update(padded) + decryptor.finalize()
+ return decoded.rstrip(b"\x00").decode("latin-1", errors="replace")
+ except ImportError:
+ pass
+ except Exception:
+ return f"<decode_error: {enc.hex()}>"
+
+ try:
+ from Crypto.Cipher import DES # type: ignore[import] # nosec: B413
+ cipher = DES.new(vnc_key, DES.MODE_ECB) # nosec: B304
decoded = cipher.decrypt(padded)
- return decoded.rstrip(b"\x00").decode("latin-1")
+ return decoded.rstrip(b"\x00").decode("latin-1", errors="replace")
except ImportError:
- return f"<encoded: {enc.hex()}> (install pycryptodome to decode)"
+ return f"<encoded: {enc.hex()}> (install cryptography to decode)"
except Exception:
return f"<decode_error: {enc.hex()}>"
diff --git a/ares/modules/windows/scheduled_tasks_enum.py b/ares/modules/windows/scheduled_tasks_enum.py
index cbe14a6..53e39b0 100644
--- a/ares/modules/windows/scheduled_tasks_enum.py
+++ b/ares/modules/windows/scheduled_tasks_enum.py
@@ -20,9 +20,13 @@ from __future__ import annotations
import asyncio
import re
-import xml.etree.ElementTree as ET
from typing import Any
+try:
+ from defusedxml.ElementTree import fromstring as _xml_fromstring
+except ImportError:
+ from xml.etree.ElementTree import fromstring as _xml_fromstring # nosec B405, B314
+
from ares.core.logger import get_logger, audit
from ares.core.campaign import Finding, Severity
from ares.core.security import sanitize_hostname
@@ -94,7 +98,7 @@ def _parse_task_xml(xml_str: str) -> dict[str, Any]:
try:
# Strip namespace for simpler parsing
xml_clean = re.sub(r'\s+xmlns(?::\w+)?="[^"]+"', "", xml_str)
- root = ET.fromstring(xml_clean)
+ root = _xml_fromstring(xml_clean) # nosec: B314
# Principal
for p in root.iter("Principal"):