Metadata-Version: 2.4
Name: khopesh-sec
Version: 1.2.1
Summary: Multi-engine security & network vulnerability scanner: IPv4/IPv6 port/service CVE scanner, CISA KEV/EPSS prioritization, SAST, Secrets, SCA, CycloneDX SBOM, GitHub Actions CI/CD, Config, PCAP forensics, Endpoint EDR, and TLS/HTTP Headers.
Author-email: Andro Nagy <andronagy48@gmail.com>
License: MIT
Project-URL: Homepage, https://andro-dev.com/
Project-URL: Repository, https://github.com/andronagy48-sudo/Khopesh
Keywords: security,vulnerability-scanner,sast,sca,cve,secrets,pcap,network-security,sarif,devsecops,soc
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Information Technology
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Security
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: dev
Requires-Dist: pytest>=8.0; extra == "dev"
Requires-Dist: pytest-cov>=5.0; extra == "dev"
Requires-Dist: ruff>=0.6; extra == "dev"
Requires-Dist: mypy>=1.11; extra == "dev"
Dynamic: license-file

# Khopesh

[![CI](https://github.com/andronagy48-sudo/Khopesh/actions/workflows/ci.yml/badge.svg)](https://github.com/andronagy48-sudo/Khopesh/actions/workflows/ci.yml)
[![PyPI](https://img.shields.io/pypi/v/khopesh-sec)](https://pypi.org/project/khopesh-sec/)
[![GitHub Marketplace](https://img.shields.io/badge/Marketplace-Khopesh%20Action-22c55e)](https://github.com/marketplace/actions/khopesh-security-scanner)
[![Python](https://img.shields.io/badge/python-3.11%2B-blue)](https://www.python.org/)
[![Engines](https://img.shields.io/badge/engines-9%20NetSec%20%26%20AppSec-8b5cf6)](#nine-detection-engines)
[![SARIF](https://img.shields.io/badge/output-SARIF%202.1.0%20%7C%20CycloneDX%201.5%20%7C%20HTML-0ea5e9)](#)
[![License: MIT](https://img.shields.io/badge/license-MIT-green)](LICENSE)

**Khopesh** (`v1.2.0`) is a zero-dependency, 9-engine network, CI/CD, and application vulnerability scanner built in Python 3.11+. Point it at an **authorized IPv4/IPv6 host, CIDR subnet (up to `/16`), packet capture, web URL, or source code repository** — it discovers open ports, fingerprints services across arbitrary ports, prioritizes CVEs with **CISA KEV** and **FIRST EPSS**, audits GitHub Actions workflows, exports **CycloneDX v1.5 SBOMs**, and supports inline suppression (`# khopesh: ignore[...]`) and `--baseline` diffing for CI/CD gates.

---

## Nine Detection Engines

### Network, Infrastructure & SOC Engines
1. **Network IPv4/IPv6 Port, Service Version & Hybrid CVE Scanner (`KHOPESH-SCAN-*`):**
   - Scans authorized IPv4/IPv6 hosts, hostnames, or CIDR subnets up to `/16` (IPv4) / `/112` (IPv6) with ICMP/ARP/NDP/OUI/NetBIOS/OS discovery.
   - Performs **port-agnostic multi-stage probing** (server-first greeting + client-first HTTP/TLS fallback on arbitrary ports) and normalized version range comparison (SemVer, PEP 440, OpenSSH `p1`/`p2`, OpenSSL letter suffixes, `last_affected`, and `introduced_exclusive`).
   - **Hybrid Vulnerability & Threat Intelligence (`cve_intel.py`, `intel_updater.py`, `threat_intel.py`):** Loads schema v2 databases refreshed from **NIST NVD CVE API 2.0**, **OSV.dev**, **CISA KEV**, and **FIRST EPSS** via `khopesh update-db` (and weekly GitHub Actions), supplemented online by live NVD CPE 2.3 and FIRST EPSS lookups with 24h local caching.
2. **PCAP Network Traffic Forensics Engine (`KHOPESH-NET-*`):**
   - Pure-Python binary `libpcap` (`.pcap` / `.cap`) parser detecting **TCP SYN port scan sweeps** (`CWE-200`), **cleartext FTP/HTTP Basic credentials** (`CWE-319`, redacted), and **SMBv1 negotiations** (`CVE-2017-0144`).
3. **Endpoint Socket, Process, Firewall & Reverse-Shell SOC Auditor (`KHOPESH-HOST-*`):**
   - White-box host endpoint auditor (`audit-host`) correlating active sockets with **Process Names & PIDs**, checking **Windows Firewall / UFW** state, flagging exposed admin/DB listeners, and detecting **Bind/Reverse Shells & C2 ports** (MITRE ATT&CK `T1059` / `T1571`).
4. **Passive TLS & HTTP Security Headers Auditor (`KHOPESH-WEB-*`):**
   - Single passive TLS & HTTP compliance check verifying TLS version, HSTS, CSP, clickjacking headers, `nosniff`, version banner disclosure, and `Set-Cookie` flags.

### Application, Supply-Chain & CI/CD Engines
5. **SAST Engine (`KHOPESH-SAST-*`):**
   - Python AST with intraprocedural variable & taint tracking (`CWE-89`, `CWE-78`, `CWE-95`, `CWE-502`, context-aware `CWE-327`, `CWE-295`, `CWE-377`, `CWE-489`) plus a JavaScript/TypeScript lexical comment & static-literal stripper (`CWE-79`, `CWE-95`, `CWE-78`).
6. **Secret & Shannon Entropy Engine (`KHOPESH-SEC-*`):**
   - Signature + Shannon entropy detection (`CWE-798`) with automatic snippet redaction.
7. **Dependency CVE / SCA Engine & CycloneDX v1.5 SBOM (`KHOPESH-SCA-*`):**
   - Parses manifests and lockfiles (`requirements.txt`, `pyproject.toml`, `poetry.lock`, `uv.lock`, `Pipfile.lock`, `package.json`, `package-lock.json`, `yarn.lock`, `pnpm-lock.yaml`), queries OSV.dev with CVSS/severity extraction, enriches CVEs with CISA KEV & FIRST EPSS, and exports **CycloneDX v1.5 JSON SBOMs** (`khopesh sbom` or `--sbom`).
8. **Container & Config Hardening Engine (`KHOPESH-CFG-*`):**
   - Audits `Dockerfile`, `docker-compose.yml`, and web configs (`next.config.js`, `nginx.conf`, `vercel.json`, `netlify.toml`).
9. **GitHub Actions CI/CD Supply-Chain Engine (`KHOPESH-GHA-*`):**
   - Audits `.github/workflows/*.yml` and `action.yml` for dangerous `pull_request_target` / `workflow_run` head checkouts (`KHOPESH-GHA-001`), script injection via untrusted `${{ github.event.* }}` contexts (`KHOPESH-GHA-002`), unpinned actions/reusable workflows/Docker tags (`KHOPESH-GHA-003`), missing or `write-all` permissions (`KHOPESH-GHA-004`), `ACTIONS_ALLOW_UNSECURE_COMMANDS` (`KHOPESH-GHA-005`), `secrets: inherit` (`KHOPESH-GHA-006`), persisted checkout credentials (`KHOPESH-GHA-007`), and `self-hosted` runners exposed to PRs (`KHOPESH-GHA-008`).

---

## Benchmarks (Honest Measurement)

Full methodology, corpus fixtures, known biases, and miss/FP breakdowns are published in [`benchmark/README.md`](benchmark/README.md) and run weekly in [`.github/workflows/benchmark.yml`](.github/workflows/benchmark.yml).

### SAST Corpus Results (61 Labeled Files: 48 Python, 13 JS/TS)

| Tool | Scope | Files | TP | FP | FN | Precision | Recall | F1 |
| --- | --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: |
| **Khopesh v1.2.0** | All (Python + JS/TS) | 61 | 31 | 3 | 7 | **91.2%** | **81.6%** | **86.1%** |
| **Khopesh v1.2.0** | Python only | 48 | 24 | 2 | 7 | **92.3%** | **77.4%** | **84.2%** |
| Bandit 1.9.4 | Python only | 48 | 26 | 17 | 5 | 60.5% | 83.9% | 70.3% |

*Known gaps measured by the hard test cases (documented transparently):* interprocedural taint across helper returns, dict/list subscript taint, aliased imports (`from os import system as s`), insecure `random` token detection, and sanitizer recognition (`shlex.quote`, `DOMPurify.sanitize`).

---

## Quick Start

### Installation

```bash
pip install khopesh-sec
```

Or install from source for development:

```bash
git clone https://github.com/andronagy48-sudo/Khopesh.git
cd Khopesh
pip install -e ".[dev]"
```

### Usage Examples

```bash
# 1. Refresh authoritative CVE, CISA KEV, and FIRST EPSS databases locally
khopesh update-db
khopesh db-info

# 2. Scan an IPv4/IPv6 host or CIDR subnet (up to /16) for open ports, versions, KEV/EPSS CVEs
khopesh netscan 192.168.1.10 --html net_report.html
khopesh netscan 2001:db8::1 --ports 22,80,443,8080

# 3. Scan a repository (SAST + Secrets + SCA + Config + GitHub Actions CI/CD + PCAP)
#    with inline `# khopesh: ignore[RULE-ID]`, `.khopeshignore`, `--baseline`, SARIF, and CycloneDX SBOM
khopesh scan ./my-app --sarif results.sarif --sbom bom.cdx.json --fail-on high
khopesh scan ./my-app --baseline previous.json --exclude "vendor/**" --fail-on medium

# 4. Export a standalone CycloneDX v1.5 JSON SBOM
khopesh sbom ./my-app -o bom.cdx.json

# 5. Audit local endpoint sockets, PIDs, firewall state, and C2/reverse-shell indicators
khopesh audit-host --html host_edr.html

# 6. Analyze a packet capture (.pcap) or passively audit a URL's TLS & HTTP headers
khopesh pcap ./traffic.pcap --html pcap_report.html
khopesh headers https://andro-dev.com --html web_headers.html
```

### Use as a GitHub Action

```yaml
- name: Run Khopesh
  uses: andronagy48-sudo/Khopesh@main
  with:
    path: "."
    fail-on: "high"
    sarif-file: "khopesh.sarif"
    sbom-file: "bom.cdx.json"
```

---

## Quality Gates (Lint, Strict Typecheck & Coverage)

```bash
ruff check khopesh tests benchmark
mypy khopesh
pytest -v --cov=khopesh --cov-report=term-missing --cov-fail-under=80
```

---

## Responsible Use

Khopesh is an **authorized vulnerability assessment, hardening, and SOC analysis framework**. Only run `netscan` / `headers` against hosts, lab environments, and networks that you own or have explicit permission to assess.

---

## Author

**Andro Nagy** — Aspiring SOC Analyst & Cybersecurity Student  
Portfolio: [https://andro-dev.com/](https://andro-dev.com/) · LinkedIn: [Andro Nagy](https://www.linkedin.com/in/andro-nagy-a302b8334) · TryHackMe: [Andro48](https://tryhackme.com/p/Andro48)
