Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /SHAdd0WTAka_Zen-Ai-Pentest /tests /integration /test_real_targets.py
| """ | |
| Integration Tests against Real Vulnerable Targets | |
| ================================================= | |
| Tests run against legitimate test targets (DVWA, Juice Shop, etc.) | |
| These are intentionally vulnerable applications for security training. | |
| Prerequisites: | |
| docker-compose -f docker-compose.test.yml up -d | |
| Author: SHAdd0WTAka + Moonshot AI | |
| """ | |
| import socket | |
| import subprocess | |
| import time | |
| from typing import Any, Dict | |
| import pytest | |
| # ============================================================================= | |
| # Test Configuration | |
| # ============================================================================= | |
| TEST_TARGETS = { | |
| "dvwa": { | |
| "host": "localhost", | |
| "port": 8080, | |
| "url": "http://localhost:8080", | |
| }, | |
| "juice_shop": { | |
| "host": "localhost", | |
| "port": 3000, | |
| "url": "http://localhost:3000", | |
| }, | |
| "bwapp": { | |
| "host": "localhost", | |
| "port": 8081, | |
| "url": "http://localhost:8081", | |
| }, | |
| "mutillidae": { | |
| "host": "localhost", | |
| "port": 8082, | |
| "url": "http://localhost:8082", | |
| }, | |
| "webgoat": { | |
| "host": "localhost", | |
| "port": 8083, | |
| "url": "http://localhost:8083", | |
| }, | |
| "metasploitable": {"host": "localhost", "port": 2222}, # SSH port | |
| } | |
| # ============================================================================= | |
| # Helper Functions | |
| # ============================================================================= | |
| def wait_for_target(host: str, port: int, timeout: int = 60) -> bool: | |
| """Wait for target to be available""" | |
| start_time = time.time() | |
| while time.time() - start_time < timeout: | |
| try: | |
| with socket.create_connection((host, port), timeout=2): | |
| return True | |
| except (socket.timeout, ConnectionRefusedError): | |
| time.sleep(1) | |
| return False | |
| def target_available(target_name: str) -> bool: | |
| """Check if test target is available""" | |
| target = TEST_TARGETS.get(target_name) | |
| if not target: | |
| return False | |
| return wait_for_target(target["host"], target["port"], timeout=5) | |
| # ============================================================================= | |
| # Network Scanning Tests | |
| # ============================================================================= | |
| def test_nmap_scan_dvwa(): | |
| """Test Nmap scan against DVWA container""" | |
| from tools import TOOL_REGISTRY | |
| nmap_scan = TOOL_REGISTRY.get("nmap_scan") | |
| assert nmap_scan is not None, "nmap_scan not in registry" | |
| # Tools are LangChain StructuredTool objects - use .invoke() or .func | |
| if hasattr(nmap_scan, "func"): | |
| result = nmap_scan.func("localhost", ports="8080", service_detection=True) | |
| else: | |
| result = nmap_scan("localhost", ports="8080", service_detection=True) | |
| assert result is not None | |
| assert "localhost" in str(result) or "8080" in str(result) or "open" in str(result).lower() | |
| print("✅ Nmap found DVWA on port 8080") | |
| def test_nmap_scan_metasploitable(): | |
| """Test Nmap against Metasploitable2 with multiple services""" | |
| from tools import TOOL_REGISTRY | |
| nmap_scan = TOOL_REGISTRY.get("nmap_scan") | |
| result = nmap_scan("localhost", ports="22,23,25,445", arguments="-sS") | |
| assert result["success"] is True | |
| # Should find at least one open port | |
| print(f"✅ Nmap found Metasploitable services: {result}") | |
| # ============================================================================= | |
| # Web Application Tests | |
| # ============================================================================= | |
| def test_nikto_scan_dvwa(): | |
| """Test Nikto scan against DVWA""" | |
| from tools import TOOL_REGISTRY | |
| nikto_scan = TOOL_REGISTRY.get("nikto_scan") | |
| if nikto_scan is None: | |
| pytest.skip("nikto_scan not available") | |
| # LangChain Tool - use .func | |
| if hasattr(nikto_scan, "func"): | |
| result = nikto_scan.func("http://localhost:8080") | |
| else: | |
| result = nikto_scan("http://localhost:8080") | |
| assert result is not None | |
| # Result is NiktoResult object, not dict | |
| summary = getattr(result, "summary", str(result)[:50]) | |
| print(f"✅ Nikto scanned DVWA: {summary}") | |
| def test_ffuf_fuzz_juice_shop(): | |
| """Test FFuF fuzzing against Juice Shop""" | |
| from tools import TOOL_REGISTRY | |
| ffuf_fuzz = TOOL_REGISTRY.get("ffuf_fuzz") | |
| if ffuf_fuzz is None: | |
| pytest.skip("ffuf_fuzz not available") | |
| # LangChain Tool - use .func with correct parameters | |
| if hasattr(ffuf_fuzz, "func"): | |
| result = ffuf_fuzz.func( | |
| url="http://localhost:3000/FUZZ", | |
| wordlist="/usr/share/wordlists/dirb/common.txt", | |
| ) | |
| else: | |
| result = ffuf_fuzz( | |
| url="http://localhost:3000/FUZZ", | |
| wordlist="/usr/share/wordlists/dirb/common.txt", | |
| ) | |
| assert result is not None | |
| print("✅ FFuF found endpoints on Juice Shop") | |
| def test_sqlmap_dvwa_sqli(): | |
| """Test SQLMap against DVWA SQL Injection vulnerability""" | |
| from tools import TOOL_REGISTRY | |
| sqlmap_scan = TOOL_REGISTRY.get("sqlmap_scan") | |
| if sqlmap_scan is None: | |
| pytest.skip("sqlmap_scan not available") | |
| # LangChain Tool - use .func | |
| # Note: sqlmap_scan takes 'url' parameter, not 'target' | |
| target_url = "http://localhost:8080/vulnerabilities/sqli/?id=1&Submit=Submit" | |
| if hasattr(sqlmap_scan, "func"): | |
| result = sqlmap_scan.func(url=target_url, level=1, risk=1) | |
| else: | |
| result = sqlmap_scan(url=target_url, level=1, risk=1) | |
| assert result is not None | |
| print("✅ SQLMap tested against DVWA") | |
| def test_gobuster_bwapp(): | |
| """Test Gobuster directory scan against bWAPP""" | |
| from tools import TOOL_REGISTRY | |
| gobuster_dir_scan = TOOL_REGISTRY.get("gobuster_dir_scan") | |
| if gobuster_dir_scan is None: | |
| pytest.skip("gobuster_dir_scan not available") | |
| result = gobuster_dir_scan( | |
| target="http://localhost:8081", | |
| wordlist="/usr/share/wordlists/dirb/common.txt", | |
| extensions="php,txt,html", | |
| ) | |
| assert result is not None | |
| print("✅ Gobuster found directories on bWAPP") | |
| # ============================================================================= | |
| # Reconnaissance Tests | |
| # ============================================================================= | |
| def test_whatweb_juice_shop(): | |
| """Test WhatWeb technology detection on Juice Shop""" | |
| from tools import TOOL_REGISTRY | |
| whatweb_scan = TOOL_REGISTRY.get("whatweb_scan") | |
| if whatweb_scan is None: | |
| pytest.skip("whatweb_scan not available") | |
| # LangChain Tool - use .func | |
| if hasattr(whatweb_scan, "func"): | |
| result = whatweb_scan.func("http://localhost:3000") | |
| else: | |
| result = whatweb_scan("http://localhost:3000") | |
| assert result is not None | |
| # Result is WhatWebResult object | |
| techs = getattr(result, "technologies", []) | |
| print(f"✅ WhatWeb detected technologies: {techs}") | |
| def test_wafw00f_dvwa(): | |
| """Test WAF detection on DVWA""" | |
| from tools import TOOL_REGISTRY | |
| wafw00f_detect = TOOL_REGISTRY.get("wafw00f_detect") | |
| if wafw00f_detect is None: | |
| pytest.skip("wafw00f_detect not available") | |
| # LangChain Tool - use .func | |
| if hasattr(wafw00f_detect, "func"): | |
| result = wafw00f_detect.func("http://localhost:8080") | |
| else: | |
| result = wafw00f_detect("http://localhost:8080") | |
| assert result is not None | |
| # Result is WAFW00FResult object | |
| waf = getattr(result, "waf", "No WAF") | |
| print(f"✅ WAFW00F detection: {waf}") | |
| # ============================================================================= | |
| # Vulnerability Scanner Tests | |
| # ============================================================================= | |
| def test_nuclei_juice_shop(): | |
| """Test Nuclei against Juice Shop""" | |
| from tools import TOOL_REGISTRY | |
| nuclei_scan = TOOL_REGISTRY.get("nuclei_scan") | |
| if nuclei_scan is None: | |
| pytest.skip("nuclei_scan not available") | |
| result = nuclei_scan(target="http://localhost:3000", templates="cves", timeout=60) | |
| assert result is not None | |
| print("✅ Nuclei scan completed on Juice Shop") | |
| # ============================================================================= | |
| # Subdomain Enumeration Tests | |
| # ============================================================================= | |
| def test_subfinder_localhost(): | |
| """Test Subfinder (passive test on localhost)""" | |
| from tools import TOOL_REGISTRY | |
| subfinder_scan = TOOL_REGISTRY.get("subfinder_scan") | |
| if subfinder_scan is None: | |
| pytest.skip("subfinder_scan not available") | |
| # This won't find much on localhost, but tests the integration | |
| result = subfinder_scan("localhost") | |
| assert result is not None | |
| print("✅ Subfinder integration works") | |
| # ============================================================================= | |
| # Meta Test | |
| # ============================================================================= | |
| def test_all_targets_available(): | |
| """Check which test targets are available""" | |
| available = [] | |
| unavailable = [] | |
| for name, config in TEST_TARGETS.items(): | |
| if target_available(name): | |
| available.append(name) | |
| else: | |
| unavailable.append(name) | |
| print(f"\n{'=' * 60}") | |
| print(f"Available targets: {available}") | |
| print(f"Unavailable targets: {unavailable}") | |
| print(f"{'=' * 60}\n") | |
| # Don't fail if some targets are missing - tests will skip | |
| assert len(available) > 0, "No test targets available! Run: docker-compose -f docker-compose.test.yml up -d" | |
| if __name__ == "__main__": | |
| print("Real Target Integration Tests") | |
| print("=" * 60) | |
| print("\nPrerequisites:") | |
| print(" docker-compose -f docker-compose.test.yml up -d") | |
| print("\nRun tests with:") | |
| print(" pytest tests/integration/test_real_targets.py -v") | |
| print("=" * 60) | |
Xet Storage Details
- Size:
- 10.9 kB
- Xet hash:
- 2854e9dc20b90fa1375c6d237c38e773e84d75bf4b9531f5a07d752dc1f294fb
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.