Buckets:

download
raw
6.89 kB
#!/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.