Exploit database

GH-f8e526d8d9e311d8f85613e761417cf0

aa022/cve-2026-23918-passive-audit

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2026-23918

11 sources

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source

Repository files11
aa022/cve-2026-23918-passive-auditRevision 5b744f588bc8

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

auditor/network.py

Python · 5,221 bytes
"""Passive network collection for the auditor."""

from __future__ import annotations

import asyncio
import socket
import ssl
import time
from typing import List, Tuple
from urllib.parse import urlparse

import httpx

from auditor.analysis import (
    analyze_cookies,
    analyze_cve_2026_23918,
    analyze_headers,
)
from auditor.models import AuditResult, Finding, Severity


async def detect_alpn(hostname: str, port: int) -> List[str]:
    """Perform a TLS handshake to discover ALPN-negotiated protocols."""
    protocols: List[str] = []
    ctx = ssl.create_default_context()
    ctx.set_alpn_protocols(["h2", "http/1.1"])

    try:
        reader, writer = await asyncio.wait_for(
            asyncio.open_connection(hostname, port, ssl=ctx),
            timeout=10.0,
        )
        ssl_obj = writer.get_extra_info("ssl_object")
        if ssl_obj is not None:
            selected = ssl_obj.selected_alpn_protocol()
            if selected:
                protocols.append(selected)
        writer.close()
        await writer.wait_closed()
    except (
        OSError,
        ssl.SSLError,
        asyncio.TimeoutError,
        socket.gaierror,
    ):
        pass

    return protocols


async def fetch_once(
    client: httpx.AsyncClient,
    url: str,
    method: str,
) -> Tuple[httpx.Response, int]:
    """Send a single HTTP request and measure latency."""
    start = time.perf_counter()

    if method == "HEAD":
        response = await client.head(url, follow_redirects=True)
    else:
        response = await client.get(url, follow_redirects=True)

    latency_ms = int((time.perf_counter() - start) * 1000)
    return response, latency_ms


async def audit_target(
    target: str,
    *,
    verify_tls: bool = True,
    timeout: float = 15.0,
    user_agent: str = "NonInvasiveAudit/1.0",
) -> AuditResult:
    """Audit a single target for HTTP/2 and security header posture."""
    url = target if target.startswith(("http://", "https://")) \
        else f"https://{target}"
    result = AuditResult(target=url, tls_verified=verify_tls)

    parsed = urlparse(url)
    hostname = parsed.hostname or ""
    port = parsed.port or (443 if parsed.scheme == "https" else 80)

    if parsed.scheme == "https" and hostname:
        result.alpn_protocols = await detect_alpn(hostname, port)

    request_headers = {
        "User-Agent": user_agent,
        "Accept": (
            "text/html,application/xhtml+xml,"
            "application/xml;q=0.9,*/*;q=0.8"
        ),
    }

    async with httpx.AsyncClient(
        http2=True,
        verify=verify_tls,
        timeout=timeout,
        headers=request_headers,
    ) as client:
        try:
            try:
                response, latency_ms = await fetch_once(
                    client, url, "HEAD"
                )
                if (
                    response.status_code in {405, 403}
                    or not response.headers
                ):
                    response, latency_ms = await fetch_once(
                        client, url, "GET"
                    )
            except httpx.HTTPError:
                response, latency_ms = await fetch_once(
                    client, url, "GET"
                )

            result.final_url = str(response.url)
            result.status_code = response.status_code
            result.http_version = response.http_version
            result.latency_ms = latency_ms
            result.server_header = response.headers.get("server")
            result.powered_by = response.headers.get("x-powered-by")

            analyze_headers(result, response.headers)
            analyze_cookies(result, response)
            analyze_cve_2026_23918(result)

        except ssl.SSLError as exc:
            result.findings.append(
                Finding(
                    severity=Severity.HIGH,
                    title="TLS verification failed",
                    evidence=str(exc),
                    recommendation=(
                        "Fix certificate chain, hostname, or expiry "
                        "before relying on scan results."
                    ),
                )
            )
        except Exception as exc:
            result.findings.append(
                Finding(
                    severity=Severity.ERROR,
                    title="Audit request failed",
                    evidence=repr(exc),
                    recommendation=(
                        "Check target reachability, DNS, firewall rules, "
                        "and TLS settings."
                    ),
                )
            )

    return result


async def audit_targets(
    targets: List[str],
    *,
    verify_tls: bool = True,
    timeout: float = 15.0,
    concurrency: int = 5,
) -> List[AuditResult]:
    """Audit multiple targets concurrently with a semaphore limit."""
    semaphore = asyncio.Semaphore(concurrency)

    async def limited(target: str) -> AuditResult:
        async with semaphore:
            return await audit_target(
                target, verify_tls=verify_tls, timeout=timeout
            )

    results: List[AuditResult] = await asyncio.gather(
        *(limited(t) for t in targets)
    )
    return results