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(modules): verify TLS by default on LDAPS/WinRM/HTTPS (run-1 H15/H16/H17) (#73)

kraii_da9d84007cc7
diff --git a/ares/core/config.py b/ares/core/config.py
index 12a2b6b..c6b2a76 100644
--- a/ares/core/config.py
+++ b/ares/core/config.py
@@ -81,6 +81,12 @@ class AresSettings(BaseSettings):
ares_rate_limit_rpm: int = Field(60, ge=1)
ares_debug: bool = False
ares_legacy_dashboard_enabled: bool = False
+ # Opt-in to disable TLS certificate verification on authenticated outbound
+ # connections (LDAPS binds, WinRM-over-HTTPS, HTTPS recon). Off by default so
+ # privileged credentials are not exposed to a transparent MITM; set
+ # ARES_ALLOW_INSECURE_TLS=true only for lab targets with self-signed certs.
+ # (AUDIT run-1 H15/H16/H17)
+ ares_allow_insecure_tls: bool = False
# Database
ares_database_url: str = "sqlite+aiosqlite:///./ares.db"
diff --git a/ares/modules/_tls_security.py b/ares/modules/_tls_security.py
new file mode 100644
index 0000000..e438bf0
--- /dev/null
+++ b/ares/modules/_tls_security.py
@@ -0,0 +1,91 @@
+"""Shared TLS verification policy for outbound module connections.
+
+AUDIT run-1 H15/H16/H17. Authenticated LDAPS binds, WinRM-over-HTTPS NTLM
+transports and HTTPS recon previously disabled certificate verification
+unconditionally, exposing the privileged credentials they carry (and the
+responses they trust) to a transparent man-in-the-middle. These helpers make
+verification the default and gate the insecure behaviour behind an explicit
+operator opt-in (``ARES_ALLOW_INSECURE_TLS=true`` / ``settings.ares_allow_insecure_tls``),
+emitting a loud warning whenever verification is actually disabled.
+"""
+from __future__ import annotations
+
+import ssl
+from typing import Any
+
+from ares.core.logger import get_logger
+
+logger = get_logger("ares.modules.tls")
+
+
+def insecure_tls_allowed() -> bool:
+ """Return True only when the operator has explicitly opted in to disabling
+ TLS verification. Any failure to resolve settings fails closed (secure)."""
+ try:
+ from ares.core.config import get_settings
+
+ return bool(getattr(get_settings(), "ares_allow_insecure_tls", False))
+ except Exception:
+ return False
+
+
+def _warn_insecure(channel: str) -> None:
+ logger.warning(
+ "tls_verification_disabled",
+ channel=channel,
+ detail="ARES_ALLOW_INSECURE_TLS is set; server certificate is NOT verified. "
+ "Credentials and responses on this channel are exposed to MITM.",
+ )
+
+
+def ldap_tls(use_ssl: bool, *, ca_certs_file: str | None = None) -> Any:
+ """Build an ldap3 ``Tls`` config for a (possibly) LDAPS bind.
+
+ Returns ``None`` for plaintext LDAP. For LDAPS the certificate is required
+ and validated against the system trust store by default; verification is
+ only disabled when the operator has opted in.
+ """
+ if not use_ssl:
+ return None
+ from ldap3 import Tls
+
+ if insecure_tls_allowed():
+ _warn_insecure("ldaps")
+ return Tls(validate=ssl.CERT_NONE)
+ return Tls(validate=ssl.CERT_REQUIRED, ca_certs_file=ca_certs_file)
+
+
+def winrm_cert_validation(use_ssl: bool) -> str:
+ """Return the pywinrm ``server_cert_validation`` value for a transport.
+
+ "validate" by default on HTTPS; "ignore" only on operator opt-in. For
+ plaintext HTTP the value is irrelevant but we return "validate".
+ """
+ if use_ssl and insecure_tls_allowed():
+ _warn_insecure("winrm")
+ return "ignore"
+ return "validate"
+
+
+def httpx_verify() -> bool:
+ """Return the ``verify`` value for an httpx client (True unless opted out)."""
+ if insecure_tls_allowed():
+ _warn_insecure("https")
+ return False
+ return True
+
+
+def harden_ssl_context(ctx: ssl.SSLContext, *, channel: str = "tls") -> ssl.SSLContext:
+ """Enforce verification on an ``ssl.SSLContext`` unless opted out.
+
+ ``ssl.create_default_context()`` already verifies; this makes the policy
+ explicit and only relaxes it (hostname + cert) on operator opt-in.
+ """
+ if insecure_tls_allowed():
+ _warn_insecure(channel)
+ ctx.check_hostname = False
+ ctx.verify_mode = ssl.CERT_NONE
+ else:
+ ctx.check_hostname = True
+ ctx.verify_mode = ssl.CERT_REQUIRED
+ return ctx
diff --git a/ares/modules/ad/adcs.py b/ares/modules/ad/adcs.py
index 3361913..079a9da 100644
--- a/ares/modules/ad/adcs.py
+++ b/ares/modules/ad/adcs.py
@@ -27,6 +27,7 @@ from ares.core.campaign import Severity
from ares.core.logger import audit, get_logger
from ares.core.security import sanitize_hostname, sanitize_ldap
from ares.core.tracing import trace_module
+from ares.modules._tls_security import ldap_tls
from ares.modules.params import ADCSParams
from ares.sdk import (
BaseModule,
@@ -700,10 +701,9 @@ class ADCSModule(BaseModule[ADCSParams, ModuleResult]):
if not target_user:
return posture
- import ssl
try:
import ldap3
- from ldap3 import ALL, NTLM, SUBTREE, Connection, Server, Tls
+ from ldap3 import ALL, NTLM, SUBTREE, Connection, Server
except ImportError:
posture["error"] = "ldap3 module not installed"
return posture
@@ -711,7 +711,7 @@ class ADCSModule(BaseModule[ADCSParams, ModuleResult]):
conn = None
for port, use_ssl in [(636, True), (389, False)]:
try:
- tls_arg = Tls(validate=ssl.CERT_NONE) if use_ssl else None
+ tls_arg = ldap_tls(use_ssl)
server = Server(dc, port=port, use_ssl=use_ssl, tls=tls_arg,
get_info=ALL, connect_timeout=10)
conn = Connection(server, user=f"{domain.upper()}\\{username}",
@@ -848,16 +848,15 @@ class ADCSModule(BaseModule[ADCSParams, ModuleResult]):
def _enum_templates_sync(self, dc: str, username: str, password: str,
domain: str) -> tuple[list[dict], list[dict]]:
"""Query LDAP for certificate templates and CA objects. Sync - runs in executor."""
- import ssl
import ldap3
- from ldap3 import ALL, NTLM, SUBTREE, Connection, Server, Tls
+ from ldap3 import ALL, NTLM, SUBTREE, Connection, Server
from ldap3.core.exceptions import LDAPBindError
conn = None
for port, use_ssl in [(636, True), (389, False)]:
try:
- tls_arg = Tls(validate=ssl.CERT_NONE) if use_ssl else None
+ tls_arg = ldap_tls(use_ssl)
server = Server(dc, port=port, use_ssl=use_ssl, tls=tls_arg,
get_info=ALL, connect_timeout=10)
conn = Connection(server, user=f"{domain.upper()}\\{username}",
diff --git a/ares/modules/ad/asreproast.py b/ares/modules/ad/asreproast.py
index a36616a..b31008f 100644
--- a/ares/modules/ad/asreproast.py
+++ b/ares/modules/ad/asreproast.py
@@ -26,6 +26,7 @@ from ares.core.campaign import Severity
from ares.core.errors import AresError, ModuleValidationError
from ares.core.security import sanitize_hostname, sanitize_ldap
from ares.core.tracing import trace_module
+from ares.modules._tls_security import ldap_tls
from ares.modules.ad.dependencies import (
ad_bind_dry_run_metadata,
build_ad_bind_plan,
@@ -613,10 +614,9 @@ class ASREPRoastModule(BaseModule[ASREPRoastParams, ModuleResult]):
async def _ldap_get_nopreauth(self, dc, domain, username, password):
"""Query LDAP for accounts with DONT_REQUIRE_PREAUTH enabled."""
ensure_ad_dependencies(("ldap3",), module_id=self.MODULE_ID)
- import ssl
import ldap3
- from ldap3 import ALL, SUBTREE, Connection, Server, Tls
+ from ldap3 import ALL, SUBTREE, Connection, Server
from ldap3.core.exceptions import LDAPBindError
bind_plan = build_ad_bind_plan(username, domain)
@@ -624,7 +624,7 @@ class ASREPRoastModule(BaseModule[ASREPRoastParams, ModuleResult]):
last_error = None
for port, use_ssl in [(636, True), (389, False)]:
try:
- tls_arg = Tls(validate=ssl.CERT_NONE) if use_ssl else None
+ tls_arg = ldap_tls(use_ssl)
server = Server(dc, port=port, use_ssl=use_ssl,
tls=tls_arg, get_info=ALL, connect_timeout=10)
conn_kwargs = {
diff --git a/ares/modules/ad/delegation_abuse.py b/ares/modules/ad/delegation_abuse.py
index 1ca3abb..3cbe9bc 100644
--- a/ares/modules/ad/delegation_abuse.py
+++ b/ares/modules/ad/delegation_abuse.py
@@ -29,6 +29,7 @@ from ares.core.campaign import Severity
from ares.core.logger import audit, get_logger
from ares.core.security import sanitize_hostname, sanitize_ldap
from ares.core.tracing import trace_module
+from ares.modules._tls_security import ldap_tls
from ares.modules.params import DelegationAbuseParams
from ares.sdk import (
BaseModule,
@@ -327,15 +328,14 @@ class DelegationAbuseModule(BaseModule[DelegationAbuseParams, ModuleResult]):
def _enum_delegation_sync(self, dc: str, username: str, password: str,
domain: str) -> tuple[list[dict], list[dict]]:
"""Enumerate unconstrained and constrained delegation via LDAP."""
- import ssl
import ldap3
- from ldap3 import ALL, NTLM, SUBTREE, Connection, Server, Tls
+ from ldap3 import ALL, NTLM, SUBTREE, Connection, Server
conn = None
for port, use_ssl in [(636, True), (389, False)]:
try:
- tls_arg = Tls(validate=ssl.CERT_NONE) if use_ssl else None
+ tls_arg = ldap_tls(use_ssl)
server = Server(dc, port=port, use_ssl=use_ssl, tls=tls_arg,
get_info=ALL, connect_timeout=10)
conn = Connection(server, user=f"{domain.upper()}\\{username}",
diff --git a/ares/modules/ad/enum_acl.py b/ares/modules/ad/enum_acl.py
index 12f5290..e410f33 100644
--- a/ares/modules/ad/enum_acl.py
+++ b/ares/modules/ad/enum_acl.py
@@ -8,6 +8,7 @@ from __future__ import annotations
from typing import Any
from ares.core.logger import get_logger
+from ares.modules._tls_security import ldap_tls
logger = get_logger("ares.modules.ad.enum_acl")
from ares.core.campaign import Severity
@@ -218,17 +219,16 @@ class ADEnumACLModule(BaseModule[DomainAuthParams, ModuleResult]):
Sync - runs in executor (fix: was async def blocking event loop).
Fixes: AUTO_BIND_NONE, cookie loop, LDAPS fallback, try/finally unbind.
"""
- import ssl
import ldap3
- from ldap3 import ALL, NTLM, SUBTREE, Connection, Server, Tls
+ from ldap3 import ALL, NTLM, SUBTREE, Connection, Server
from ldap3.core.exceptions import LDAPBindError
bind_plan = build_ad_bind_plan(username, domain)
conn = None
for port, use_ssl in [(636, True), (389, False)]:
try:
- tls_arg = Tls(validate=ssl.CERT_NONE) if use_ssl else None
+ tls_arg = ldap_tls(use_ssl)
server = Server(dc, port=port, use_ssl=use_ssl,
tls=tls_arg, get_info=ALL, connect_timeout=10)
conn_kwargs = {
diff --git a/ares/modules/ad/enum_computers.py b/ares/modules/ad/enum_computers.py
index f4de458..0861872 100644
--- a/ares/modules/ad/enum_computers.py
+++ b/ares/modules/ad/enum_computers.py
@@ -16,6 +16,7 @@ from ares.core.campaign import Severity
from ares.core.errors import AresError, ModuleValidationError, NetworkError
from ares.core.security import sanitize_hostname, sanitize_ldap
from ares.core.tracing import trace_module
+from ares.modules._tls_security import ldap_tls
from ares.modules.ad.dependencies import build_ad_bind_plan
from ares.modules.params import DomainAuthParams
from ares.sdk import (
@@ -258,11 +259,10 @@ class ADEnumComputersModule(BaseModule[DomainAuthParams, ModuleResult]):
return self._findings, raw
async def _fetch_computers(self, dc, username, password, domain, use_ldaps=True):
- import ssl
- from ldap3 import ALL, AUTO_BIND_NO_TLS, NTLM, SUBTREE, Connection, Server, Tls
+ from ldap3 import ALL, AUTO_BIND_NO_TLS, NTLM, SUBTREE, Connection, Server
port = 636 if use_ldaps else 389
- tls = Tls(validate=ssl.CERT_NONE) if use_ldaps else None
+ tls = ldap_tls(use_ldaps)
bind_plan = build_ad_bind_plan(username, domain)
try:
server = Server(
diff --git a/ares/modules/ad/enum_spn.py b/ares/modules/ad/enum_spn.py
index 80e648e..e54e900 100644
--- a/ares/modules/ad/enum_spn.py
+++ b/ares/modules/ad/enum_spn.py
@@ -11,6 +11,7 @@ from ares.core.campaign import Severity
from ares.core.errors import AresError, ModuleValidationError
from ares.core.security import sanitize_hostname, sanitize_ldap
from ares.core.tracing import trace_module
+from ares.modules._tls_security import ldap_tls
from ares.modules.ad.dependencies import (
ad_bind_dry_run_metadata,
build_ad_bind_plan,
@@ -254,10 +255,9 @@ class ADEnumSPNModule(BaseModule[DomainAuthParams, ModuleResult]):
Issue #1 fix: moved from async def to sync def + run_in_executor call above.
Issue #2 fix: conn.unbind() in try/finally - always closes even on exception.
"""
- import ssl
import ldap3
- from ldap3 import ALL, SUBTREE, Connection, Server, Tls
+ from ldap3 import ALL, SUBTREE, Connection, Server
from ldap3.core.exceptions import LDAPBindError
# Try LDAPS first, fallback to plain LDAP
@@ -266,7 +266,7 @@ class ADEnumSPNModule(BaseModule[DomainAuthParams, ModuleResult]):
last_error = None
for port, use_ssl in [(636, True), (389, False)]:
try:
- tls_arg = Tls(validate=ssl.CERT_NONE) if use_ssl else None
+ tls_arg = ldap_tls(use_ssl)
server = Server(dc, port=port, use_ssl=use_ssl,
tls=tls_arg, get_info=ALL,
connect_timeout=10)
diff --git a/ares/modules/ad/enum_users.py b/ares/modules/ad/enum_users.py
index fd475d1..b358494 100644
--- a/ares/modules/ad/enum_users.py
+++ b/ares/modules/ad/enum_users.py
@@ -38,6 +38,9 @@ UAC_ACCOUNT_DISABLE = 0x0002
UAC_DONT_EXPIRE_PASSWORD = 0x10000
UAC_PREAUTH_NOT_REQUIRED = 0x400000
+from ares.modules._tls_security import ldap_tls
+
+
def _dn_to_base(domain: str) -> str:
return ",".join(f"DC={p}" for p in domain.upper().split("."))
@@ -255,10 +258,9 @@ class ADEnumUsersModule(BaseModule[DomainAuthParams, ModuleResult]):
Fix Issue #1: moved from async def to sync def + run_in_executor call above.
Fix Issue #2: conn.unbind() in try/finally - always closes even on exception.
"""
- import ssl
import ldap3
- from ldap3 import ALL, NTLM, SUBTREE, Connection, Server, Tls
+ from ldap3 import ALL, NTLM, SUBTREE, Connection, Server
from ldap3.core.exceptions import LDAPBindError
bind_plan = build_ad_bind_plan(username, domain)
@@ -267,7 +269,7 @@ class ADEnumUsersModule(BaseModule[DomainAuthParams, ModuleResult]):
for port, use_ssl in ([(636, True), (389, False)] if use_ldaps else [(389, False)]):
attempt_conn = None
try:
- tls_arg = Tls(validate=ssl.CERT_NONE) if use_ssl else None
+ tls_arg = ldap_tls(use_ssl)
server = Server(dc, port=port, use_ssl=use_ssl,
tls=tls_arg, get_info=ALL,
connect_timeout=10)
diff --git a/ares/modules/ad/laps_enum.py b/ares/modules/ad/laps_enum.py
index 1cf8d16..ce81110 100644
--- a/ares/modules/ad/laps_enum.py
+++ b/ares/modules/ad/laps_enum.py
@@ -24,6 +24,7 @@ from ares.core.campaign import Severity
from ares.core.logger import audit, get_logger
from ares.core.security import sanitize_hostname, sanitize_ldap
from ares.core.tracing import trace_module
+from ares.modules._tls_security import ldap_tls
from ares.modules.ad.dependencies import build_ad_bind_plan
from ares.modules.params import LAPSEnumParams
from ares.sdk import (
@@ -312,16 +313,15 @@ class LAPSEnumModule(BaseModule[LAPSEnumParams, ModuleResult]):
Returns list of {computer, password, version, expiry}.
Sync - runs in executor.
"""
- import ssl
import ldap3
- from ldap3 import ALL, NTLM, SUBTREE, Connection, Server, Tls
+ from ldap3 import ALL, NTLM, SUBTREE, Connection, Server
bind_plan = build_ad_bind_plan(username, domain)
conn = None
for port, use_ssl in [(636, True), (389, False)]:
try:
- tls_arg = Tls(validate=ssl.CERT_NONE) if use_ssl else None
+ tls_arg = ldap_tls(use_ssl)
server = Server(dc, port=port, use_ssl=use_ssl, tls=tls_arg,
get_info=ALL, connect_timeout=10)
conn_kwargs = {
diff --git a/ares/modules/ad/sccm.py b/ares/modules/ad/sccm.py
index 45a2b53..ea4b6f7 100644
--- a/ares/modules/ad/sccm.py
+++ b/ares/modules/ad/sccm.py
@@ -39,6 +39,7 @@ from ares.core.campaign import Finding, Severity
from ares.core.logger import audit, get_logger
from ares.core.security import sanitize_hostname, sanitize_ldap
from ares.core.tracing import trace_module
+from ares.modules._tls_security import ldap_tls
from ares.modules.params import SCCMParams
from ares.sdk import (
BaseModule,
@@ -387,10 +388,9 @@ class SCCMModule(BaseModule[SCCMParams, ModuleResult]):
result: dict = {"error": None, "site_servers": [], "management_points": [],
"distribution_points": [], "site_code": ""}
try:
- import ssl
import ldap3
- tls = ldap3.Tls(validate=ssl.CERT_NONE) # noqa: F841
+ tls = ldap_tls(True) # noqa: F841
server = ldap3.Server(dc, port=389, connect_timeout=10)
conn = ldap3.Connection(
server, user=f"{domain.upper()}\\{username}",
diff --git a/ares/modules/cloud/identity_federation.py b/ares/modules/cloud/identity_federation.py
index a7d5d9c..c25b8b3 100644
--- a/ares/modules/cloud/identity_federation.py
+++ b/ares/modules/cloud/identity_federation.py
@@ -32,6 +32,7 @@ from ares.core.campaign import Finding, Severity
from ares.core.logger import audit, get_logger
from ares.core.security import sanitize_hostname
from ares.core.tracing import trace_module
+from ares.modules._tls_security import httpx_verify
from ares.modules.base import BaseModule, ModuleResult, OpsecLevel
from ares.modules.params import CloudFederationParams
from ares.sdk import (
@@ -537,7 +538,7 @@ class CloudIdentityFederationModule(BaseModule):
try:
import httpx
- with httpx.Client(follow_redirects=False, timeout=15, verify=False) as client:
+ with httpx.Client(follow_redirects=False, timeout=15, verify=httpx_verify()) as client:
# Try ADFS federation metadata
endpoints_to_try = [
f"{adfs_url}/FederationMetadata/2007-06/FederationMetadata.xml",
diff --git a/ares/modules/credential/pass_spray.py b/ares/modules/credential/pass_spray.py
index 04475ec..2f67cba 100644
--- a/ares/modules/credential/pass_spray.py
+++ b/ares/modules/credential/pass_spray.py
@@ -47,6 +47,9 @@ DEFAULT_SPRAY_PASSWORDS = [
# ── Password policy query ─────────────────────────────────────────────────────
+from ares.modules._tls_security import ldap_tls
+
+
def query_password_policy(
dc: str, domain: str, username: str, password: str,
) -> dict[str, Any]:
@@ -66,12 +69,10 @@ def query_password_policy(
"""
result: dict[str, Any] = {"error": None, "policy_found": False}
try:
- import ssl
-
import ldap3
for port, use_ssl in [(636, True), (389, False)]:
try:
- tls = ldap3.Tls(validate=ssl.CERT_NONE) if use_ssl else None
+ tls = ldap_tls(use_ssl)
server = ldap3.Server(dc, port=port, use_ssl=use_ssl,
tls=tls, connect_timeout=10)
conn = ldap3.Connection(
@@ -648,11 +649,10 @@ class PassSprayModule(BaseModule[PassSprayParams, ModuleResult]):
if use_ldap:
# LDAP SIMPLE bind - fallback when SMB 445 is blocked
try:
- import ssl
import ldap3
use_ssl = (ldap_port == 636)
- tls_arg = ldap3.Tls(validate=ssl.CERT_NONE) if use_ssl else None
+ tls_arg = ldap_tls(use_ssl)
server = ldap3.Server(
target, port=ldap_port,
use_ssl=use_ssl, tls=tls_arg,
diff --git a/ares/modules/credential/reuse.py b/ares/modules/credential/reuse.py
index cbe6486..e0992a2 100644
--- a/ares/modules/credential/reuse.py
+++ b/ares/modules/credential/reuse.py
@@ -31,6 +31,9 @@ from ares.sdk import (
logger = get_logger("ares.modules.credential.reuse")
+from ares.modules._tls_security import harden_ssl_context
+
+
def _audit_oauth_posture_sync(target: str) -> dict[str, Any]:
"""
Non-destructive probe of OAuth 2.0 Device Code Flow / Identity Posture.
@@ -48,8 +51,7 @@ def _audit_oauth_posture_sync(target: str) -> dict[str, Any]:
clean_target = target.strip().lower()
ctx = ssl.create_default_context()
- ctx.check_hostname = False
- ctx.verify_mode = ssl.CERT_NONE
+ harden_ssl_context(ctx)
probe_urls: list[str] = []
# MOD-032: Do not probe public login.microsoftonline.com if target is private/internal RFC1918 IP
diff --git a/ares/modules/lateral/modules.py b/ares/modules/lateral/modules.py
index 3d472f5..8bd16b0 100644
--- a/ares/modules/lateral/modules.py
+++ b/ares/modules/lateral/modules.py
@@ -50,6 +50,9 @@ if TYPE_CHECKING:
logger = get_logger("ares.lateral")
+from ares.modules._tls_security import winrm_cert_validation
+
+
class LateralTechnique(str, Enum):
PSEXEC = "psexec"
WMIEXEC = "wmiexec"
@@ -1105,7 +1108,7 @@ class WinRMLateral(BaseLateralModule):
endpoint,
auth=(target_user, auth.password),
transport="kerberos",
- server_cert_validation="ignore" if use_ssl else "validate",
+ server_cert_validation=winrm_cert_validation(use_ssl),
)
r = session.run_cmd(command)
stdout = r.std_out.decode("utf-8", errors="replace").strip()
@@ -1124,7 +1127,7 @@ class WinRMLateral(BaseLateralModule):
endpoint,
auth=(target_user, auth.password or secret),
transport=protocol,
- server_cert_validation="ignore" if use_ssl else "validate",
+ server_cert_validation=winrm_cert_validation(use_ssl),
)
r = session.run_cmd(command)
stdout = r.std_out.decode("utf-8", errors="replace").strip()
diff --git a/ares/modules/lateral/ntlm_relay.py b/ares/modules/lateral/ntlm_relay.py
index 817618a..76ceafd 100644
--- a/ares/modules/lateral/ntlm_relay.py
+++ b/ares/modules/lateral/ntlm_relay.py
@@ -32,6 +32,7 @@ from ares.core.campaign import Finding, Severity
from ares.core.logger import audit, get_logger
from ares.core.security import sanitize_hostname
from ares.core.tracing import trace_module
+from ares.modules._tls_security import ldap_tls
from ares.modules.base import BaseModule, OpsecLevel
from ares.modules.params import NTLMRelayParams
from ares.sdk import (
@@ -439,13 +440,12 @@ class NTLMRelayModule(BaseModule):
"""Enumerate domain computers via LDAP to build target list."""
loop = asyncio.get_running_loop()
def _ldap_enum():
- import ssl
import ldap3
hosts = []
for port, use_ssl in [(636, True), (389, False)]:
try:
- tls = ldap3.Tls(validate=ssl.CERT_NONE) if use_ssl else None
+ tls = ldap_tls(use_ssl)
server = ldap3.Server(dc, port=port, use_ssl=use_ssl,
tls=tls, connect_timeout=10)
conn = ldap3.Connection(
@@ -544,10 +544,8 @@ class NTLMRelayModule(BaseModule):
# Check LDAP signing (try unauthenticated bind to check)
def _check_ldap(h=host):
try:
- import ssl
-
import ldap3
- tls = ldap3.Tls(validate=ssl.CERT_NONE)
+ tls = ldap_tls(True)
# Try LDAPS first (636), then LDAP (389)
for port, use_ssl in [(389, False)]:
try:
@@ -777,13 +775,11 @@ class NTLMRelayModule(BaseModule):
dacl_modified = False
try:
- import ssl
-
# Step 1: Bind via LDAP
import ldap3
from impacket.ldap import ldap as imp_ldap # noqa: F401
from impacket.ldap import ldapasn1 as ldapasn1_impacket # noqa: F401
- tls = ldap3.Tls(validate=ssl.CERT_NONE) # noqa: F841
+ tls = ldap_tls(True) # noqa: F841
server = ldap3.Server(dc, port=389, connect_timeout=10)
conn = ldap3.Connection(
server, user=f"{domain.upper()}\\{username}",
diff --git a/ares/modules/network/http_fingerprint.py b/ares/modules/network/http_fingerprint.py
index 728ef7a..442ce19 100644
--- a/ares/modules/network/http_fingerprint.py
+++ b/ares/modules/network/http_fingerprint.py
@@ -13,6 +13,7 @@ from typing import Any
from ares.core.campaign import Finding, Severity
from ares.core.logger import get_logger
from ares.core.tracing import trace_module
+from ares.modules._tls_security import httpx_verify
from ares.modules.base import BaseModule, OpsecLevel
from ares.modules.params import HTTPFingerprintParams
from ares.sdk import (
@@ -248,7 +249,7 @@ class HttpFingerprintModule(BaseModule):
try:
async with httpx.AsyncClient(
- timeout=6.0, verify=False,
+ timeout=6.0, verify=httpx_verify(),
follow_redirects=False,
headers={"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"},
) as client:
diff --git a/ares/modules/network/service_detect.py b/ares/modules/network/service_detect.py
index b414499..7e9dfbb 100644
--- a/ares/modules/network/service_detect.py
+++ b/ares/modules/network/service_detect.py
@@ -79,6 +79,9 @@ _OS_PATTERNS: list[tuple[str, str, str, float]] = [
]
+from ares.modules._tls_security import harden_ssl_context
+
+
def _fingerprint_os_from_banners(banners: list[str]) -> dict[str, Any] | None:
combined = " ".join(banners).lower()
for pattern, family, distro, conf in _OS_PATTERNS:
@@ -98,8 +101,7 @@ async def _grab_banner(host: str, port: int, timeout: float = 4.0,
try:
if use_tls:
ctx = ssl.create_default_context()
- ctx.check_hostname = False
- ctx.verify_mode = ssl.CERT_NONE
+ harden_ssl_context(ctx)
reader, writer = await asyncio.wait_for(
asyncio.open_connection(host, port, ssl=ctx), timeout=timeout
)
diff --git a/tests/unit/modules/test_tls_security_h15.py b/tests/unit/modules/test_tls_security_h15.py
new file mode 100644
index 0000000..26e99f1
--- /dev/null
+++ b/tests/unit/modules/test_tls_security_h15.py
@@ -0,0 +1,74 @@
+"""AUDIT run-1 H15/H16/H17: outbound TLS verification is on by default and only
+disabled behind the explicit ARES_ALLOW_INSECURE_TLS opt-in."""
+
+import ssl
+
+import pytest
+
+from ares.modules import _tls_security as tlssec
+
+
+def force_insecure(monkeypatch):
+ def _set(value: bool):
+ monkeypatch.setattr(tlssec, "insecure_tls_allowed", lambda: value)
+ return _set
+
+
+def test_ldap_tls_plaintext_returns_none(force_insecure):
+ force_insecure(False)
+ assert tlssec.ldap_tls(False) is None
+
+
+def test_ldap_tls_verifies_by_default(force_insecure):
+ pytest.importorskip("ldap3") # optional dep; not in the base test env
+ force_insecure(False)
+ tls = tlssec.ldap_tls(True)
+ assert tls is not None
+ assert tls.validate == ssl.CERT_REQUIRED
+
+
+def test_ldap_tls_insecure_only_on_opt_in(force_insecure):
+ pytest.importorskip("ldap3") # optional dep; not in the base test env
+ force_insecure(True)
+ tls = tlssec.ldap_tls(True)
+ assert tls.validate == ssl.CERT_NONE
+
+
+def test_winrm_cert_validation_default_validate(force_insecure):
+ force_insecure(False)
+ assert tlssec.winrm_cert_validation(True) == "validate"
+ force_insecure(True)
+ assert tlssec.winrm_cert_validation(True) == "ignore"
+ # plaintext transport is never "ignore"
+ assert tlssec.winrm_cert_validation(False) == "validate"
+
+
+def test_httpx_verify_default_true(force_insecure):
+ force_insecure(False)
+ assert tlssec.httpx_verify() is True
+ force_insecure(True)
+ assert tlssec.httpx_verify() is False
+
+
+def test_harden_ssl_context_defaults_to_verification(force_insecure):
+ force_insecure(False)
+ ctx = tlssec.harden_ssl_context(ssl.create_default_context())
+ assert ctx.verify_mode == ssl.CERT_REQUIRED
+ assert ctx.check_hostname is True
+
+ force_insecure(True)
+ ctx2 = tlssec.harden_ssl_context(ssl.create_default_context())
+ assert ctx2.verify_mode == ssl.CERT_NONE
+ assert ctx2.check_hostname is False
+
+
+def test_insecure_defaults_closed_on_settings_error(monkeypatch):
+ # If settings cannot be resolved, we must fail closed (verification ON).
+ import ares.core.config as cfg
+
+ def _boom():
+ raise RuntimeError("no settings")
+
+ monkeypatch.setattr(cfg, "get_settings", _boom)
+ assert tlssec.insecure_tls_allowed() is False
diff --git a/tests/unit/test_module_descriptor_readiness.py b/tests/unit/test_module_descriptor_readiness.py
index d40aa83..11e7e66 100644
--- a/tests/unit/test_module_descriptor_readiness.py
+++ b/tests/unit/test_module_descriptor_readiness.py
@@ -13504,6 +13504,7 @@ def test_independent_ast_census_matches_locked_inventory() -> None:
"ghost_forge",
"phantom_token",
"_parsers",
+ "_tls_security",
"sssd_harvest",
"ccache_hunt",
"keytab_abuse",