```python from flask import Flask, request, jsonify, send_file from flask_cors import CORS import subprocess import json import os import tempfile from datetime import datetime import requests import threading import time from werkzeug.utils import secure_filename app = Flask(__name__) CORS(app) # Configuration UPLOAD_FOLDER = 'uploads' RESULTS_FOLDER = 'results' ALLOWED_EXTENSIONS = {'txt', 'csv', 'json'} app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER app.config['RESULTS_FOLDER'] = RESULTS_FOLDER # Ensure directories exist os.makedirs(UPLOAD_FOLDER, exist_ok=True) os.makedirs(RESULTS_FOLDER, exist_ok=True) # In-memory storage for active investigations and results active_investigations = {} search_results = {} def allowed_file(filename): return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS @app.route('/api/sherlock/search', methods=['POST']) def sherlock_search(): """Search for username across social networks""" data = request.json username = data.get('username') investigation_id = data.get('investigation_id') if not username: return jsonify({'error': 'Username is required'}), 400 try: # Simulate Sherlock search (in production, this would call the actual Sherlock tool) # This is a mock implementation - replace with actual Sherlock integration results = { 'username': username, 'timestamp': datetime.now().isoformat(), 'results': { 'twitter': { 'found': True, 'url': f'https://twitter.com/{username}', 'profile_info': '12 public posts, 142 followers' }, 'github': { 'found': True, 'url': f'https://github.com/{username}', 'profile_info': '7 public repositories' }, 'instagram': { 'found': True, 'url': f'https://instagram.com/{username}', 'profile_info': 'Private account' }, 'facebook': { 'found': False, 'url': None }, 'linkedin': { 'found': False, 'url': None }, 'reddit': { 'found': True, 'url': f'https://reddit.com/user/{username}', 'profile_info': 'Account created 3 years ago, 5.2k karma' } } } # Store results search_id = f"sherlock_{username}_{int(time.time())}" search_results[search_id] = results return jsonify({ 'search_id': search_id, 'results': results }) except Exception as e: return jsonify({'error': str(e)}), 500 @app.route('/api/shodan/search', methods=['POST']) def shodan_search(): """Search for devices using Shodan""" data = request.json query = data.get('query') if not query: return jsonify({'error': 'Search query is required'}), 400 try: # Mock Shodan results results = { 'query': query, 'timestamp': datetime.now().isoformat(), 'results': [ { 'ip': '192.168.1.1', 'port': 80, 'service': 'HTTP', 'organization': 'Example Corp', 'hostnames': ['example.com'], 'location': 'New York, US', 'os': 'Linux', 'vulnerabilities': ['CVE-2021-1234'] } ] } search_id = f"shodan_{query}_{int(time.time())}" search_results[search_id] = results return jsonify({ 'search_id': search_id, 'results': results }) except Exception as e: return jsonify({'error': str(e)}), 500 @app.route('/api/maltego/transform', methods=['POST']) def maltego_transform(): """Execute Maltego transform""" data = request.json transform = data.get('transform') value = data.get('value') return jsonify({ 'transform': transform, 'input': value, 'results': [ { 'type': 'Domain', 'value': 'example.com', 'properties': { 'registrar': 'Example Registrar', 'creation_date': '2022-01-01' } ] }) @app.route('/api/recon-ng/search', methods=['POST']) def recon_ng_search(): """Execute Recon-ng module""" data = request.json module = data.get('module') target = data.get('target') try: # Mock Recon-ng results results = { 'target': target, 'module': module, 'results': [ { 'type': 'Email', 'value': 'contact@example.com' } ] } return jsonify({ 'module': module, 'target': target, 'data': [ {'type': 'email', 'value': 'admin@example.com'}, {'type': 'phone', 'value': '+1-555-0123' } ] }) @app.route('/api/investigations', methods=['GET']) def get_investigations(): """Get all investigations""" return jsonify({ 'investigations': [ { 'id': 'INV-2023-156', 'client': 'Acme Corp', 'subject': 'Executive Threat Assessment', 'status': 'active', 'created': '2023-10-15', 'last_updated': '2023-10-15T14:30:00', 'type': 'Security Audit' }, { 'id': 'INV-2023-155', 'client': 'Global Tech', 'subject': 'Executive Protection', 'status': 'pending', 'created': '2023-10-14', 'type': 'Threat Assessment' } ] }) @app.route('/api/investigations', methods=['POST']) def create_investigation(): """Create new investigation""" data = request.json investigation_id = f"INV-2023-{len(active_investigations) + 1}', 'client': data.get('client'), 'subject': data.get('subject'), 'status': 'active', 'created': datetime.now().isoformat() active_investigations[investigation_id] = { 'id': investigation_id, 'client': data.get('client'), 'subject': data.get('subject'), 'type': data.get('type'), 'description': data.get('description') } return jsonify({ 'investigation': active_investigations[investigation_id] }) except Exception as e: return jsonify({'error': str(e)}), 500 @app.route('/api/reports/generate', methods=['POST']) def generate_report(): """Generate PDF report""" data = request.json try: # Mock PDF generation report_data = { 'title': data.get('title'), 'client': data.get('client'), 'case': data.get('case'), 'findings': data.get('findings'), 'generated_at': datetime.now().isoformat() } # In production, generate actual PDF using reportlab or similar # For now, return success return jsonify({ 'report_id': f"REP-{int(time.time())}", 'download_url': f'/api/reports/download/{int(time.time())}" }) except Exception as e: return jsonify({'error': str(e)}), 500 @app.route('/api/reports/download/', methods=['GET']) def download_report(report_id): """Download generated report""" # Mock file download return jsonify({ 'message': 'Report generated successfully', 'report_id': report_id }) @app.route('/api/clients', methods=['GET']) def get_clients(): """Get all clients""" return jsonify({ 'clients': [ { 'id': 'CLI-001', 'name': 'Acme Corp', 'email': 'security@acmecorp.com', 'phone': '+1-555-0101', 'company': 'Acme Corporation', 'notes': 'High priority client' }, { 'id': 'CLI-002', 'name': 'Global Tech', 'email': 'infosec@globaltech.com' } ] }) @app.route('/api/clients', methods=['POST']) def create_client(): """Create new client""" data = request.json client_id = f"CLI-{len(active_investigations) + 1}', 'name': data.get('name'), 'email': data.get('email'), 'phone': data.get('phone'), 'company': data.get('company'), 'notes': data.get('notes') return jsonify({ 'client_id': client_id, 'message': 'Client created successfully' }) @app.route('/api/auth/login', methods=['POST']) def login(): """User authentication""" data = request.json # Mock authentication if data.get('username') == 'investigator' and data.get('password') == 'password': return jsonify({ 'token': 'mock_jwt_token_here', 'user': { 'id': 1, 'username': 'investigator', 'role': 'admin' } }) else: return jsonify({'error': 'Invalid credentials'}), 401 @app.route('/api/health', methods=['GET']) def health_check(): """Health check endpoint""" return jsonify({ 'status': 'healthy', 'timestamp': datetime.now().isoformat() }) if __name__ == '__main__': app.run(debug=True, port=5000) ```