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
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
|
|
|
| 68 |
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
node_color = []
|
| 73 |
-
for node in G.nodes():
|
| 74 |
-
x, y = pos[node]
|
| 75 |
-
node_x.append(x)
|
| 76 |
-
node_y.append(y)
|
| 77 |
-
node_text.append(node)
|
| 78 |
-
if node in graph_data["risky"]:
|
| 79 |
-
node_color.append('#ff4444') # kırmızı = riskli
|
| 80 |
-
else:
|
| 81 |
-
node_color.append('#1f77b4') # mavi = normal
|
| 82 |
-
|
| 83 |
-
node_trace = go.Scatter(
|
| 84 |
-
x=node_x, y=node_y,
|
| 85 |
-
mode='markers+text',
|
| 86 |
-
hoverinfo='text',
|
| 87 |
-
text=node_text,
|
| 88 |
-
textposition="top center",
|
| 89 |
-
marker=dict(
|
| 90 |
-
showscale=False,
|
| 91 |
-
color=node_color,
|
| 92 |
-
size=30,
|
| 93 |
-
line_width=2
|
| 94 |
-
)
|
| 95 |
-
)
|
| 96 |
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
# ────────────────────────────────────────────────
|
| 162 |
-
with gr.Blocks(...) as demo:
|
| 163 |
-
# ... önceki kısımlar aynı
|
| 164 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
with gr.Tabs():
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
)
|
| 179 |
|
| 180 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
╔════════════════════════════════════════════════════════════════════════════╗
|
| 3 |
+
║ ADVANCED WEB + BANKING SECURITY RECONNAISSANCE FRAMEWORK ║
|
| 4 |
+
║ HuggingFace Spaces Free Tier Optimized (16GB RAM, 2CPU, 50GB disk) ║
|
| 5 |
+
║ ║
|
| 6 |
+
║ WARNING: FOR AUTHORIZED TESTING ONLY ║
|
| 7 |
+
║ Unauthorized access = Federal Crime (CFAA, Wire Fraud Act) ║
|
| 8 |
+
╚════════════════════════════════════════════════════════════════════════════╝
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
import gradio as gr
|
| 12 |
+
import requests
|
| 13 |
+
from bs4 import BeautifulSoup
|
| 14 |
+
import json
|
| 15 |
+
import re
|
| 16 |
import base64
|
| 17 |
+
import hashlib
|
| 18 |
+
from typing import Dict, List, Tuple, Optional
|
| 19 |
+
from datetime import datetime
|
| 20 |
+
from collections import defaultdict
|
| 21 |
+
import logging
|
| 22 |
+
|
| 23 |
+
# Optimize for free tier
|
| 24 |
+
logging.basicConfig(level=logging.WARNING)
|
| 25 |
|
| 26 |
+
# ════════════════════════════════════════════════════════════════════════════
|
| 27 |
+
# SECTION 0: THREAT DEFINITIONS (Banking + Web Security)
|
| 28 |
+
# ════════════════════════════════════════════════════════════════════════════
|
| 29 |
+
|
| 30 |
+
BANKING_VULNERABILITIES = {
|
| 31 |
+
"🔴 CRITICAL": {
|
| 32 |
+
"SQL_Injection": {
|
| 33 |
+
"risk": 9.9,
|
| 34 |
+
"locations": ["/login", "/search", "/api/users", "/transfer"],
|
| 35 |
+
"patterns": ["' OR '1'='1", "UNION SELECT", "stacked queries"],
|
| 36 |
+
"impact": "Full database compromise"
|
| 37 |
+
},
|
| 38 |
+
"Authentication_Bypass": {
|
| 39 |
+
"risk": 9.8,
|
| 40 |
+
"locations": ["/login", "/api/auth", "/admin"],
|
| 41 |
+
"patterns": ["Missing MFA", "Weak session management", "Token reuse"],
|
| 42 |
+
"impact": "Account takeover, fraud"
|
| 43 |
+
},
|
| 44 |
+
"IDOR": {
|
| 45 |
+
"risk": 9.5,
|
| 46 |
+
"locations": ["/account/123", "/transfer/999", "/card/xyz"],
|
| 47 |
+
"patterns": ["Sequential IDs", "Predictable parameters"],
|
| 48 |
+
"impact": "Access to other users' data/accounts"
|
| 49 |
+
},
|
| 50 |
+
"RCE": {
|
| 51 |
+
"risk": 10.0,
|
| 52 |
+
"locations": ["/upload", "/plugin", "/admin"],
|
| 53 |
+
"patterns": ["Unrestricted file upload", "Code execution endpoint"],
|
| 54 |
+
"impact": "Complete server compromise"
|
| 55 |
+
}
|
| 56 |
+
},
|
| 57 |
+
"🟠 HIGH": {
|
| 58 |
+
"XSS": {
|
| 59 |
+
"risk": 7.5,
|
| 60 |
+
"locations": ["/comment", "/search", "/profile"],
|
| 61 |
+
"patterns": ["<script>", "javascript:", "onerror="],
|
| 62 |
+
"impact": "Session theft, credential harvesting"
|
| 63 |
+
},
|
| 64 |
+
"CSRF": {
|
| 65 |
+
"risk": 7.3,
|
| 66 |
+
"locations": ["/transfer", "/payment", "/settings"],
|
| 67 |
+
"patterns": ["Missing CSRF token", "No SameSite cookie"],
|
| 68 |
+
"impact": "Unauthorized actions on behalf of users"
|
| 69 |
+
},
|
| 70 |
+
"Insecure_API": {
|
| 71 |
+
"risk": 8.2,
|
| 72 |
+
"locations": ["/api/v1/", "/api/mobile/"],
|
| 73 |
+
"patterns": ["No auth check", "Rate limit bypass", "Predictable tokens"],
|
| 74 |
+
"impact": "Data theft, service disruption"
|
| 75 |
+
},
|
| 76 |
+
"Weak_Encryption": {
|
| 77 |
+
"risk": 7.8,
|
| 78 |
+
"locations": ["/login", "/transfer", "/card"],
|
| 79 |
+
"patterns": ["HTTP instead HTTPS", "Old TLS version", "Weak cipher"],
|
| 80 |
+
"impact": "MITM attack, credential interception"
|
| 81 |
+
}
|
| 82 |
+
},
|
| 83 |
+
"🟡 MEDIUM": {
|
| 84 |
+
"Information_Disclosure": {
|
| 85 |
+
"risk": 6.5,
|
| 86 |
+
"locations": ["/error", "/api/debug", "/backup"],
|
| 87 |
+
"patterns": ["Stack traces", "API keys in responses", "Version disclosure"],
|
| 88 |
+
"impact": "Information leakage, further attacks"
|
| 89 |
+
},
|
| 90 |
+
"Broken_Access_Control": {
|
| 91 |
+
"risk": 6.8,
|
| 92 |
+
"locations": ["/admin", "/settings", "/reports"],
|
| 93 |
+
"patterns": ["No permission check", "Horizontal privilege escalation"],
|
| 94 |
+
"impact": "Unauthorized access to sensitive features"
|
| 95 |
+
},
|
| 96 |
+
"Insecure_Deserialization": {
|
| 97 |
+
"risk": 6.9,
|
| 98 |
+
"locations": ["/config", "/api/data", "/upload"],
|
| 99 |
+
"patterns": ["pickle.", "unserialize", "unsafe deserialization"],
|
| 100 |
+
"impact": "RCE, data manipulation"
|
| 101 |
+
}
|
| 102 |
}
|
| 103 |
+
}
|
| 104 |
|
| 105 |
+
BANKING_INDICATORS = {
|
| 106 |
+
"Payment Processors": {
|
| 107 |
+
"Stripe": r"stripe\.(js|com)",
|
| 108 |
+
"PayPal": r"paypal\.(api|gateway)",
|
| 109 |
+
"Square": r"squareup\.com",
|
| 110 |
+
"Wise": r"wise\.com",
|
| 111 |
+
"Checkout": r"checkout\.com"
|
| 112 |
+
},
|
| 113 |
+
"Security Indicators": {
|
| 114 |
+
"MFA_Enabled": r"(2fa|two-factor|totp|authenticator|mfa)",
|
| 115 |
+
"OAuth": r"(oauth|openid|saml)",
|
| 116 |
+
"HTTPS": r"https://",
|
| 117 |
+
"HSTS": r"Strict-Transport-Security",
|
| 118 |
+
"CSP": r"Content-Security-Policy"
|
| 119 |
+
},
|
| 120 |
+
"Risk Indicators": {
|
| 121 |
+
"Outdated_Framework": r"(WordPress|Drupal|Joomla|Laravel|Django|Flask)",
|
| 122 |
+
"Exposed_Admin": r"(/admin|/wp-admin|/administrator)",
|
| 123 |
+
"Debug_Mode": r"(debug|dev|development|staging)",
|
| 124 |
+
"Version_Disclosure": r"(X-Powered-By|Server:)"
|
| 125 |
+
}
|
| 126 |
+
}
|
| 127 |
|
| 128 |
+
# ════════════════════════════════════════════════════════════════════════════
|
| 129 |
+
# SECTION 1: OPTIMIZED RECONNAISSANCE ENGINE
|
| 130 |
+
# ════════════════════════════════════════════════════════════════════════════
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
|
| 132 |
+
class QuickReconEngine:
|
| 133 |
+
"""Optimized for HF Spaces free tier (minimal RAM/CPU)"""
|
| 134 |
+
|
| 135 |
+
def __init__(self):
|
| 136 |
+
self.findings = []
|
| 137 |
+
self.cache = {}
|
| 138 |
+
|
| 139 |
+
def analyze_target(self, domain: str) -> Dict:
|
| 140 |
+
"""Fast analysis without async/heavy operations"""
|
| 141 |
+
|
| 142 |
+
results = {
|
| 143 |
+
"domain": domain,
|
| 144 |
+
"timestamp": datetime.now().isoformat(),
|
| 145 |
+
"vulnerabilities": [],
|
| 146 |
+
"risk_summary": {"critical": 0, "high": 0, "medium": 0},
|
| 147 |
+
"technologies": [],
|
| 148 |
+
"security_headers": {},
|
| 149 |
+
"recommendations": []
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
try:
|
| 153 |
+
# 1. Basic HTTP analysis
|
| 154 |
+
results["security_headers"] = self._check_headers(domain)
|
| 155 |
+
|
| 156 |
+
# 2. Technology detection
|
| 157 |
+
results["technologies"] = self._detect_technologies(domain)
|
| 158 |
+
|
| 159 |
+
# 3. Vulnerability patterns
|
| 160 |
+
results["vulnerabilities"] = self._detect_vulnerabilities(domain, results["technologies"])
|
| 161 |
+
|
| 162 |
+
# 4. Risk calculation
|
| 163 |
+
results["risk_summary"] = self._calculate_risk(results["vulnerabilities"])
|
| 164 |
+
|
| 165 |
+
# 5. Recommendations
|
| 166 |
+
results["recommendations"] = self._generate_recommendations(results["vulnerabilities"])
|
| 167 |
+
|
| 168 |
+
except Exception as e:
|
| 169 |
+
results["error"] = str(e)
|
| 170 |
+
|
| 171 |
+
return results
|
| 172 |
+
|
| 173 |
+
def _check_headers(self, domain: str) -> Dict:
|
| 174 |
+
"""Check security headers"""
|
| 175 |
+
headers_check = {
|
| 176 |
+
"has_https": False,
|
| 177 |
+
"has_hsts": False,
|
| 178 |
+
"has_csp": False,
|
| 179 |
+
"has_x_frame_options": False,
|
| 180 |
+
"has_x_content_type": False,
|
| 181 |
+
"vulnerabilities": []
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
try:
|
| 185 |
+
resp = requests.head(
|
| 186 |
+
f"https://{domain}",
|
| 187 |
+
timeout=5,
|
| 188 |
+
verify=False,
|
| 189 |
+
allow_redirects=True
|
| 190 |
+
)
|
| 191 |
+
|
| 192 |
+
headers = resp.headers
|
| 193 |
+
headers_check["has_https"] = True
|
| 194 |
+
|
| 195 |
+
if "Strict-Transport-Security" not in headers:
|
| 196 |
+
headers_check["vulnerabilities"].append("❌ HSTS Header Missing")
|
| 197 |
+
else:
|
| 198 |
+
headers_check["has_hsts"] = True
|
| 199 |
+
|
| 200 |
+
if "Content-Security-Policy" not in headers:
|
| 201 |
+
headers_check["vulnerabilities"].append("⚠️ CSP Header Missing (XSS Risk)")
|
| 202 |
+
else:
|
| 203 |
+
headers_check["has_csp"] = True
|
| 204 |
+
|
| 205 |
+
if "X-Frame-Options" not in headers:
|
| 206 |
+
headers_check["vulnerabilities"].append("⚠️ No X-Frame-Options (Clickjacking Risk)")
|
| 207 |
+
else:
|
| 208 |
+
headers_check["has_x_frame_options"] = True
|
| 209 |
+
|
| 210 |
+
if "X-Content-Type-Options" not in headers:
|
| 211 |
+
headers_check["vulnerabilities"].append("⚠️ No X-Content-Type-Options")
|
| 212 |
+
else:
|
| 213 |
+
headers_check["has_x_content_type"] = True
|
| 214 |
+
|
| 215 |
+
# Check for dangerous headers
|
| 216 |
+
if "Server" in headers:
|
| 217 |
+
server = headers["Server"]
|
| 218 |
+
headers_check["vulnerabilities"].append(f"⚠️ Server Info Leak: {server}")
|
| 219 |
+
|
| 220 |
+
if "X-Powered-By" in headers:
|
| 221 |
+
headers_check["vulnerabilities"].append(f"⚠️ Technology Leak: {headers['X-Powered-By']}")
|
| 222 |
+
|
| 223 |
+
except Exception as e:
|
| 224 |
+
headers_check["vulnerabilities"].append(f"❌ Cannot reach target: {str(e)}")
|
| 225 |
+
|
| 226 |
+
return headers_check
|
| 227 |
+
|
| 228 |
+
def _detect_technologies(self, domain: str) -> List[str]:
|
| 229 |
+
"""Detect technologies used"""
|
| 230 |
+
techs = []
|
| 231 |
+
|
| 232 |
+
try:
|
| 233 |
+
resp = requests.get(
|
| 234 |
+
f"https://{domain}",
|
| 235 |
+
timeout=5,
|
| 236 |
+
verify=False,
|
| 237 |
+
headers={"User-Agent": "Mozilla/5.0"}
|
| 238 |
+
)
|
| 239 |
+
content = resp.text.lower()
|
| 240 |
+
headers = resp.headers
|
| 241 |
+
|
| 242 |
+
# Check headers
|
| 243 |
+
if "server" in headers:
|
| 244 |
+
server = headers["server"].lower()
|
| 245 |
+
if "apache" in server:
|
| 246 |
+
techs.append("Apache")
|
| 247 |
+
if "nginx" in server:
|
| 248 |
+
techs.append("Nginx")
|
| 249 |
+
if "iis" in server:
|
| 250 |
+
techs.append("IIS")
|
| 251 |
+
|
| 252 |
+
# Check content
|
| 253 |
+
patterns = {
|
| 254 |
+
"WordPress": r"wp-content|wp-includes|wordpress",
|
| 255 |
+
"Drupal": r"drupal\.css|sites/default",
|
| 256 |
+
"Joomla": r"joomla|com_content",
|
| 257 |
+
"React": r"__react|react\.js",
|
| 258 |
+
"Vue": r"__vue|vue\.js",
|
| 259 |
+
"Angular": r"ng-app|angular\.js",
|
| 260 |
+
"Flask": r"flask|werkzeug",
|
| 261 |
+
"Django": r"django|django_session",
|
| 262 |
+
"Laravel": r"laravel_session|xsrf-token",
|
| 263 |
+
"Stripe": r"stripe\.js|stripe\.com",
|
| 264 |
+
"PayPal": r"paypal\.com|paypalapi"
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
for tech, pattern in patterns.items():
|
| 268 |
+
if re.search(pattern, content):
|
| 269 |
+
techs.append(tech)
|
| 270 |
+
|
| 271 |
+
except:
|
| 272 |
+
pass
|
| 273 |
+
|
| 274 |
+
return list(set(techs))
|
| 275 |
+
|
| 276 |
+
def _detect_vulnerabilities(self, domain: str, technologies: List[str]) -> List[Dict]:
|
| 277 |
+
"""Detect potential vulnerabilities"""
|
| 278 |
+
vulns = []
|
| 279 |
+
|
| 280 |
+
try:
|
| 281 |
+
resp = requests.get(
|
| 282 |
+
f"https://{domain}",
|
| 283 |
+
timeout=5,
|
| 284 |
+
verify=False,
|
| 285 |
+
headers={"User-Agent": "Mozilla/5.0"}
|
| 286 |
+
)
|
| 287 |
+
content = resp.text
|
| 288 |
+
|
| 289 |
+
# Check for common vulnerable patterns
|
| 290 |
+
checks = {
|
| 291 |
+
"SQL_Injection": {
|
| 292 |
+
"patterns": [r"/search\?", r"/find\?", r"/filter\?"],
|
| 293 |
+
"risk": 9.9,
|
| 294 |
+
"description": "Potential SQL injection points found"
|
| 295 |
+
},
|
| 296 |
+
"Exposed_Admin": {
|
| 297 |
+
"patterns": [r"/admin", r"/wp-admin", r"/administrator", r"/management"],
|
| 298 |
+
"risk": 8.5,
|
| 299 |
+
"description": "Admin interface might be exposed"
|
| 300 |
+
},
|
| 301 |
+
"Debug_Enabled": {
|
| 302 |
+
"patterns": [r"debug.*true", r"debug.*enabled", r"__debugger__"],
|
| 303 |
+
"risk": 8.0,
|
| 304 |
+
"description": "Debug mode appears to be enabled"
|
| 305 |
+
},
|
| 306 |
+
"Version_Disclosure": {
|
| 307 |
+
"patterns": [r"v[\d\.]+", r"version.*[\d\.]+", r"wordpress.*[\d\.]+"],
|
| 308 |
+
"risk": 5.5,
|
| 309 |
+
"description": "Application version information disclosed"
|
| 310 |
+
},
|
| 311 |
+
"Stack_Trace_Exposure": {
|
| 312 |
+
"patterns": [r"traceback", r"stacktrace", r"at .*line", r"in .*\.py"],
|
| 313 |
+
"risk": 7.0,
|
| 314 |
+
"description": "Stack traces might be exposed in error pages"
|
| 315 |
+
}
|
| 316 |
+
}
|
| 317 |
+
|
| 318 |
+
for vuln_type, check_info in checks.items():
|
| 319 |
+
for pattern in check_info["patterns"]:
|
| 320 |
+
if re.search(pattern, content, re.IGNORECASE):
|
| 321 |
+
vulns.append({
|
| 322 |
+
"type": vuln_type,
|
| 323 |
+
"risk": check_info["risk"],
|
| 324 |
+
"description": check_info["description"],
|
| 325 |
+
"cvss": f"{check_info['risk']:.1f}"
|
| 326 |
+
})
|
| 327 |
+
break
|
| 328 |
+
|
| 329 |
+
# Framework-specific vulnerabilities
|
| 330 |
+
for tech in technologies:
|
| 331 |
+
if tech == "WordPress":
|
| 332 |
+
vulns.append({
|
| 333 |
+
"type": "Known_CMS_Vulns",
|
| 334 |
+
"risk": 7.5,
|
| 335 |
+
"description": f"WordPress might have known vulnerabilities. Check WPScan database.",
|
| 336 |
+
"cvss": "7.5"
|
| 337 |
+
})
|
| 338 |
+
elif tech == "Laravel":
|
| 339 |
+
vulns.append({
|
| 340 |
+
"type": "Laravel_Specific",
|
| 341 |
+
"risk": 6.8,
|
| 342 |
+
"description": "Check for Laravel-specific vulns (debug mode, CSRF, etc)",
|
| 343 |
+
"cvss": "6.8"
|
| 344 |
+
})
|
| 345 |
+
|
| 346 |
+
except:
|
| 347 |
+
pass
|
| 348 |
+
|
| 349 |
+
return vulns
|
| 350 |
+
|
| 351 |
+
def _calculate_risk(self, vulnerabilities: List[Dict]) -> Dict:
|
| 352 |
+
"""Calculate overall risk"""
|
| 353 |
+
risk_summary = {"critical": 0, "high": 0, "medium": 0}
|
| 354 |
+
|
| 355 |
+
for vuln in vulnerabilities:
|
| 356 |
+
risk = vuln.get("risk", 5.0)
|
| 357 |
+
if risk >= 9.0:
|
| 358 |
+
risk_summary["critical"] += 1
|
| 359 |
+
elif risk >= 7.0:
|
| 360 |
+
risk_summary["high"] += 1
|
| 361 |
+
else:
|
| 362 |
+
risk_summary["medium"] += 1
|
| 363 |
+
|
| 364 |
+
return risk_summary
|
| 365 |
+
|
| 366 |
+
def _generate_recommendations(self, vulnerabilities: List[Dict]) -> List[str]:
|
| 367 |
+
"""Generate security recommendations"""
|
| 368 |
+
recommendations = []
|
| 369 |
+
|
| 370 |
+
if not vulnerabilities:
|
| 371 |
+
return ["✅ No major vulnerabilities detected"]
|
| 372 |
+
|
| 373 |
+
# Critical findings
|
| 374 |
+
critical = [v for v in vulnerabilities if v.get("risk", 0) >= 9.0]
|
| 375 |
+
if critical:
|
| 376 |
+
recommendations.append(f"🔴 CRITICAL: {len(critical)} critical issues found - Immediate action required")
|
| 377 |
+
|
| 378 |
+
# High findings
|
| 379 |
+
high = [v for v in vulnerabilities if 7.0 <= v.get("risk", 0) < 9.0]
|
| 380 |
+
if high:
|
| 381 |
+
recommendations.append(f"🟠 HIGH: {len(high)} high-risk issues - Address within 24-48 hours")
|
| 382 |
+
|
| 383 |
+
# Specific recommendations
|
| 384 |
+
if any(v["type"] == "Exposed_Admin" for v in vulnerabilities):
|
| 385 |
+
recommendations.append("🔐 Secure admin interfaces with strong authentication and WAF rules")
|
| 386 |
+
|
| 387 |
+
if any(v["type"] == "SQL_Injection" for v in vulnerabilities):
|
| 388 |
+
recommendations.append("🛡️ Implement input validation, parameterized queries, and WAF rules")
|
| 389 |
+
|
| 390 |
+
if any(v["type"] == "Debug_Enabled" for v in vulnerabilities):
|
| 391 |
+
recommendations.append("🔧 Disable debug mode in production immediately")
|
| 392 |
+
|
| 393 |
+
if any(v["type"] == "Version_Disclosure" for v in vulnerabilities):
|
| 394 |
+
recommendations.append("🚫 Remove version information from headers and error messages")
|
| 395 |
+
|
| 396 |
+
recommendations.extend([
|
| 397 |
+
"📋 Regular security audits and penetration testing",
|
| 398 |
+
"🔄 Keep all software updated and patched",
|
| 399 |
+
"📊 Implement security monitoring and alerting",
|
| 400 |
+
"👥 Security training for all developers"
|
| 401 |
+
])
|
| 402 |
+
|
| 403 |
+
return recommendations
|
| 404 |
+
|
| 405 |
+
# ════════════════════════════════════════════════════════════════════════════
|
| 406 |
+
# SECTION 2: ATTACK SURFACE VISUALIZATION
|
| 407 |
+
# ════════════════════════════════════════════════════════════════════════════
|
| 408 |
+
|
| 409 |
+
def create_risk_report(analysis: Dict) -> Tuple[str, str, str]:
|
| 410 |
+
"""Generate visual reports for findings"""
|
| 411 |
+
|
| 412 |
+
# Summary Report
|
| 413 |
+
summary = f"""
|
| 414 |
+
## 🔐 SECURITY ASSESSMENT REPORT
|
| 415 |
+
|
| 416 |
+
**Target:** {analysis['domain']}
|
| 417 |
+
**Date:** {analysis['timestamp']}
|
| 418 |
+
|
| 419 |
+
### 📊 RISK SUMMARY
|
| 420 |
+
- 🔴 **Critical Issues:** {analysis['risk_summary']['critical']}
|
| 421 |
+
- 🟠 **High Issues:** {analysis['risk_summary']['high']}
|
| 422 |
+
- 🟡 **Medium Issues:** {analysis['risk_summary']['medium']}
|
| 423 |
+
|
| 424 |
+
**Overall Risk:** {'CRITICAL 🔴' if analysis['risk_summary']['critical'] > 0 else 'HIGH 🟠' if analysis['risk_summary']['high'] > 0 else 'MEDIUM 🟡'}
|
| 425 |
+
|
| 426 |
+
### 🔧 TECHNOLOGIES DETECTED
|
| 427 |
+
{', '.join(analysis['technologies']) if analysis['technologies'] else 'No specific frameworks detected'}
|
| 428 |
+
|
| 429 |
+
### 🛡️ SECURITY HEADERS
|
| 430 |
+
- HTTPS: {'✅ Yes' if analysis['security_headers'].get('has_https') else '❌ No'}
|
| 431 |
+
- HSTS: {'✅ Yes' if analysis['security_headers'].get('has_hsts') else '❌ No'}
|
| 432 |
+
- CSP: {'✅ Yes' if analysis['security_headers'].get('has_csp') else '❌ No'}
|
| 433 |
+
- X-Frame-Options: {'✅ Yes' if analysis['security_headers'].get('has_x_frame_options') else '❌ No'}
|
| 434 |
|
| 435 |
+
### ⚠️ HEADER VULNERABILITIES
|
| 436 |
+
{chr(10).join([f'- {v}' for v in analysis['security_headers'].get('vulnerabilities', [])])}
|
|
|
|
|
|
|
|
|
|
| 437 |
|
| 438 |
+
### 🎯 VULNERABILITIES FOUND
|
| 439 |
+
"""
|
| 440 |
+
|
| 441 |
+
for vuln in analysis.get('vulnerabilities', []):
|
| 442 |
+
summary += f"\n**{vuln['type']}** (CVSS: {vuln['cvss']})\n"
|
| 443 |
+
summary += f"- {vuln['description']}\n"
|
| 444 |
+
|
| 445 |
+
# Recommendations
|
| 446 |
+
recommendations = "\n### 💡 RECOMMENDATIONS\n"
|
| 447 |
+
for i, rec in enumerate(analysis['recommendations'], 1):
|
| 448 |
+
recommendations += f"{i}. {rec}\n"
|
| 449 |
+
|
| 450 |
+
summary += recommendations
|
| 451 |
+
|
| 452 |
+
# JSON Report
|
| 453 |
+
json_report = json.dumps(analysis, indent=2)
|
| 454 |
+
|
| 455 |
+
# Detailed Report
|
| 456 |
+
detailed = f"""
|
| 457 |
+
# 📋 DETAILED SECURITY ASSESSMENT
|
| 458 |
+
|
| 459 |
+
## Executive Summary
|
| 460 |
+
This assessment evaluated the security posture of **{analysis['domain']}**.
|
| 461 |
+
|
| 462 |
+
### Critical Findings
|
| 463 |
+
{f"- {len([v for v in analysis['vulnerabilities'] if v['risk'] >= 9])} critical vulnerabilities detected" if analysis['vulnerabilities'] else "No critical vulnerabilities found"}
|
| 464 |
+
|
| 465 |
+
### Methodology
|
| 466 |
+
1. **Passive Reconnaissance** - Public information gathering
|
| 467 |
+
2. **HTTP Analysis** - Security header inspection
|
| 468 |
+
3. **Technology Detection** - Framework and library identification
|
| 469 |
+
4. **Vulnerability Pattern Matching** - Common weakness detection
|
| 470 |
+
|
| 471 |
+
### Key Findings
|
| 472 |
+
"""
|
| 473 |
+
|
| 474 |
+
if analysis.get('vulnerabilities'):
|
| 475 |
+
detailed += "\n#### Vulnerabilities by Severity\n"
|
| 476 |
+
for vuln in sorted(analysis['vulnerabilities'], key=lambda x: x['risk'], reverse=True):
|
| 477 |
+
detailed += f"\n- **{vuln['type']}** (Risk: {vuln['risk']}/10)\n"
|
| 478 |
+
detailed += f" - {vuln['description']}\n"
|
| 479 |
+
detailed += f" - CVSS Score: {vuln['cvss']}\n"
|
| 480 |
+
|
| 481 |
+
detailed += f"""
|
| 482 |
+
|
| 483 |
+
### Remediation Guidance
|
| 484 |
+
1. **Immediate Actions** (24-48 hours)
|
| 485 |
+
- Address all critical findings
|
| 486 |
+
- Enable security headers
|
| 487 |
+
- Implement WAF rules
|
| 488 |
+
|
| 489 |
+
2. **Short-term** (1-2 weeks)
|
| 490 |
+
- Patch known vulnerabilities
|
| 491 |
+
- Implement security controls
|
| 492 |
+
- Security awareness training
|
| 493 |
+
|
| 494 |
+
3. **Long-term** (Ongoing)
|
| 495 |
+
- Regular assessments
|
| 496 |
+
- Security monitoring
|
| 497 |
+
- Incident response planning
|
| 498 |
+
|
| 499 |
+
---
|
| 500 |
+
*Assessment conducted: {analysis['timestamp']}*
|
| 501 |
+
*Status: Preliminary - Manual verification recommended*
|
| 502 |
+
"""
|
| 503 |
+
|
| 504 |
+
return summary, json_report, detailed
|
| 505 |
+
|
| 506 |
+
# ════════════════════════════════════════════════════════════════════════════
|
| 507 |
+
# SECTION 3: GRADIO INTERFACE (HF Spaces Optimized)
|
| 508 |
+
# ════════════════════════════════════════════════════════════════════════════
|
| 509 |
+
|
| 510 |
+
def run_assessment(target_domain: str) -> Tuple[str, str, str]:
|
| 511 |
+
"""Main assessment function"""
|
| 512 |
+
|
| 513 |
+
if not target_domain or len(target_domain) < 3:
|
| 514 |
+
return (
|
| 515 |
+
"❌ Invalid domain entered",
|
| 516 |
+
"{}",
|
| 517 |
+
"Please enter a valid domain (e.g., example.com)"
|
| 518 |
+
)
|
| 519 |
+
|
| 520 |
+
# Clean input
|
| 521 |
+
target = target_domain.strip().replace("https://", "").replace("http://", "").split("/")[0]
|
| 522 |
+
|
| 523 |
+
# Run analysis
|
| 524 |
+
engine = QuickReconEngine()
|
| 525 |
+
analysis = engine.analyze_target(target)
|
| 526 |
+
|
| 527 |
+
# Generate reports
|
| 528 |
+
summary, json_report, detailed = create_risk_report(analysis)
|
| 529 |
+
|
| 530 |
+
return summary, json_report, detailed
|
| 531 |
+
|
| 532 |
+
# ════════════════════════════════════════════════════════════════════════════
|
| 533 |
+
# GRADIO UI
|
| 534 |
+
# ════════════════════════════════════════════════════════════════════════════
|
| 535 |
+
|
| 536 |
+
with gr.Blocks(
|
| 537 |
+
theme=gr.themes.Soft(primary_hue="red"),
|
| 538 |
+
title="Security Assessment Framework"
|
| 539 |
+
) as demo:
|
| 540 |
+
|
| 541 |
+
gr.Markdown("""
|
| 542 |
+
# 🛡️ ADVANCED SECURITY ASSESSMENT FRAMEWORK
|
| 543 |
+
## Web & Banking Security Testing Tool
|
| 544 |
+
|
| 545 |
+
**⚠️ DISCLAIMER:** This tool is for authorized testing only.
|
| 546 |
+
Unauthorized access to computer systems is a federal crime under the CFAA.
|
| 547 |
+
|
| 548 |
+
**Features:**
|
| 549 |
+
- 🔍 Fast domain reconnaissance
|
| 550 |
+
- 🔧 Technology identification
|
| 551 |
+
- 🚨 Vulnerability detection
|
| 552 |
+
- 📊 Risk assessment
|
| 553 |
+
- 💡 Security recommendations
|
| 554 |
+
""")
|
| 555 |
+
|
| 556 |
+
with gr.Row():
|
| 557 |
+
with gr.Column(scale=2):
|
| 558 |
+
domain_input = gr.Textbox(
|
| 559 |
+
label="🎯 Target Domain",
|
| 560 |
+
placeholder="example.com (without https://)",
|
| 561 |
+
info="Enter domain to assess (authorized testing only)"
|
| 562 |
+
)
|
| 563 |
+
|
| 564 |
+
assess_btn = gr.Button(
|
| 565 |
+
"🔍 START ASSESSMENT",
|
| 566 |
+
variant="primary",
|
| 567 |
+
size="lg"
|
| 568 |
+
)
|
| 569 |
+
|
| 570 |
+
with gr.Column(scale=1):
|
| 571 |
+
gr.Markdown("""
|
| 572 |
+
### How to Use
|
| 573 |
+
1. Enter target domain
|
| 574 |
+
2. Click START ASSESSMENT
|
| 575 |
+
3. Review findings in tabs
|
| 576 |
+
|
| 577 |
+
### ⚡ Optimized
|
| 578 |
+
- Free HF Spaces tier
|
| 579 |
+
- 10-30 second assessment
|
| 580 |
+
- No GPU needed
|
| 581 |
+
""")
|
| 582 |
+
|
| 583 |
with gr.Tabs():
|
| 584 |
+
with gr.Tab("📋 Summary Report"):
|
| 585 |
+
summary_output = gr.Markdown(label="Security Summary")
|
| 586 |
+
|
| 587 |
+
with gr.Tab("📊 JSON Data"):
|
| 588 |
+
json_output = gr.Code(
|
| 589 |
+
language="json",
|
| 590 |
+
label="Raw Assessment Data"
|
| 591 |
+
)
|
| 592 |
+
|
| 593 |
+
with gr.Tab("📄 Detailed Report"):
|
| 594 |
+
detailed_output = gr.Markdown(label="Full Assessment")
|
| 595 |
+
|
| 596 |
+
# Event handler
|
| 597 |
+
assess_btn.click(
|
| 598 |
+
fn=run_assessment,
|
| 599 |
+
inputs=domain_input,
|
| 600 |
+
outputs=[summary_output, json_output, detailed_output]
|
| 601 |
)
|
| 602 |
|
| 603 |
+
# ════════════════════════════════════════════════════════════════════════════
|
| 604 |
+
# LAUNCH
|
| 605 |
+
# ════════════════════════════════════════════════════════════════════════════
|
| 606 |
+
|
| 607 |
+
if __name__ == "__main__":
|
| 608 |
+
demo.launch(
|
| 609 |
+
share=True,
|
| 610 |
+
server_name="0.0.0.0",
|
| 611 |
+
server_port=7860,
|
| 612 |
+
show_error=True
|
| 613 |
+
)
|