Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /SHAdd0WTAka_Zen-Ai-Pentest /examples /port_security_demo.py
| #!/usr/bin/env python3 | |
| """ | |
| Port Security Demo for Zen-AI-Pentest | |
| ===================================== | |
| Demonstrates secure port allocation with VPN detection and MITM protection. | |
| """ | |
| import asyncio | |
| import sys | |
| from pathlib import Path | |
| sys.path.insert(0, str(Path(__file__).parent.parent)) | |
| from core.port_manager_integration import ( | |
| PentestPortAllocator, | |
| SecurePortManager, | |
| ServiceType, | |
| print_security_status, | |
| ) | |
| def demo_security_status(): | |
| """Show current security status.""" | |
| print_security_status() | |
| def demo_vpn_detection(): | |
| """Demonstrate VPN detection.""" | |
| print("\n" + "=" * 60) | |
| print("๐ VPN Detection Demo") | |
| print("=" * 60) | |
| pm = SecurePortManager() | |
| if pm.is_available: | |
| vpn_active = pm.vpn_active | |
| print(f"\nVPN Active: {'YES โ ๏ธ' if vpn_active else 'No โ '}") | |
| if pm._vpn_detector: | |
| interfaces = pm._vpn_detector.get_vpn_interfaces() | |
| if interfaces: | |
| print(f"Detected Interfaces: {', '.join(interfaces)}") | |
| else: | |
| print("\nโ LocalPortManager Secure not available") | |
| print(" Install from: https://github.com/SHAdd0WTAka/LocalportManager") | |
| def demo_service_registration(): | |
| """Demonstrate secure service registration.""" | |
| print("\n" + "=" * 60) | |
| print("๐ง Service Registration Demo") | |
| print("=" * 60) | |
| pm = SecurePortManager() | |
| if not pm.is_available: | |
| print("\nโ LocalPortManager Secure not available") | |
| return | |
| # Example 1: Native service (always safe) | |
| print("\n1. Native Python Service (always safe):") | |
| url = pm.register_tool( | |
| "api-server", | |
| "python -m http.server {port}", | |
| service_type=ServiceType.NATIVE, | |
| ) | |
| print(f" Registered: {url}") | |
| # Example 2: Docker service (blocked if VPN active) | |
| print("\n2. Docker Service (blocked if VPN active):") | |
| if pm.vpn_active: | |
| print(" โ ๏ธ VPN is active - Docker will be BLOCKED") | |
| print(" Use --no-kill-switch to bypass (DANGEROUS)") | |
| else: | |
| url = pm.register_tool("grafana", "docker run -p {port}:3000 grafana/grafana") | |
| print(f" Registered: {url}") | |
| # Example 3: Forced Docker (bypass kill switch) | |
| print("\n3. Forced Docker (bypass kill switch):") | |
| print(" โ ๏ธ This is DANGEROUS - MITM risk!") | |
| # url = pm.register_tool("risky", "docker run nginx", force_docker=True) | |
| def demo_port_allocator(): | |
| """Demonstrate intelligent port allocator.""" | |
| print("\n" + "=" * 60) | |
| print("๐ง Smart Port Allocator Demo") | |
| print("=" * 60) | |
| allocator = PentestPortAllocator() | |
| async def run(): | |
| # This automatically chooses the safest option | |
| url = await allocator.allocate( | |
| name="nmap-api", | |
| docker_cmd="docker run -p {port}:8080 zen-ai/nmap-api", | |
| native_cmd="python -m zen_ai.nmap_api --port {port}", | |
| ) | |
| print(f"\nAllocated: {url}") | |
| print(" (Automatically chose safest option based on VPN status)") | |
| asyncio.run(run()) | |
| def demo_best_practices(): | |
| """Show security best practices.""" | |
| print("\n" + "=" * 60) | |
| print("๐ Security Best Practices") | |
| print("=" * 60) | |
| print(""" | |
| 1. ๐ Always use 127.0.0.1 binding | |
| GOOD: docker run -p 127.0.0.1:8080:80 nginx | |
| BAD: docker run -p 8080:80 nginx | |
| 2. ๐ซ Never use --network host with VPN | |
| GOOD: docker run --network bridge nginx | |
| BAD: docker run --network host nginx | |
| 3. ๐ก๏ธ Use isolated networks for sensitive services | |
| docker network create --internal isolated | |
| docker run --network isolated postgres | |
| 4. โ Prefer native services when VPN is active | |
| Python/Node apps instead of Docker containers | |
| 5. ๐ Monitor security status regularly | |
| python -m core.port_manager_integration | |
| 6. ๐จ Enable kill switch in production | |
| export LPM_KILL_SWITCH=true | |
| """) | |
| def demo_architecture(): | |
| """Show secure architecture.""" | |
| print("\n" + "=" * 60) | |
| print("๐๏ธ Secure Architecture") | |
| print("=" * 60) | |
| print(""" | |
| โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
| โ ZEN-AI-PENTEST Secure Architecture โ | |
| โ โ | |
| โ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โ | |
| โ โ Scanner โ โ Analyzer โ โ Reporter โ โ | |
| โ โโโโโโโโฌโโโโโโโโ โโโโโโโโฌโโโโโโโโ โโโโโโโโฌโโโโโโโโ โ | |
| โ โ โ โ โ | |
| โ โโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโ โ | |
| โ โ โ | |
| โ โโโโโโโโโโโโโโดโโโโโโโโโโโโโ โ | |
| โ โ SecurePortManager โ โ | |
| โ โ (VPN Detection) โ โ | |
| โ โโโโโโโโโโโโโโฌโโโโโโโโโโโโโ โ | |
| โ โ โ | |
| โ โโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโ โ | |
| โ โ โ โ โ | |
| โ โผ โผ โผ โ | |
| โ โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโ โ | |
| โ โ Native โ โ Docker โ โ Docker โ โ | |
| โ โ Service โ โ (No VPN) โ โ (Isolated)โ โ | |
| โ โ :9001 โ โ :9002 โ โ :9003 โ โ | |
| โ โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโ โ | |
| โ โ | |
| โ ๐ VPN Active = Docker blocked (MITM protection) โ | |
| โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
| """) | |
| if __name__ == "__main__": | |
| print("\n" + "=" * 70) | |
| print(" ๐ ZEN-AI-PENTEST Port Security Demo") | |
| print("=" * 70) | |
| demos = [ | |
| ("Security Status", demo_security_status), | |
| ("VPN Detection", demo_vpn_detection), | |
| ("Service Registration", demo_service_registration), | |
| ("Smart Allocator", demo_port_allocator), | |
| ("Best Practices", demo_best_practices), | |
| ("Architecture", demo_architecture), | |
| ] | |
| print("\nAvailable demos:") | |
| for i, (name, _) in enumerate(demos, 1): | |
| print(f" {i}. {name}") | |
| print("\n" + "=" * 70) | |
| for name, func in demos: | |
| try: | |
| func() | |
| except Exception as e: | |
| print(f"\nโ ๏ธ {name} error: {e}") | |
| print("\n" + "=" * 70) | |
| print(" Demo complete!") | |
| print("=" * 70) | |
Xet Storage Details
- Size:
- 7.56 kB
- Xet hash:
- ef26642d8b737f2a5fdee6abb556698924e45fe5216b0d9733366698b6ea3689
ยท
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.