Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /SHAdd0WTAka_Zen-Ai-Pentest /scripts /security_scan.py
| #!/usr/bin/env python3 | |
| """ | |
| Comprehensive Security Scanner for Zen-AI-Pentest | |
| Scans all requirements files and reports vulnerabilities | |
| """ | |
| import json | |
| import subprocess | |
| import sys | |
| from pathlib import Path | |
| from typing import Dict, List | |
| def run_pip_audit(requirements_file: Path) -> List[Dict]: | |
| """Run pip-audit on a requirements file""" | |
| try: | |
| result = subprocess.run( | |
| [ | |
| "pip-audit", | |
| "-r", | |
| str(requirements_file), | |
| "--format=json", | |
| "--desc", | |
| ], | |
| capture_output=True, | |
| text=True, | |
| timeout=120, | |
| ) | |
| if result.returncode == 0: | |
| return json.loads(result.stdout).get("dependencies", []) | |
| return [] | |
| except Exception as e: | |
| print(f"โ ๏ธ pip-audit failed for {requirements_file}: {e}") | |
| return [] | |
| def scan_all_requirements(): | |
| """Scan all requirements files in the project""" | |
| root = Path("/home/atakan/Schreibtisch/Zen-Ai-Pentest") | |
| # Find all requirements files | |
| req_files = list(root.rglob("requirements*.txt")) | |
| req_files = [f for f in req_files if "node_modules" not in str(f)] | |
| print("=" * 70) | |
| print("๐ ZEN-AI-PENTEST SECURITY SCAN") | |
| print("=" * 70) | |
| print() | |
| all_vulns = [] | |
| for req_file in sorted(req_files): | |
| print(f"๐ Scanning: {req_file.relative_to(root)}") | |
| vulns = run_pip_audit(req_file) | |
| file_vulns = [] | |
| for dep in vulns: | |
| if dep.get("vulns"): | |
| for v in dep["vulns"]: | |
| file_vulns.append( | |
| { | |
| "file": req_file.relative_to(root), | |
| "package": dep["name"], | |
| "version": dep["version"], | |
| "vuln_id": v.get("id", "UNKNOWN"), | |
| "description": v.get("description", "")[:80], | |
| "fix_versions": v.get("fix_versions", []), | |
| } | |
| ) | |
| if file_vulns: | |
| print(f" โ ๏ธ {len(file_vulns)} vulnerabilities found") | |
| all_vulns.extend(file_vulns) | |
| else: | |
| print(" โ No vulnerabilities") | |
| print() | |
| # Summary | |
| print("=" * 70) | |
| print("๐ SUMMARY") | |
| print("=" * 70) | |
| if all_vulns: | |
| print(f"\n๐ด Total vulnerabilities found: {len(all_vulns)}\n") | |
| # Group by severity | |
| critical_high = [v for v in all_vulns if any(x in v["vuln_id"].upper() for x in ["CRITICAL", "CVE-2024", "CVE-2025"])] | |
| others = [v for v in all_vulns if v not in critical_high] | |
| if critical_high: | |
| print("๐จ CRITICAL/HIGH Priority:") | |
| for v in critical_high[:10]: | |
| fix = v["fix_versions"][0] if v["fix_versions"] else "N/A" | |
| print(f" โข {v['package']}=={v['version']} in {v['file']}") | |
| print(f" {v['vuln_id']} โ Upgrade to {fix}") | |
| print() | |
| if others: | |
| print("โ ๏ธ Other vulnerabilities:") | |
| for v in others[:5]: | |
| fix = v["fix_versions"][0] if v["fix_versions"] else "N/A" | |
| print(f" โข {v['package']} ({v['vuln_id']}) โ {fix}") | |
| else: | |
| print("\nโ No vulnerabilities found in any requirements file!\n") | |
| return len(all_vulns) | |
| if __name__ == "__main__": | |
| count = scan_all_requirements() | |
| sys.exit(0 if count == 0 else 1) | |
Xet Storage Details
- Size:
- 3.51 kB
- Xet hash:
- 9c9c6882e74bd0b60b49c8614190359fe5fc557ad9b7fc34bae04078a5102216
ยท
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.