Exploit database

GH-49a09ef0a3f480a3671ed1d028426ba0

uxokpro1234/java4shell-cve-2026-114938-defender

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2026-114938

42 sources

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

Repository files7

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

scripts/ci_gate.py

Python · 4,607 bytes
#!/usr/bin/env python3
"""
ci_gate.py — Java4Shell (CVE-2026-114938) CI/CD security gate

Intended to run as a pipeline step (GitHub Actions, GitLab CI, Jenkins,
etc.) against the build/runtime agent, a test container, or a deploy
target you can reach with `java -version` and `ps`. It reuses
scan_environment.py's logic, then applies a pass/fail policy on top so the
pipeline can block a release on unmitigated exposure.

This is a policy wrapper, not a new detector — see scan_environment.py and
lib/ for the actual checks. No decoding, no network access, no mutation of
the environment it scans.

Exit codes:
    0 = gate passed
    1 = gate failed — blocking issue found
    2 = gate inconclusive — see --fail-on to decide whether that should also
        block your pipeline

Usage:
    python3 ci_gate.py
    python3 ci_gate.py --fail-on affected,unknown --format json --output report.json
    python3 ci_gate.py --annotate github
"""

from __future__ import annotations

import argparse
import json
import os
import sys

sys.path.insert(0, os.path.join(os.path.dirname(__file__), "lib"))

from scan_environment import build_report, render_text  # noqa: E402


def emit_github_annotations(report: dict) -> None:
    """Emits GitHub Actions workflow-command annotations so blocking issues
    show up directly on the PR/run, not just buried in logs."""
    for inst in report["installations"]:
        if inst["verdict"] == "affected":
            print(
                f"::error file={inst['path']}::Java4Shell (CVE-2026-114938): "
                f"{inst['version_string']} on vulnerable hardware, no mitigation detected."
            )
        elif inst["verdict"] == "unknown":
            print(
                f"::warning file={inst['path']}::Java4Shell (CVE-2026-114938): "
                f"could not fully determine exposure for {inst['version_string']}."
            )
    for proc in report["running_processes"]:
        if not proc["mitigation_flag_present"] and report["cpu_vulnerable_path_status"] == "vulnerable":
            print(
                f"::warning::Running java process pid {proc['pid']} has no "
                "Java4Shell mitigation flag in its command line."
            )


def decide_exit_code(report: dict, fail_on: set[str]) -> int:
    verdict = report["summary"]["overall_verdict"]  # affected | unknown | not_affected
    if verdict == "affected" and "affected" in fail_on:
        return 1
    if verdict == "unknown" and "unknown" in fail_on:
        return 2
    return 0


def main() -> int:
    parser = argparse.ArgumentParser(description="Java4Shell CI/CD security gate.")
    parser.add_argument(
        "--fail-on",
        default="affected",
        help=(
            "Comma-separated set of verdicts that should fail the build: "
            "any combination of 'affected', 'unknown'. Default: 'affected'. "
            "Pass 'none' to always exit 0 (report-only mode)."
        ),
    )
    parser.add_argument("--format", choices=["text", "json"], default="text")
    parser.add_argument("--output", help="Write the report to this file.")
    parser.add_argument(
        "--annotate",
        choices=["none", "github"],
        default="none",
        help="Emit CI-native inline annotations in addition to the normal report.",
    )
    args = parser.parse_args()

    fail_on = set() if args.fail_on.strip().lower() == "none" else {
        s.strip().lower() for s in args.fail_on.split(",") if s.strip()
    }
    unknown_fail_on = fail_on - {"affected", "unknown"}
    if unknown_fail_on:
        parser.error(f"--fail-on accepts 'affected'/'unknown'/'none', got: {unknown_fail_on}")

    report = build_report()
    report["gate_policy"] = {"fail_on": sorted(fail_on)}

    rendered = json.dumps(report, indent=2) if args.format == "json" else render_text(report)
    print(rendered)

    if args.output:
        with open(args.output, "w") as f:
            f.write(rendered + "\n")

    if args.annotate == "github":
        emit_github_annotations(report)

    exit_code = decide_exit_code(report, fail_on)

    print("-" * 55)
    if exit_code == 0:
        print("GATE: PASS")
    elif exit_code == 1:
        print("GATE: FAIL — affected installation(s) with no mitigation detected.")
        print("  See mitigate.py for the recommended JVM flags, or patch the JDK.")
    else:
        print("GATE: INCONCLUSIVE — treated as failing per --fail-on policy.")
        print("  Investigate manually; CPU flags or JDK version could not be confirmed.")

    return exit_code


if __name__ == "__main__":
    sys.exit(main())