Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /SHAdd0WTAka_Zen-Ai-Pentest /examples /email_report_example.py
| #!/usr/bin/env python3 | |
| """ | |
| Example: Send Email Report After Scan | |
| ===================================== | |
| Shows how to integrate email notifications into your pentest workflow. | |
| """ | |
| import os | |
| import sys | |
| from pathlib import Path | |
| # Add parent to path | |
| sys.path.insert(0, str(Path(__file__).parent.parent)) | |
| from pathlib import Path | |
| from notifications.email_sender import EmailReporter | |
| def example_basic_usage(): | |
| """Basic email sending example""" | |
| # Configure (via environment variables or direct) | |
| os.environ["SMTP_HOST"] = "smtp.gmail.com" | |
| os.environ["SMTP_PORT"] = "587" | |
| os.environ["SMTP_USER"] = "your-email@gmail.com" | |
| os.environ["SMTP_PASS"] = "your-app-password" # Use app password for Gmail | |
| reporter = EmailReporter() | |
| # Send scan report | |
| success = reporter.send_scan_report( | |
| to_email="admin@company.com", | |
| scan_target="example.com", | |
| findings=[ | |
| { | |
| "severity": "critical", | |
| "title": "SQL Injection", | |
| "description": "SQL injection vulnerability in login form", | |
| }, | |
| { | |
| "severity": "high", | |
| "title": "XSS", | |
| "description": "Cross-site scripting in search parameter", | |
| }, | |
| ], | |
| duration=120.5, | |
| scan_id="scan-2024-001", | |
| report_path="/path/to/full_report.pdf", # Optional attachment | |
| ) | |
| print(f"Email sent: {'✅' if success else '❌'}") | |
| def example_with_orchestrator(): | |
| """Integration with pentest orchestrator""" | |
| from core.orchestrator import PentestOrchestrator | |
| from notifications.email_sender import EmailReporter | |
| # Initialize | |
| PentestOrchestrator() | |
| email_reporter = EmailReporter() | |
| # Run scan | |
| target = "example.com" | |
| print(f"Starting scan of {target}...") | |
| # Simulate scan results | |
| results = { | |
| "target": target, | |
| "findings": [ | |
| { | |
| "severity": "critical", | |
| "title": "SQL Injection", | |
| "description": "In login form", | |
| }, | |
| {"severity": "high", "title": "XSS", "description": "In search"}, | |
| ], | |
| "duration": 125.5, | |
| "scan_id": "scan-001", | |
| } | |
| # Generate report file | |
| report_path = f"/tmp/report-{results['scan_id']}.pdf" # nosec B108 | |
| # ... generate PDF report ... | |
| # Send email notification | |
| print("Sending email report...") | |
| email_reporter.send_scan_report( | |
| to_email="security@company.com", | |
| scan_target=results["target"], | |
| findings=results["findings"], | |
| duration=results["duration"], | |
| scan_id=results["scan_id"], | |
| report_path=report_path, | |
| subject=f"[SECURITY] Pentest Complete: {target} - {len(results['findings'])} issues found", | |
| ) | |
| print("Done!") | |
| def example_multiple_recipients(): | |
| """Send to multiple recipients""" | |
| reporter = EmailReporter() | |
| reporter.send_scan_report( | |
| to_email=[ | |
| "admin@company.com", | |
| "security@company.com", | |
| "cto@company.com", | |
| ], | |
| scan_target="internal-api.company.com", | |
| findings=[ | |
| { | |
| "severity": "critical", | |
| "title": "API Key Exposed", | |
| "description": "API key in GitHub", | |
| }, | |
| ], | |
| duration=300.0, | |
| scan_id="scan-002", | |
| subject="🚨 CRITICAL: Internal API Security Issues", | |
| ) | |
| def example_simple_notification(): | |
| """Send simple text notification""" | |
| reporter = EmailReporter() | |
| reporter.send_simple_notification( | |
| to_email="admin@company.com", | |
| subject="Scan Started", | |
| message="Pentest scan of example.com has started.\n\nScan ID: scan-003\nStarted: 2024-01-15 10:00 UTC\n\nYou will receive a full report upon completion.", | |
| ) | |
| def example_with_env_file(): | |
| """Load config from .env file""" | |
| # Create .env file | |
| # Load it | |
| from dotenv import load_dotenv | |
| load_dotenv() | |
| # Now EmailReporter automatically picks up the config | |
| reporter = EmailReporter() | |
| # Use it... | |
| reporter.send_scan_report( | |
| to_email="admin@company.com", | |
| scan_target="test.com", | |
| findings=[], | |
| duration=60.0, | |
| scan_id="scan-004", | |
| ) | |
| if __name__ == "__main__": | |
| print("Email Report Examples") | |
| print("=" * 50) | |
| print() | |
| print("1. Basic Usage: example_basic_usage()") | |
| print("2. With Orchestrator: example_with_orchestrator()") | |
| print("3. Multiple Recipients: example_multiple_recipients()") | |
| print("4. Simple Notification: example_simple_notification()") | |
| print("5. With .env File: example_with_env_file()") | |
| print() | |
| print("Uncomment the function you want to run") | |
| # Uncomment to run: | |
| # example_basic_usage() | |
Xet Storage Details
- Size:
- 4.81 kB
- Xet hash:
- 5ea513e9133ccd520bad0a421f6edf7576a5a50fb147bb98a86f57ec2b383d2a
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.