Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /Kolerr-Lab_supper-decoyable /support /demo.py
| #!/usr/bin/env python3 | |
| """ | |
| DECOYABLE Quick Demo Script | |
| This script demonstrates DECOYABLE's security scanning capabilities | |
| with sample vulnerable code. Run this to see DECOYABLE in action! | |
| Usage: | |
| python demo.py | |
| """ | |
| import os | |
| import tempfile | |
| from pathlib import Path | |
| # Sample vulnerable code for demonstration | |
| SAMPLE_VULNERABLE_CODE = ''' | |
| # This file contains intentional security vulnerabilities for demo purposes | |
| import os | |
| import subprocess | |
| import sqlite3 | |
| # Hardcoded secret (should be detected) | |
| API_KEY = "sk-1234567890abcdef" # API key exposed | |
| DB_PASSWORD = "admin123" # Weak password | |
| def vulnerable_function(user_input, card_number): | |
| """ | |
| Function with multiple security issues | |
| """ | |
| # Command injection vulnerability | |
| os.system(f"ls {user_input}") # Dangerous! | |
| # SQL injection vulnerability | |
| conn = sqlite3.connect('users.db') | |
| cursor = conn.cursor() | |
| query = f"SELECT * FROM users WHERE id = '{user_input}'" # SQL injection! | |
| cursor.execute(query) | |
| # Path traversal vulnerability | |
| filename = f"/tmp/{user_input}" # Could be ../../../etc/passwd | |
| with open(filename, 'w') as f: | |
| f.write(card_number) # Storing sensitive data insecurely | |
| return API_KEY | |
| # AWS credentials (should be detected) | |
| AWS_ACCESS_KEY = "AKIAIOSFODNN7EXAMPLE" | |
| AWS_SECRET_KEY = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY" | |
| # GitHub token (should be detected) | |
| GITHUB_TOKEN = "ghp_1234567890abcdef1234567890abcdef12345678" | |
| ''' | |
| def create_demo_files(): | |
| """Create sample files with vulnerabilities for scanning.""" | |
| demo_dir = Path("demo_vulnerable_code") | |
| # Create demo directory | |
| demo_dir.mkdir(exist_ok=True) | |
| # Create vulnerable Python file | |
| vuln_file = demo_dir / "vulnerable_app.py" | |
| vuln_file.write_text(SAMPLE_VULNERABLE_CODE) | |
| # Create requirements.txt with known vulnerable package | |
| req_file = demo_dir / "requirements.txt" | |
| req_file.write_text("requests==2.25.0 # Known vulnerable version\n") | |
| print(f"โ Created demo files in {demo_dir}/") | |
| return demo_dir | |
| def run_demo_scan(scan_dir): | |
| """Run DECOYABLE scan on the demo files.""" | |
| print("\n๐ Running DECOYABLE security scan...") | |
| print("=" * 50) | |
| try: | |
| # Import DECOYABLE components and setup services | |
| from decoyable.core.main import setup_services | |
| from decoyable.scanners.secrets_scanner import SecretsScanner, SecretsScannerConfig | |
| from decoyable.scanners.sast_scanner import SASTScanner, SASTScannerConfig | |
| from decoyable.scanners.deps_scanner import DependenciesScanner, DependenciesScannerConfig | |
| # Setup all services properly | |
| config, registry, cli_service = setup_services() | |
| # Initialize scanners with proper config | |
| secrets_config = SecretsScannerConfig() | |
| sast_config = SASTScannerConfig() | |
| deps_config = DependenciesScannerConfig() | |
| secrets_scanner = SecretsScanner(secrets_config) | |
| sast_scanner = SASTScanner(sast_config) | |
| deps_scanner = DependenciesScanner(deps_config) | |
| total_findings = 0 | |
| # Scan for secrets | |
| print("๐ Scanning for secrets...") | |
| import asyncio | |
| for py_file in scan_dir.glob("*.py"): | |
| try: | |
| report = asyncio.run(secrets_scanner.scan_path(str(py_file))) | |
| if report.results: | |
| print(f" ๐ {py_file.name}:") | |
| for finding in report.results: | |
| finding_display = f" ๐จ {finding.secret_type}: [REDACTED]" | |
| print(finding_display) | |
| total_findings += 1 | |
| except Exception as e: | |
| print(f" โ Error scanning {py_file.name}: {e}") | |
| # Scan for SAST vulnerabilities | |
| print("\n๐ป Scanning for code vulnerabilities...") | |
| for py_file in scan_dir.glob("*.py"): | |
| try: | |
| report = asyncio.run(sast_scanner.scan_path(str(py_file))) | |
| if report.results: | |
| print(f" ๐ {py_file.name}:") | |
| for finding in report.results: | |
| print(f" ๐จ {finding.vulnerability_type}: {finding.description}") | |
| total_findings += 1 | |
| except Exception as e: | |
| print(f" โ Error scanning {py_file.name}: {e}") | |
| # Scan dependencies | |
| print("\n๐ฆ Scanning dependencies...") | |
| req_file = scan_dir / "requirements.txt" | |
| if req_file.exists(): | |
| try: | |
| report = asyncio.run(deps_scanner.scan_path(str(req_file))) | |
| if report.results: | |
| for finding in report.results: | |
| print(f" ๐จ Vulnerable package: {finding.package} {finding.version}") | |
| print(f" ๐ก {finding.description}") | |
| total_findings += 1 | |
| except Exception as e: | |
| print(f" โ Error scanning dependencies: {e}") | |
| print("\n" + "=" * 50) | |
| print(f"๐ฏ DEMO COMPLETE: Found {total_findings} security issues!") | |
| print("\n๐ก DECOYABLE caught these before they could become real security breaches!") | |
| except ImportError as e: | |
| print(f"โ Could not import DECOYABLE: {e}") | |
| print("๐ก Make sure DECOYABLE is properly installed:") | |
| print(" pip install -e .") | |
| except Exception as e: | |
| print(f"โ Scan failed: {e}") | |
| print("๐ก This demo requires DECOYABLE to be properly set up") | |
| def cleanup_demo(scan_dir): | |
| """Clean up demo files.""" | |
| import shutil | |
| if scan_dir.exists(): | |
| shutil.rmtree(scan_dir) | |
| print(f"๐งน Cleaned up demo files from {scan_dir}/") | |
| def main(): | |
| """Run the complete demo.""" | |
| print("๐ DECOYABLE Security Scanner Demo") | |
| print("===================================") | |
| print("This demo will create sample vulnerable code and scan it with DECOYABLE") | |
| print("to show how it detects real security issues.\n") | |
| # Create demo files | |
| demo_dir = create_demo_files() | |
| try: | |
| # Run the scan | |
| run_demo_scan(demo_dir) | |
| print("\n๐ Demo completed successfully!") | |
| print("\n๐ What just happened:") | |
| print(" โข DECOYABLE scanned Python code for secrets and vulnerabilities") | |
| print(" โข It found hardcoded API keys, weak passwords, and code injection flaws") | |
| print(" โข It identified vulnerable third-party packages") | |
| print(" โข All issues were caught before deployment!") | |
| print("\n๐ Learn more:") | |
| print(" โข GitHub: https://github.com/Kolerr-Lab/supper-decoyable") | |
| print(" โข Documentation: See README.md") | |
| print(" โข Try it on your own code: decoyable scan .") | |
| finally: | |
| # Cleanup | |
| cleanup_demo(demo_dir) | |
| if __name__ == "__main__": | |
| main() |
Xet Storage Details
- Size:
- 6.89 kB
- Xet hash:
- 6a23de99f390521c24192c900998c3e7a27b90ca9aadc7afd98e4a054a18ca6d
ยท
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.