Exploit database

GH-035a689a06a33d3df19f9b8ad1617c58

aasteriskz7/host-data-summarization-tool

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2021-44228

465 sources

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source

Repository files6

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

backend/app.py

Python · 4,026 bytes
import os
from datetime import datetime
from flask import Flask, jsonify, request
from flask_cors import CORS
from dotenv import load_dotenv
from data_manager import DataManager
from ai_summarizer import AISummarizer

# Load environment variables from .env file
load_dotenv()

app = Flask(__name__)
CORS(app)

# Environment variable handling
GEMINI_API_KEY = os.getenv('GEMINI_API_KEY')

if not GEMINI_API_KEY:
    print("Warning: GEMINI_API_KEY environment variable not set")

# Initialize DataManager
data_manager = DataManager()

# Initialize AISummarizer (will be None if no API key)
ai_summarizer = None
if GEMINI_API_KEY:
    try:
        ai_summarizer = AISummarizer(api_key=GEMINI_API_KEY)
        print("AI Summarizer initialized successfully")
    except Exception as e:
        print(f"Failed to initialize AI Summarizer: {str(e)}")
        ai_summarizer = None

@app.route('/')
def health_check():
    return jsonify({
        'status': 'running',
        'message': 'Censys Host Summarizer API',
        'api_key_configured': bool(GEMINI_API_KEY)
    })

@app.route('/api/hosts')
def get_hosts():
    """Get list of all available IP addresses"""
    try:
        ips = data_manager.get_all_ips()
        return jsonify({'ips': ips})
    except Exception as e:
        return jsonify({
            'error': True,
            'message': f'Failed to load host data: {str(e)}',
            'code': 'DATA_LOAD_ERROR'
        }), 500

@app.route('/api/host/<ip>')
def get_host(ip):
    """Get raw host data for specific IP address"""
    try:
        host_data = data_manager.get_host_by_ip(ip)
        if host_data is None:
            return jsonify({
                'error': True,
                'message': f'Host not found for IP address: {ip}',
                'code': 'HOST_NOT_FOUND'
            }), 404
        
        return jsonify(host_data)
    except Exception as e:
        return jsonify({
            'error': True,
            'message': f'Failed to retrieve host data: {str(e)}',
            'code': 'DATA_RETRIEVAL_ERROR'
        }), 500

@app.route('/api/summarize/<ip>', methods=['POST'])
def summarize_host(ip):
    """Generate AI-powered cybersecurity summary for specific IP address"""
    try:
        # Check if AI summarizer is available
        if not ai_summarizer:
            return jsonify({
                'error': True,
                'message': 'AI summarization not available. Please check GEMINI_API_KEY configuration.',
                'code': 'AI_NOT_CONFIGURED'
            }), 503
        
        # Get host data
        host_data = data_manager.get_host_by_ip(ip)
        if host_data is None:
            return jsonify({
                'error': True,
                'message': f'Host not found for IP address: {ip}',
                'code': 'HOST_NOT_FOUND'
            }), 404
        
        # Generate AI summary
        summary = ai_summarizer.generate_summary(host_data)
        
        return jsonify({
            'ip': ip,
            'summary': summary,
            'timestamp': datetime.utcnow().isoformat() + 'Z'
        })
        
    except Exception as e:
        error_message = str(e)
        
        # Determine appropriate error code and status
        if 'API key' in error_message or 'authentication' in error_message:
            status_code = 401
            error_code = 'API_KEY_ERROR'
        elif 'quota' in error_message or 'rate limit' in error_message:
            status_code = 429
            error_code = 'API_QUOTA_ERROR'
        elif 'network' in error_message or 'connection' in error_message:
            status_code = 502
            error_code = 'API_CONNECTION_ERROR'
        else:
            status_code = 500
            error_code = 'SUMMARIZATION_ERROR'
        
        return jsonify({
            'error': True,
            'message': f'Failed to generate summary: {error_message}',
            'code': error_code
        }), status_code

if __name__ == '__main__':
    app.run(debug=True, host='0.0.0.0', port=5000)