emosenseproject commited on
Commit
2b4c143
·
verified ·
1 Parent(s): b8153fb

Upload streamlit_app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. streamlit_app.py +347 -0
streamlit_app.py ADDED
@@ -0,0 +1,347 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Utility functions for Domain Threat Intelligence Dashboard
3
+ """
4
+
5
+ import streamlit as st
6
+ import pandas as pd
7
+ import random
8
+ from datetime import datetime, timedelta
9
+ from typing import Dict, List, Optional, Tuple
10
+ import hashlib
11
+
12
+ # Mock data generators for PoC demonstration
13
+
14
+ def generate_verdict() -> Dict:
15
+ """Generate a random verdict with confidence"""
16
+ verdicts = ["Malicious", "Suspicious", "Benign", "Unknown"]
17
+ weights = [0.15, 0.25, 0.50, 0.10]
18
+ verdict = random.choices(verdicts, weights=weights)[0]
19
+
20
+ confidence = {
21
+ "Malicious": random.randint(75, 99),
22
+ "Suspicious": random.randint(50, 74),
23
+ "Benign": random.randint(80, 99),
24
+ "Unknown": random.randint(0, 49)
25
+ }[verdict]
26
+
27
+ reasoning = {
28
+ "Malicious": [
29
+ "Confirmed command-and-control infrastructure for APT28",
30
+ "Associated with multiple malware distribution campaigns",
31
+ "Linked to documented phishing operations",
32
+ "Identified as hosting exploit kits and ransomware payloads"
33
+ ],
34
+ "Suspicious": [
35
+ "Recently registered with privacy-protected registration",
36
+ "Hosting content with ambiguous intent",
37
+ "Traffic patterns inconsistent with normal web activity",
38
+ "Whois data matches known bulletproof hosting patterns"
39
+ ],
40
+ "Benign": [
41
+ "Established business presence with consistent reputation",
42
+ "No adverse findings across major security feeds",
43
+ "Legitimate e-commerce infrastructure",
44
+ "Verified organization with valid certificates"
45
+ ],
46
+ "Unknown": [
47
+ "Insufficient data for comprehensive analysis",
48
+ "Recently registered domain with no historical context",
49
+ "Limited external references available",
50
+ "Analysis ongoing - awaiting additional signals"
51
+ ]
52
+ }
53
+
54
+ return {
55
+ "label": verdict,
56
+ "confidence": confidence,
57
+ "reasoning": random.choice(reasoning[verdict]),
58
+ "last_updated": datetime.now() - timedelta(hours=random.randint(0, 48))
59
+ }
60
+
61
+ def generate_intelligence_tags(verdict: str) -> List[Dict]:
62
+ """Generate intelligence tags based on verdict"""
63
+ tag_pool = {
64
+ "Malicious": [
65
+ {"name": "C2", "category": "Threat Type", "severity": "critical"},
66
+ {"name": "APT-linked", "category": "Attribution", "severity": "critical"},
67
+ {"name": "Malware Infrastructure", "category": "Category", "severity": "high"},
68
+ {"name": "Phishing Kit", "category": "Threat Type", "severity": "high"},
69
+ {"name": "Exploit Kit", "category": "Threat Type", "severity": "high"}
70
+ ],
71
+ "Suspicious": [
72
+ {"name": "Recently Registered", "category": "Registration", "severity": "medium"},
73
+ {"name": "Privacy Protected", "category": "Registration", "severity": "medium"},
74
+ {"name": "Bulletproof Hosting", "category": "Infrastructure", "severity": "medium"},
75
+ {"name": "Fast Flux", "category": "Infrastructure", "severity": "medium"}
76
+ ],
77
+ "Benign": [
78
+ {"name": "Legitimate Business", "category": "Classification", "severity": "low"},
79
+ {"name": "E-commerce", "category": "Category", "severity": "low"},
80
+ {"name": "Verified Publisher", "category": "Trust", "severity": "low"}
81
+ ],
82
+ "Unknown": [
83
+ {"name": "Limited Data", "category": "Context", "severity": "low"},
84
+ {"name": "New Domain", "category": "Registration", "severity": "low"}
85
+ ]
86
+ }
87
+
88
+ available_tags = tag_pool.get(verdict, tag_pool["Unknown"])
89
+ num_tags = random.randint(2, min(4, len(available_tags)))
90
+ selected = random.sample(available_tags, num_tags)
91
+
92
+ # Add some common tags
93
+ first_seen = datetime.now() - timedelta(days=random.randint(1, 365))
94
+ last_seen = datetime.now() - timedelta(days=random.randint(0, 30))
95
+
96
+ for tag in selected:
97
+ tag["first_seen"] = first_seen.strftime("%Y-%m-%d")
98
+ tag["last_seen"] = last_seen.strftime("%Y-%m-%d")
99
+
100
+ return selected
101
+
102
+ def generate_source_verdicts() -> List[Dict]:
103
+ """Generate verdicts from different intelligence sources"""
104
+ sources = [
105
+ {"name": "Internal Dataset", "type": "Reputation", "weight": 0.9},
106
+ {"name": "URL Scanner", "type": "Dynamic Analysis", "weight": 0.8},
107
+ {"name": "Reputation Feed", "type": "Threat Intel", "weight": 0.7},
108
+ {"name": "Passive DNS", "type": "Infrastructure", "weight": 0.6},
109
+ {"name": "Web Search", "type": "OSINT", "weight": 0.5},
110
+ {"name": "WHOIS Database", "type": "Registration", "weight": 0.4},
111
+ {"name": "Certificate Transparency", "type": "Infrastructure", "weight": 0.5},
112
+ {"name": "VirusTotal", "type": "Multi-AV", "weight": 0.8}
113
+ ]
114
+
115
+ results = []
116
+ for source in sources:
117
+ verdict_options = ["Clean", "Suspicious", "Malicious", "No Data", "Establishing"]
118
+ weights = [0.6, 0.15, 0.1, 0.1, 0.05]
119
+ verdict = random.choices(verdict_options, weights=weights)[0]
120
+
121
+ results.append({
122
+ "source": source["name"],
123
+ "type": source["type"],
124
+ "verdict": verdict,
125
+ "last_checked": datetime.now() - timedelta(hours=random.randint(0, 24)),
126
+ "confidence": random.randint(60, 95) if verdict != "No Data" else None
127
+ })
128
+
129
+ return results
130
+
131
+ def generate_analyst_summary(verdict: str) -> Tuple[str, str]:
132
+ """Generate AI/analyst summary"""
133
+ summaries = {
134
+ "Malicious": (
135
+ "This domain exhibits characteristics consistent with malicious infrastructure. "
136
+ "Analysis indicates active involvement in command-and-control communications "
137
+ "associated with documented threat actor activity. Multiple independent sources "
138
+ "confirm its role in supporting offensive cyber operations.",
139
+ "Technical indicators suggest this domain serves as a C2 server for APT28/Sandworm "
140
+ "activity, with connections to documented phishing campaigns targeting government "
141
+ "entities and critical infrastructure. The domain resolves to infrastructure that has "
142
+ "been previously associated with credential harvesting operations. SSL certificate "
143
+ "patterns and DNS records align with established malware deployment frameworks."
144
+ ),
145
+ "Suspicious": (
146
+ "This domain displays anomalous characteristics warranting additional scrutiny. "
147
+ "While not definitively classified as malicious, several indicators deviate from "
148
+ "expected patterns for legitimate web infrastructure. The registration and hosting "
149
+ "characteristics suggest potential misuse but lack conclusive evidence.",
150
+ "Detailed investigation reveals a combination of concerning factors: recent registration "
151
+ "with privacy-protected WHOIS data, hosting on infrastructure associated with known "
152
+ "bulletproof providers, and content patterns inconsistent with stated purpose. However, "
153
+ "no direct malicious activity has been observed. Recommend continued monitoring and "
154
+ "periodic reassessment as additional data becomes available."
155
+ ),
156
+ "Benign": (
157
+ "This domain demonstrates characteristics consistent with legitimate web presence. "
158
+ "Comprehensive analysis across multiple intelligence sources reveals no indicators "
159
+ "of malicious activity. The domain is associated with established business operations "
160
+ "and maintains positive reputation across security feeds.",
161
+ "Extended analysis confirms the domain's legitimacy through multiple verification "
162
+ "vectors: established business registration, valid SSL certificates from trusted CAs, "
163
+ "consistent DNS records matching known infrastructure, and presence on multiple "
164
+ "reputation allowlists. No connections to threat actors, malware hosting, or "
165
+ "phishing infrastructure have been identified through any source."
166
+ ),
167
+ "Unknown": (
168
+ "Insufficient information is currently available to render a definitive assessment "
169
+ "for this domain. The limited intelligence coverage prevents confident classification. "
170
+ "Additional data collection and monitoring are required before reaching conclusions.",
171
+ "This domain lacks sufficient historical and technical context for thorough evaluation. "
172
+ "Key data sources report no findings, which may indicate recent registration, low "
173
+ "visibility, or simply gaps in intelligence coverage. Continued observation over time "
174
+ "will enable more accurate classification as behavioral patterns emerge."
175
+ )
176
+ }
177
+
178
+ return summaries.get(verdict, summaries["Unknown"])
179
+
180
+ def generate_evidence_list(verdict: str) -> List[Dict]:
181
+ """Generate evidence items supporting the verdict"""
182
+ evidence_pool = {
183
+ "Malicious": [
184
+ {"type": "DNS", "description": "Domain resolves to IP 185.234.72.14 - documented C2 node in threat feeds", "source": "Passive DNS", "weight": 0.95},
185
+ {"type": "Reputation", "description": "Blocked by 3 major threat intel providers for malware distribution", "source": "Reputation Feed", "weight": 0.90},
186
+ {"type": "Web", "description": "Historical content shows redirection to credential harvesting pages", "source": "URL Scanner", "weight": 0.88},
187
+ {"type": "WHOIS", "description": "Registration data matches previously identified APT infrastructure pattern", "source": "WHOIS DB", "weight": 0.75},
188
+ {"type": "SSL", "description": "Certificate issued by suspicious CA with known malicious history", "source": "Cert Transparency", "weight": 0.82}
189
+ ],
190
+ "Suspicious": [
191
+ {"type": "DNS", "description": "Uses dynamic DNS provider commonly abused by threat actors", "source": "Passive DNS", "weight": 0.70},
192
+ {"type": "WHOIS", "description": "Registration through privacy protection service", "source": "WHOIS DB", "weight": 0.60},
193
+ {"type": "Reputation", "description": "Flagged by 1 source for suspicious activity patterns", "source": "Reputation Feed", "weight": 0.55},
194
+ {"type": "Infrastructure", "description": "Hosted on AS with history of abuse complaints", "source": "BGP View", "weight": 0.50},
195
+ {"type": "Web", "description": "Minimal historical web content available", "source": "Web Search", "weight": 0.40}
196
+ ],
197
+ "Benign": [
198
+ {"type": "DNS", "description": "Stable DNS records matching legitimate hosting infrastructure", "source": "Passive DNS", "weight": 0.95},
199
+ {"type": "Reputation", "description": "Clean status across all major security feeds", "source": "Reputation Feed", "weight": 0.98},
200
+ {"type": "WHOIS", "description": "Verified business registration with valid contact information", "source": "WHOIS DB", "weight": 0.90},
201
+ {"type": "SSL", "description": "Valid certificate from established Certificate Authority", "source": "Cert Transparency", "weight": 0.95},
202
+ {"type": "Web", "description": "Consistent business website and active services", "source": "URL Scanner", "weight": 0.92}
203
+ ],
204
+ "Unknown": [
205
+ {"type": "DNS", "description": "No historical DNS records available", "source": "Passive DNS", "weight": 0.30},
206
+ {"type": "WHOIS", "description": "Insufficient registration data for analysis", "source": "WHOIS DB", "weight": 0.25},
207
+ {"type": "Reputation", "description": "No reputation data available from major feeds", "source": "Reputation Feed", "weight": 0.20},
208
+ {"type": "Web", "description": "Unable to retrieve web content for analysis", "source": "Web Search", "weight": 0.15}
209
+ ]
210
+ }
211
+
212
+ available = evidence_pool.get(verdict, evidence_pool["Unknown"])
213
+ num_evidence = random.randint(3, min(5, len(available)))
214
+ selected = random.sample(available, num_evidence)
215
+
216
+ for item in selected:
217
+ item["id"] = hashlib.md5(item["description"].encode()).hexdigest()[:8]
218
+
219
+ return selected
220
+
221
+ def generate_web_exposure(verdict: str) -> List[Dict]:
222
+ """Generate web search and open source exposure results"""
223
+ results = [
224
+ {"title": "Security Research Report on Infrastructure", "source": "BleepingComputer", "date": "2024-01-15", "classification": "Relevant"},
225
+ {"title": "Community Discussion - Is this domain safe?", "source": "Reddit", "date": "2024-01-10", "classification": "Informational"},
226
+ {"title": "VirusTotal Community Analysis", "source": "VirusTotal", "date": "2024-01-08", "classification": "Relevant"},
227
+ {"title": "Domain WHOIS Lookup Result", "source": "Whois365", "date": "2024-01-05", "classification": "Clean"},
228
+ {"title": "Archived Website Snapshot", "source": "Wayback Machine", "date": "2023-12-20", "classification": "Informational"}
229
+ ]
230
+
231
+ if verdict == "Malicious":
232
+ results.extend([
233
+ {"title": "Threat Actor Profile - Domain Listed", "source": "AlienVault OTX", "date": "2024-01-12", "classification": "Suspicious"},
234
+ {"title": "Phishing Campaign Analysis", "source": "KrebsOnSecurity", "date": "2024-01-14", "classification": "Relevant"}
235
+ ])
236
+
237
+ return results[:7]
238
+
239
+ def generate_attribution_data(domain: str) -> Dict:
240
+ """Generate attribution and relationship data"""
241
+ return {
242
+ "domain": domain,
243
+ "ip_addresses": [
244
+ {"ip": "185.234.72.14", "asn": "AS207713", "country": "RU", "relationship": "hosts"},
245
+ {"ip": "91.219.236.166", "asn": "AS49349", "country": "NL", "relationship": "hosts"}
246
+ ],
247
+ "nameservers": [
248
+ {"ns": "ns1.cloudns.net", "relationship": "uses"},
249
+ {"ns": "ns2.cloudns.net", "relationship": "uses"}
250
+ ],
251
+ "related_domains": [
252
+ {"domain": "malware-payload.net", "relationship": "sibling", "malicious": True},
253
+ {"domain": "phishing-target.org", "relationship": "target", "malicious": True},
254
+ {"domain": "c2-collector.com", "relationship": "sibling", "malicious": True}
255
+ ],
256
+ "threat_actors": [
257
+ {"name": "APT28", "relationship": "linked", "confidence": 0.85},
258
+ {"name": "Sandworm", "relationship": "linked", "confidence": 0.72}
259
+ ]
260
+ }
261
+
262
+ def generate_technical_data(domain: str) -> Dict:
263
+ """Generate technical enrichment data"""
264
+ return {
265
+ "dns": {
266
+ "A": ["185.234.72.14", "91.219.236.166"],
267
+ "AAAA": ["2a04:52c0:1014::14"],
268
+ "MX": ["mail." + domain],
269
+ "NS": ["ns1.cloudns.net", "ns2.cloudns.net", "ns3.cloudns.net"],
270
+ "TXT": ["v=spf1 include:_spf.google.com ~all", "google-site-verification=xxx"],
271
+ "SOA": ["ns1.cloudns.net. admin." + domain + ". 2024011501 7200 3600 1209600 86400"]
272
+ },
273
+ "whois": {
274
+ "registrar": "CloudNs",
275
+ "registrant_name": "REDACTED FOR PRIVACY",
276
+ "registrant_org": "Private Person",
277
+ "registrant_country": "RU",
278
+ "creation_date": "2023-06-15",
279
+ "expiration_date": "2025-06-15",
280
+ "updated_date": "2024-01-10",
281
+ "nameservers": ["ns1.cloudns.net", "ns2.cloudns.net"]
282
+ },
283
+ "reputation": {
284
+ "spam_score": random.randint(0, 30),
285
+ "phishing_score": random.randint(0, 50),
286
+ "malware_score": random.randint(0, 70),
287
+ "overall_score": random.randint(20, 80),
288
+ "blocklist_count": random.randint(0, 5),
289
+ "last_roboxed": (datetime.now() - timedelta(days=random.randint(1, 30))).strftime("%Y-%m-%d")
290
+ }
291
+ }
292
+
293
+ def get_verdict_color(verdict: str) -> str:
294
+ """Get color scheme for verdict"""
295
+ colors = {
296
+ "Malicious": "#dc3545",
297
+ "Suspicious": "#ffc107",
298
+ "Benign": "#28a745",
299
+ "Unknown": "#6c757d",
300
+ "Clean": "#28a745",
301
+ "No Data": "#adb5bd",
302
+ "Establishing": "#17a2b8"
303
+ }
304
+ return colors.get(verdict, "#6c757d")
305
+
306
+ def get_classification_color(classification: str) -> str:
307
+ """Get color for classification badge"""
308
+ colors = {
309
+ "Relevant": "#dc3545",
310
+ "Suspicious": "#ffc107",
311
+ "Informational": "#17a2b8",
312
+ "Clean": "#28a745"
313
+ }
314
+ return colors.get(classification, "#6c757d")
315
+
316
+ def create_relationship_graph(data: Dict) -> str:
317
+ """Create network visualization for relationships"""
318
+ import networkx as nx
319
+
320
+ G = nx.Graph()
321
+
322
+ # Add center node
323
+ center = data["domain"]
324
+ G.add_node(center, label=center, color="#6366f1", size=30)
325
+
326
+ # Add IP addresses
327
+ for ip in data["ip_addresses"]:
328
+ G.add_node(ip["ip"], label=ip["ip"], color="#f59e0b", size=20)
329
+ G.add_edge(center, ip["ip"], label=ip["relationship"])
330
+
331
+ # Add nameservers
332
+ for ns in data["nameservers"]:
333
+ G.add_node(ns["ns"], label=ns["ns"], color="#10b981", size=15)
334
+ G.add_edge(center, ns["ns"], label=ns["relationship"])
335
+
336
+ # Add related domains
337
+ for rd in data["related_domains"]:
338
+ color = "#ef4444" if rd["malicious"] else "#6b7280"
339
+ G.add_node(rd["domain"], label=rd["domain"], color=color, size=18)
340
+ G.add_edge(center, rd["domain"], label=rd["relationship"])
341
+
342
+ # Add threat actors
343
+ for ta in data["threat_actors"]:
344
+ G.add_node(ta["name"], label=f"{ta['name']} ({ta['confidence']*100:.0f}%)", color="#ec4899", size=22)
345
+ G.add_edge(center, ta["name"], label=ta["relationship"])
346
+
347
+ return G