Spaces:
Runtime error
Runtime error
Upload 3 files
Browse files- integration/api_security.py +19 -0
- intel/threat_feeds.py +12 -0
- logs/log_management.py +9 -0
integration/api_security.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, request, jsonify
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
app = Flask(__name__)
|
| 5 |
+
|
| 6 |
+
@app.route('/secure-endpoint', methods=['POST'])
|
| 7 |
+
def secure_endpoint():
|
| 8 |
+
secret = os.getenv("API_SECRET", "default_secret")
|
| 9 |
+
data = request.json
|
| 10 |
+
if "api_key" not in data or data["api_key"] != secret:
|
| 11 |
+
return jsonify({"status": "failure", "error": "Unauthorized"}), 401
|
| 12 |
+
if "command" in data and isinstance(data["command"], str):
|
| 13 |
+
command = data["command"]
|
| 14 |
+
if command.isalnum():
|
| 15 |
+
return jsonify({"status": "success", "output": f"Command '{command}' executed securely"})
|
| 16 |
+
return jsonify({"status": "failure", "error": "Invalid command"}), 400
|
| 17 |
+
|
| 18 |
+
if __name__ == "__main__":
|
| 19 |
+
app.run(debug=True, port=5000)
|
intel/threat_feeds.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import requests
|
| 3 |
+
|
| 4 |
+
def fetch_threat_intelligence():
|
| 5 |
+
response = requests.get("https://threat-intel-feed.example.com/api")
|
| 6 |
+
if response.status_code == 200:
|
| 7 |
+
return response.json()
|
| 8 |
+
return []
|
| 9 |
+
|
| 10 |
+
if __name__ == "__main__":
|
| 11 |
+
threat_data = fetch_threat_intelligence()
|
| 12 |
+
print(f"Threat Data: {threat_data}")
|
logs/log_management.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
def analyze_logs(log_file):
|
| 3 |
+
print(f"Analyzing logs from: {log_file}")
|
| 4 |
+
# Simulated log anomalies
|
| 5 |
+
return {"anomalies_found": 5, "critical_events": ["Unauthorized access attempt"]}
|
| 6 |
+
|
| 7 |
+
if __name__ == "__main__":
|
| 8 |
+
analysis = analyze_logs("system_logs.txt")
|
| 9 |
+
print(f"Log Analysis Results: {analysis}")
|