Elffuss BraidHub

kikocis/osiris public

7ebe85210b60 · 46.2 KiBRawPermalink
1'use client';
2
3import { useState, useCallback, useEffect, memo } from 'react';
4import { motion, AnimatePresence } from 'framer-motion';
5import {
6 Search, Radar, Globe, Shield, FileText, Radio,
7 ChevronDown, ChevronUp, Loader2, AlertTriangle, Server,
8 Wifi, Lock, MapPin, Bug, Code, Layers, Network, Fingerprint,
9 CheckCircle, XCircle, Clock, ExternalLink, Crosshair,
10 Maximize2, Minimize2, Gavel
11} from 'lucide-react';
12
13const TABS = [
14 { id: 'scanner', label: 'PORT SCAN', icon: Radar, placeholder: 'IP or hostname', color: '#00E5FF' },
15 { id: 'vuln', label: 'VULN SWEEP', icon: Bug, placeholder: 'IP or hostname', color: '#FF3D3D' },
16
17 { id: 'dns', label: 'DNS', icon: Server, placeholder: 'Domain name', color: '#448AFF' },
18 { id: 'whois', label: 'WHOIS', icon: FileText, placeholder: 'Domain name', color: '#FFD700' },
19 { id: 'certs', label: 'CERTS', icon: Lock, placeholder: 'Domain name', color: '#E040FB' },
20 { id: 'threats', label: 'THREATS', icon: AlertTriangle, placeholder: 'IP, domain, or hash', color: '#FF9500' },
21 { id: 'headers', label: 'HEADERS', icon: Code, placeholder: 'URL to inspect', color: '#87CEEB' },
22 { id: 'ssl', label: 'SSL/TLS', icon: Shield, placeholder: 'Domain name', color: '#76FF03' },
23 { id: 'subdomains', label: 'SUBDOMAINS', icon: Layers, placeholder: 'Domain to enumerate', color: '#00BCD4' },
24 { id: 'tech', label: 'TECH DETECT', icon: Fingerprint, placeholder: 'URL to fingerprint', color: '#9C27B0' },
25 { id: 'sanctions', label: 'SANCTIONS', icon: Gavel, placeholder: 'Person / org / vessel name', color: '#FF1744' },
26 { id: 'sweep', label: 'IP SWEEP', icon: Crosshair, placeholder: 'Enter IP address (e.g. 8.8.8.8)', color: '#FF3D3D' },
27];
28
29interface OsintPanelProps { isOpen?: boolean; onClose?: () => void; isMobile?: boolean; onSweepVisualize?: (data: any) => void; onScanGeolocate?: (target: string, data: any) => void; }
30
31function OsintPanelInner({ isMobile, onSweepVisualize, onScanGeolocate }: OsintPanelProps) {
32 const [activeTab, setActiveTab] = useState('scanner');
33 const [isFullScreen, setIsFullScreen] = useState(false);
34 const [query, setQuery] = useState('');
35 const [results, setResults] = useState<any>(null);
36 const [loading, setLoading] = useState(false);
37 const [error, setError] = useState('');
38 const [scanType, setScanType] = useState('quick');
39 const [expanded, setExpanded] = useState(true);
40 const [history, setHistory] = useState<{tab:string;query:string;time:string}[]>([]);
41 const [sweepResult, setSweepResult] = useState<any>(null);
42 const [sweepProgress, setSweepProgress] = useState<{ current: number; total: number } | null>(null);
43 const [sweepCidr, setSweepCidr] = useState(24);
44 const [cveCache, setCveCache] = useState<Record<string, any>>({});
45 const [expandedDevice, setExpandedDevice] = useState<string | null>(null);
46
47 // Fetch CVE details when a device is expanded in full-screen mode
48 const fetchCveDetails = useCallback(async (cveIds: string[]) => {
49 const missing = cveIds.filter(id => !cveCache[id]);
50 if (missing.length === 0) return;
51 // Mark as loading
52 setCveCache(prev => {
53 const next = { ...prev };
54 for (const id of missing) next[id] = { loading: true };
55 return next;
56 });
57 // Fetch in parallel
58 const results = await Promise.allSettled(
59 missing.map(id => fetch(`/api/osint/cve?cve=${encodeURIComponent(id)}`).then(r => r.json()).then(data => ({ id, data })))
60 );
61 setCveCache(prev => {
62 const next = { ...prev };
63 for (const r of results) {
64 if (r.status === 'fulfilled') {
65 next[r.value.id] = r.value.data;
66 }
67 }
68 return next;
69 });
70 }, [cveCache]);
71
72 const runLookup = useCallback(async () => {
73 if (!query.trim() || loading) return;
74 setLoading(true); setError(''); setResults(null);
75
76 // IP Sweep / Vuln Scan — separate flow
77 if (activeTab === 'sweep' || activeTab === 'vuln') {
78 setSweepResult(null);
79 setSweepProgress({ current: 0, total: Math.pow(2, 32 - sweepCidr) });
80 try {
81 const cidr = sweepCidr;
82 const res = await fetch(`/api/osint/sweep?ip=${encodeURIComponent(query)}&cidr=${cidr}`);
83 if (!res.ok) { const e = await res.json().catch(() => ({})); throw new Error(e.error || `Sweep failed (${res.status})`); }
84 const data = await res.json();
85 setSweepResult(data);
86 setSweepProgress(null);
87 setHistory(prev => [{ tab: activeTab, query, time: new Date().toLocaleTimeString() }, ...prev.slice(0, 9)]);
88 } catch (err: any) {
89 setError(err.message);
90 setSweepProgress(null);
91 } finally {
92 setLoading(false);
93 }
94 return;
95 }
96
97 try {
98 let url = '';
99 switch (activeTab) {
100
101 case 'dns': url = `/api/osint/dns?domain=${encodeURIComponent(query)}`; break;
102 case 'certs': url = `/api/osint/certs?domain=${encodeURIComponent(query)}`; break;
103 case 'whois': url = `/api/osint/whois?domain=${encodeURIComponent(query)}`; break;
104 case 'threats': url = `/api/osint/threats?query=${encodeURIComponent(query)}`; break;
105 case 'scanner': url = `/api/scanner?target=${encodeURIComponent(query)}&type=${scanType}`; break;
106 case 'headers': url = `/api/scanner?target=${encodeURIComponent(query)}&type=headers`; break;
107 case 'ssl': url = `/api/scanner?target=${encodeURIComponent(query)}&type=ssl`; break;
108 case 'subdomains': url = `/api/scanner?target=${encodeURIComponent(query)}&type=subdomains`; break;
109 case 'tech': url = `/api/scanner?target=${encodeURIComponent(query)}&type=tech`; break;
110 case 'sanctions': url = `/api/osint/sanctions?query=${encodeURIComponent(query)}`; break;
111 }
112 const res = await fetch(url);
113 const data = await res.json();
114 if (res.ok) {
115 setResults(data);
116 setHistory(prev => [{ tab: activeTab, query, time: new Date().toLocaleTimeString() }, ...prev.slice(0, 9)]);
117
118 // Geolocate the target in the background
119 if (activeTab !== 'sweep' && activeTab !== 'vuln' && activeTab !== 'sanctions') {
120 fetch(`/api/osint/ip?ip=${encodeURIComponent(query)}`)
121 .then(r => r.json())
122 .then(locData => {
123 if (locData && locData.geo && locData.geo.lat && locData.geo.lon && onScanGeolocate) {
124 // ip-api returns lat/lon, we pass it up
125 onScanGeolocate(query, { lat: locData.geo.lat, lng: locData.geo.lon, ...locData, type: activeTab });
126 }
127 })
128 .catch(() => {});
129 }
130 } else {
131 setError(data.error || 'Lookup failed');
132 }
133 } catch { setError('Network error'); }
134 finally { setLoading(false); }
135 }, [query, activeTab, scanType, loading, sweepCidr]);
136
137 const currentTab = TABS.find(t => t.id === activeTab);
138
139 // ── Shodan-style structured result renderers ──
140
141 const ResultRow = ({ label, value, color, mono = true }: { label: string; value: any; color?: string; mono?: boolean }) => {
142 if (value === undefined || value === null || value === '') return null;
143 return (
144 <div className="flex items-start gap-3 py-1.5 border-b border-[var(--border-secondary)]/20 last:border-0">
145 <span className="text-[9px] font-mono text-[var(--text-muted)] uppercase tracking-wider w-[90px] flex-shrink-0 pt-0.5">{label}</span>
146 <span className={`text-[10px] ${mono ? 'font-mono' : ''} break-all flex-1`} style={{ color: color || 'var(--text-primary)' }}>
147 {String(value)}
148 </span>
149 </div>
150 );
151 };
152
153 const StatusBadge = ({ ok, label }: { ok: boolean; label: string }) => (
154 <span className={`inline-flex items-center gap-1 px-2 py-0.5 rounded text-[9px] font-mono font-bold ${ok ? 'bg-green-500/15 text-green-400 border border-green-500/30' : 'bg-red-500/15 text-red-400 border border-red-500/30'}`}>
155 {ok ? <CheckCircle className="w-2.5 h-2.5" /> : <XCircle className="w-2.5 h-2.5" />}
156 {label}
157 </span>
158 );
159
160 // Surfaces an inline OFAC-SDN hit (used by the WHOIS and IP-intel routes
161 // when their cross-check finds a sanctioned registrant / ASN owner).
162 const SanctionsBadge = ({ match }: { match: any }) => {
163 if (!match || !Array.isArray(match.hits) || match.hits.length === 0) return null;
164 return (
165 <div className="mb-2 px-2 py-2 rounded border border-red-500/40 bg-red-500/15">
166 <div className="flex items-center gap-2 mb-1.5">
167 <AlertTriangle className="w-3.5 h-3.5 text-red-400" />
168 <span className="text-[10px] font-mono font-bold text-red-400 tracking-wider">
169 SANCTIONED — {match.source || 'OFAC SDN'}
170 </span>
171 </div>
172 {match.hits.slice(0, 5).map((h: any, i: number) => (
173 <div key={i} className="text-[9px] font-mono text-red-200 break-all leading-tight">
174 <span className="text-[var(--text-muted)]">↳ {h.matched_value}:</span>{' '}
175 {(h.entries || []).slice(0, 2).map((e: any) => e.name).join('; ')}
176 </div>
177 ))}
178 </div>
179 );
180 };
181
182 const SectionHeader = ({ title, icon: Icon, color }: { title: string; icon: any; color: string }) => (
183 <div className="flex items-center gap-2 mt-3 mb-1.5 first:mt-0">
184 <Icon className="w-3.5 h-3.5" style={{ color }} />
185 <span className="text-[10px] font-mono font-bold tracking-widest" style={{ color }}>{title}</span>
186 <div className="flex-1 h-px" style={{ background: `${color}30` }} />
187 </div>
188 );
189
190 const PortRow = ({ port, state, service, version }: { port: number; state: string; service?: string; version?: string }) => (
191 <div className="flex items-center gap-2 py-1 px-2 rounded hover:bg-[var(--hover-accent)] transition-colors">
192 <span className="text-[11px] font-mono font-bold text-[var(--cyan-primary)] w-[60px]">{port}</span>
193 <StatusBadge ok={state === 'open'} label={state.toUpperCase()} />
194 <span className="text-[10px] font-mono text-[var(--text-secondary)] flex-1">{service || 'unknown'}</span>
195 {version && <span className="text-[9px] font-mono text-[var(--text-muted)]">{version}</span>}
196 </div>
197 );
198
199 const renderStructuredResults = () => {
200 if (!results) return null;
201 const r = results;
202
203 // ── PORT SCAN ──
204 if (activeTab === 'scanner') {
205 const ports = r.ports || r.open_ports || r.results || [];
206 const host = r.host || r.target || query;
207 return (
208 <div>
209 <SectionHeader title="HOST INFO" icon={Server} color="#00E5FF" />
210 <ResultRow label="Target" value={host} color="#00E5FF" />
211 <ResultRow label="Scan Type" value={r.scan_type || scanType} />
212 <ResultRow label="Duration" value={r.duration || r.scan_time} />
213 {Array.isArray(ports) && ports.length > 0 && (
214 <>
215 <SectionHeader title={`OPEN PORTS (${ports.length})`} icon={Wifi} color="#00E676" />
216 <div className="space-y-0.5">
217 {ports.map((p: any, i: number) => (
218 <PortRow key={i} port={p.port || p} state={p.state || 'open'} service={p.service || p.name} version={p.version} />
219 ))}
220 </div>
221 </>
222 )}
223 {(!Array.isArray(ports) || ports.length === 0) && renderFallback()}
224 </div>
225 );
226 }
227
228 // ── VULN SCAN ──
229 if (activeTab === 'vuln') {
230 const vulns = r.vulnerabilities || r.vulns || r.cves || [];
231 const exploits = vulns.filter((v: any) => v.is_exploit);
232 const regularVulns = vulns.filter((v: any) => !v.is_exploit);
233
234 return (
235 <div>
236 <SectionHeader title="VULNERABILITY ASSESSMENT" icon={Bug} color="#FF3D3D" />
237 <ResultRow label="Target" value={r.target || query} color="#FF3D3D" />
238 <ResultRow label="Total CVEs" value={Array.isArray(vulns) ? vulns.length : 0} color={Array.isArray(vulns) && vulns.length > 0 ? '#FF3D3D' : '#00E676'} />
239 <ResultRow label="Risk Level" value={r.risk_level || r.severity} />
240 {Array.isArray(regularVulns) && regularVulns.length > 0 && (
241 <div className="mt-2 space-y-1">
242 {regularVulns.slice(0, 20).map((v: any, i: number) => (
243 <div key={i} className="p-2 rounded-lg border border-red-500/20 bg-red-500/5 flex flex-col">
244 <div className="flex items-center justify-between">
245 <span className="text-[10px] font-mono font-bold text-red-400">{v.id || v.cve || v.name}</span>
246 {v.severity && <span className={`text-[8px] font-mono font-bold px-1.5 py-0.5 rounded ${v.severity === 'CRITICAL' ? 'bg-red-500/20 text-red-400' : v.severity === 'HIGH' ? 'bg-orange-500/20 text-orange-400' : 'bg-yellow-500/20 text-yellow-400'}`}>{v.severity}</span>}
247 </div>
248 {v.cvss && <div className="text-[9px] font-mono text-[var(--text-muted)] mt-1">CVSS: {v.cvss} ({v.type || 'cve'})</div>}
249 {v.description && <p className="text-[9px] font-mono text-[var(--text-muted)] mt-1 line-clamp-2">{v.description}</p>}
250 </div>
251 ))}
252 </div>
253 )}
254
255 {exploits.length > 0 && (
256 <div className="mt-4">
257 <SectionHeader title={`POSSIBLE EXPLOITS (${exploits.length})`} icon={AlertTriangle} color="#FF9500" />
258 <div className="mt-2 space-y-1">
259 {exploits.slice(0, 10).map((e: any, i: number) => (
260 <div key={i} className="p-2 rounded-lg border border-orange-500/30 bg-orange-500/10 flex flex-col">
261 <div className="flex items-center justify-between">
262 <span className="text-[10px] font-mono font-bold text-orange-400">{e.id}</span>
263 <span className="text-[8px] font-mono font-bold px-1.5 py-0.5 rounded bg-orange-500/20 text-orange-400">EXPLOIT</span>
264 </div>
265 <div className="text-[9px] font-mono text-[var(--text-muted)] mt-1 flex justify-between">
266 <span>Source: {e.type?.toUpperCase() || 'UNKNOWN'}</span>
267 {e.cvss && <span>CVSS: {e.cvss}</span>}
268 </div>
269 </div>
270 ))}
271 </div>
272 </div>
273 )}
274
275 {(!Array.isArray(vulns) || vulns.length === 0) && renderFallback()}
276 </div>
277 );
278 }
279
280
281
282 // ── DNS ──
283 if (activeTab === 'dns') {
284 return (
285 <div>
286 <SectionHeader title="DNS RECORDS" icon={Server} color="#448AFF" />
287 <ResultRow label="Domain" value={r.domain || query} color="#448AFF" />
288 {r.A && <ResultRow label="A Records" value={Array.isArray(r.A) ? r.A.join(', ') : r.A} />}
289 {r.AAAA && <ResultRow label="AAAA" value={Array.isArray(r.AAAA) ? r.AAAA.join(', ') : r.AAAA} />}
290 {r.MX && <ResultRow label="MX" value={Array.isArray(r.MX) ? r.MX.map((m:any) => m.exchange || m).join(', ') : r.MX} />}
291 {r.NS && <ResultRow label="NS" value={Array.isArray(r.NS) ? r.NS.join(', ') : r.NS} />}
292 {r.TXT && <ResultRow label="TXT" value={Array.isArray(r.TXT) ? r.TXT.join(' | ') : r.TXT} />}
293 {r.CNAME && <ResultRow label="CNAME" value={Array.isArray(r.CNAME) ? r.CNAME.join(', ') : r.CNAME} />}
294 {r.SOA && <ResultRow label="SOA" value={typeof r.SOA === 'object' ? `${r.SOA.nsname} (${r.SOA.hostmaster})` : r.SOA} />}
295 {renderFallbackExcluding(['domain','A','AAAA','MX','NS','TXT','CNAME','SOA','timestamp','cached'])}
296 </div>
297 );
298 }
299
300 // ── WHOIS ──
301 if (activeTab === 'whois') {
302 return (
303 <div>
304 <SectionHeader title="WHOIS INTELLIGENCE" icon={FileText} color="#FFD700" />
305 <SanctionsBadge match={r.sanctions_match} />
306 <ResultRow label="Domain" value={r.domain_name || r.domainName || query} color="#FFD700" />
307 <ResultRow label="Registrar" value={r.registrar} />
308 <ResultRow label="Created" value={r.creation_date || r.createdDate} />
309 <ResultRow label="Expires" value={r.expiration_date || r.expiresDate} />
310 <ResultRow label="Updated" value={r.updated_date || r.updatedDate} />
311 <ResultRow label="Status" value={Array.isArray(r.status) ? r.status.join(', ') : r.status} />
312 <ResultRow label="Nameservers" value={Array.isArray(r.name_servers || r.nameServers) ? (r.name_servers || r.nameServers).join(', ') : r.name_servers} />
313 {renderFallbackExcluding(['domain_name','domainName','registrar','creation_date','createdDate','expiration_date','expiresDate','updated_date','updatedDate','status','name_servers','nameServers','timestamp','cached','raw','sanctions_match'])}
314 </div>
315 );
316 }
317
318 // ── SANCTIONS ──
319 if (activeTab === 'sanctions') {
320 const matches = Array.isArray(r.matches) ? r.matches : [];
321 return (
322 <div>
323 <SectionHeader title="OFAC SDN SEARCH" icon={Gavel} color="#FF1744" />
324 <ResultRow label="Query" value={r.query || query} color="#FF1744" />
325 <ResultRow label="Source" value={r.source} />
326 <ResultRow label="Matches" value={r.total ?? matches.length} color={matches.length ? '#FF1744' : '#00E676'} />
327 {matches.slice(0, 20).map((m: any) => (
328 <div key={m.id} className="mt-2 p-2 rounded border border-red-500/30 bg-red-500/5">
329 <div className="flex items-center justify-between mb-1">
330 <span className="text-[10px] font-mono font-bold text-red-400 break-all">{m.name}</span>
331 <span className="text-[8px] font-mono uppercase tracking-wider text-[var(--text-muted)] ml-2 flex-shrink-0">{m.schema}</span>
332 </div>
333 <ResultRow label="Aliases" value={Array.isArray(m.aliases) && m.aliases.length ? m.aliases.slice(0, 4).join(' • ') : undefined} />
334 <ResultRow label="Countries" value={Array.isArray(m.countries) && m.countries.length ? m.countries.join(', ').toUpperCase() : undefined} />
335 <ResultRow label="Programs" value={Array.isArray(m.programs) && m.programs.length ? m.programs.slice(0, 3).join(', ') : undefined} />
336 <ResultRow label="First Seen" value={m.first_seen ? m.first_seen.slice(0, 10) : undefined} />
337 </div>
338 ))}
339 {matches.length === 0 && (
340 <div className="mt-2 px-2 py-1.5 text-[10px] font-mono text-green-400">No OFAC SDN matches for that query.</div>
341 )}
342 </div>
343 );
344 }
345
346 // ── CERTS ──
347 if (activeTab === 'certs') {
348 const certs = r.certificates || r.certs || (Array.isArray(r) ? r : []);
349 return (
350 <div>
351 <SectionHeader title="CERTIFICATE TRANSPARENCY" icon={Lock} color="#E040FB" />
352 <ResultRow label="Domain" value={query} color="#E040FB" />
353 <ResultRow label="Certificates" value={Array.isArray(certs) ? certs.length : 0} />
354 {Array.isArray(certs) && certs.slice(0, 15).map((c: any, i: number) => (
355 <div key={i} className="mt-1.5 p-2 rounded border border-[var(--border-secondary)]/30 bg-[var(--bg-tertiary)]/30">
356 <ResultRow label="Issuer" value={c.issuer_name || c.issuer} />
357 <ResultRow label="Common Name" value={c.common_name || c.name_value} />
358 <ResultRow label="Not Before" value={c.not_before} />
359 <ResultRow label="Not After" value={c.not_after} />
360 </div>
361 ))}
362 {(!Array.isArray(certs) || certs.length === 0) && renderFallback()}
363 </div>
364 );
365 }
366
367 // ── THREATS ──
368 if (activeTab === 'threats') {
369 return (
370 <div>
371 <SectionHeader title="THREAT INTELLIGENCE" icon={AlertTriangle} color="#FF9500" />
372 <ResultRow label="Query" value={query} color="#FF9500" />
373 <ResultRow label="Risk Score" value={r.risk_score || r.score} color={
374 (r.risk_score || r.score || 0) > 70 ? '#FF3D3D' : (r.risk_score || r.score || 0) > 40 ? '#FF9500' : '#00E676'
375 } />
376 <ResultRow label="Malicious" value={r.malicious !== undefined ? (r.malicious ? 'YES' : 'NO') : undefined} color={r.malicious ? '#FF3D3D' : '#00E676'} />
377 <ResultRow label="Category" value={r.category || r.type} />
378 <ResultRow label="Reports" value={r.total_reports || r.reports} />
379 <ResultRow label="Last Seen" value={r.last_seen || r.last_analysis} />
380 {r.tags && <ResultRow label="Tags" value={Array.isArray(r.tags) ? r.tags.join(', ') : r.tags} />}
381 {renderFallbackExcluding(['risk_score','score','malicious','category','type','total_reports','reports','last_seen','last_analysis','tags','timestamp','cached','query'])}
382 </div>
383 );
384 }
385
386 // ── SSL ──
387 if (activeTab === 'ssl') {
388 return (
389 <div>
390 <SectionHeader title="SSL/TLS ANALYSIS" icon={Shield} color="#76FF03" />
391 <ResultRow label="Target" value={query} color="#76FF03" />
392 <ResultRow label="Protocol" value={r.protocol || r.tls_version} />
393 <ResultRow label="Cipher" value={r.cipher || r.cipher_suite} />
394 <ResultRow label="Valid" value={r.valid !== undefined ? (r.valid ? 'YES' : 'NO') : undefined} color={r.valid ? '#00E676' : '#FF3D3D'} />
395 <ResultRow label="Issuer" value={r.issuer} />
396 <ResultRow label="Subject" value={r.subject} />
397 <ResultRow label="Expires" value={r.expires || r.not_after} />
398 <ResultRow label="SANs" value={Array.isArray(r.sans) ? r.sans.join(', ') : r.sans} />
399 {renderFallback()}
400 </div>
401 );
402 }
403
404 // Fallback for other tools
405 return renderFallback();
406 };
407
408 const renderFallback = () => {
409 if (!results) return null;
410 return (
411 <div className="space-y-1">
412 {Object.entries(results).filter(([k]) => !['timestamp','cached'].includes(k)).map(([key, value]) => (
413 <ResultRow key={key} label={key.replace(/_/g, ' ')} value={typeof value === 'object' ? JSON.stringify(value, null, 1) : String(value)} />
414 ))}
415 </div>
416 );
417 };
418
419 const renderFallbackExcluding = (exclude: string[]) => {
420 if (!results) return null;
421 const extra = Object.entries(results).filter(([k]) => !exclude.includes(k));
422 if (extra.length === 0) return null;
423 return (
424 <div className="mt-2 space-y-1">
425 {extra.map(([key, value]) => (
426 <ResultRow key={key} label={key.replace(/_/g, ' ')} value={typeof value === 'object' ? JSON.stringify(value, null, 1) : String(value)} />
427 ))}
428 </div>
429 );
430 };
431
432 const renderContent = () => (
433 <div className="flex flex-col gap-2.5">
434 {/* Tool Grid */}
435 <div className="flex flex-col gap-1">
436 {/* Sweep - Main Action */}
437 {TABS.filter(t => t.id === 'sweep').map(tab => (
438 <button key={tab.id} onClick={() => { setActiveTab(tab.id); setQuery(''); setResults(null); setError(''); }}
439 className={`flex items-center justify-center gap-2 px-3 py-3 rounded-lg text-[12px] font-mono tracking-widest font-bold transition-all border ${activeTab === tab.id ? 'border-opacity-60 bg-opacity-20' : 'border-[var(--border-secondary)] hover:bg-[var(--hover-accent)]'}`}
440 style={{
441 borderColor: activeTab === tab.id ? tab.color : 'rgba(255,61,61,0.3)',
442 backgroundColor: activeTab === tab.id ? `${tab.color}20` : 'rgba(255,61,61,0.05)',
443 color: activeTab === tab.id ? tab.color : tab.color,
444 boxShadow: activeTab === tab.id ? `0 0 15px ${tab.color}30` : 'none'
445 }}>
446 <tab.icon className="w-5 h-5" />
447 <span>GLOBAL {tab.label}</span>
448 </button>
449 ))}
450 {/* Other Tools */}
451 <div className="grid grid-cols-5 gap-1 mt-1">
452 {TABS.filter(t => t.id !== 'sweep').map(tab => (
453 <button key={tab.id} onClick={() => { setActiveTab(tab.id); setQuery(''); setResults(null); setError(''); }}
454 className={`flex flex-col items-center gap-1 px-1 py-2 rounded-lg text-[8px] font-mono tracking-wider transition-all border ${activeTab === tab.id ? 'border-opacity-40 bg-opacity-15' : 'border-transparent hover:bg-[var(--hover-accent)]'}`}
455 style={{ borderColor: activeTab === tab.id ? tab.color : 'transparent', backgroundColor: activeTab === tab.id ? `${tab.color}15` : undefined, color: activeTab === tab.id ? tab.color : 'var(--text-muted)' }}>
456 <tab.icon className="w-3.5 h-3.5" />
457 <span className="leading-none text-center truncate w-full">{tab.label}</span>
458 </button>
459 ))}
460 </div>
461 </div>
462
463 {/* Input Area */}
464 <div className="flex flex-col gap-1.5">
465 <div className="flex gap-1.5">
466 <div className="flex-1 relative">
467 <Search className="absolute left-2.5 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-[var(--text-muted)]" />
468 <input type="text" value={query} onChange={e => setQuery(e.target.value)} onKeyDown={e => e.key === 'Enter' && runLookup()}
469 placeholder={currentTab?.placeholder}
470 className="w-full bg-[var(--bg-primary)]/60 border border-[var(--border-primary)] rounded-lg pl-8 pr-3 py-2.5 text-[11px] font-mono text-[var(--text-primary)] placeholder:text-[var(--text-muted)]/40 focus:outline-none transition-colors"
471 style={{ borderColor: query ? `${currentTab?.color}40` : undefined }} />
472 </div>
473 <button onClick={runLookup} disabled={loading || !query.trim()}
474 className="px-4 py-2 rounded-lg text-[10px] font-mono font-bold tracking-wider disabled:opacity-30 transition-all flex items-center justify-center min-w-[70px]"
475 style={{ backgroundColor: `${currentTab?.color}20`, border: `1px solid ${currentTab?.color}40`, color: currentTab?.color }}>
476 {loading ? <Loader2 className="w-3.5 h-3.5 animate-spin" /> : 'SCAN'}
477 </button>
478 </div>
479
480 {/* Secondary Controls */}
481 {activeTab === 'scanner' && (
482 <select value={scanType} onChange={e => setScanType(e.target.value)}
483 className="bg-[var(--bg-primary)]/60 border border-[var(--border-primary)] rounded-lg px-2 py-1.5 text-[10px] font-mono text-[var(--text-muted)] outline-none w-full">
484 <option value="quick">QUICK SCAN</option><option value="deep">DEEP SCAN</option><option value="ports">TOP 1000 PORTS</option>
485 </select>
486 )}
487 {(activeTab === 'sweep' || activeTab === 'vuln') && (
488 <div className="flex items-center justify-between bg-[var(--bg-primary)]/60 border border-[var(--border-primary)] rounded-lg p-1">
489 <span className="text-[9px] font-mono text-[var(--text-muted)] pl-2">SUBNET MASK:</span>
490 <div className="flex items-center gap-0.5">
491 {[24, 25, 26, 27, 28].map(c => (
492 <button key={c} onClick={() => setSweepCidr(c)}
493 className={`px-2 py-1 text-[10px] font-mono rounded transition-all ${
494 sweepCidr === c ? 'bg-[#FF3D3D]/20 text-[#FF3D3D]' : 'text-[var(--text-muted)] hover:bg-[var(--bg-tertiary)]'
495 }`}
496 >/{c}</button>
497 ))}
498 </div>
499 </div>
500 )}
501 </div>
502
503 {error && (
504 <div className="p-2.5 rounded-lg border border-red-500/30 bg-red-500/10 text-[11px] font-mono text-red-400 flex items-center gap-2">
505 <AlertTriangle className="w-3.5 h-3.5 flex-shrink-0" />{error}
506 </div>
507 )}
508
509 {/* Sweep Progress */}
510 {sweepProgress && loading && (
511 <div className="p-3 rounded-lg border border-[#FF3D3D]/30 bg-[#FF3D3D]/5">
512 <div className="flex items-center justify-between mb-2">
513 <span className="text-[10px] font-mono tracking-wider text-[#FF3D3D]">SWEEPING SUBNET...</span>
514 <span className="text-[10px] font-mono text-[#E8E6E0]">{sweepProgress.total} hosts</span>
515 </div>
516 <div className="w-full h-1.5 bg-[#1A1A18] rounded-full overflow-hidden">
517 <div className="h-full rounded-full" style={{ width: '100%', background: 'linear-gradient(90deg, #FF3D3D, #FF6B00, #FFD700)', animation: 'sweep-pulse 1.5s ease-in-out infinite' }} />
518 </div>
519 </div>
520 )}
521
522 {/* Sweep Results */}
523 {sweepResult && !loading && (
524 <div className="bg-[var(--bg-primary)]/40 border border-[var(--border-primary)] rounded-lg overflow-hidden max-h-[55vh] overflow-y-auto styled-scrollbar">
525 {/* Summary */}
526 <div className="p-3 border-b border-[#2A2A28]">
527 <div className="flex items-center justify-between mb-3">
528 <div>
529 <div className="text-[11px] font-mono tracking-wider text-[#E8E6E0]">{sweepResult.subnet}</div>
530 <div className="text-[9px] font-mono text-[#5C5A54]">{sweepResult.center.city}, {sweepResult.center.country} · {sweepResult.center.isp}</div>
531 </div>
532 <div className="text-right">
533 <div className="text-[18px] font-mono font-bold text-[#FF3D3D]">{sweepResult.summary.total_responsive}</div>
534 <div className="text-[8px] font-mono text-[#5C5A54] tracking-wider">DEVICES FOUND</div>
535 </div>
536 </div>
537 {/* Breakdown Bar */}
538 <div className="flex h-2 rounded-full overflow-hidden bg-[#1A1A18] mb-2">
539 {Object.entries(sweepResult.summary.device_breakdown).map(([type, count]: [string, any]) => {
540 const device = sweepResult.devices.find((d: any) => d.device_type === type);
541 return <div key={type} style={{ width: `${(count / sweepResult.summary.total_responsive) * 100}%`, backgroundColor: device?.device_color || '#666' }} title={`${type}: ${count}`} />;
542 })}
543 </div>
544 <div className="flex flex-wrap gap-x-3 gap-y-1">
545 {Object.entries(sweepResult.summary.device_breakdown).map(([type, count]: [string, any]) => {
546 const device = sweepResult.devices.find((d: any) => d.device_type === type);
547 return (
548 <div key={type} className="flex items-center gap-1">
549 <div className="w-2 h-2 rounded-full" style={{ backgroundColor: device?.device_color || '#666' }} />
550 <span className="text-[9px] font-mono text-[#8A8880]">{type}</span>
551 <span className="text-[9px] font-mono text-[#E8E6E0] font-bold">{String(count)}</span>
552 </div>
553 );
554 })}
555 </div>
556 </div>
557 {/* Visualize Button */}
558 <div className="p-3 border-b border-[#2A2A28]">
559 <button onClick={() => onSweepVisualize?.(sweepResult)}
560 className="w-full py-2.5 rounded-lg font-mono text-[11px] tracking-wider font-bold transition-all hover:scale-[1.02] active:scale-[0.98] flex items-center justify-center gap-2"
561 style={{ background: 'linear-gradient(135deg, rgba(255,61,61,0.2), rgba(255,107,0,0.2))', border: '1px solid rgba(255,61,61,0.5)', color: '#FF3D3D', textShadow: '0 0 10px rgba(255,61,61,0.5)' }}
562 >
563 <Globe className="w-4 h-4" /> VISUALIZE ON GLOBE
564 </button>
565 </div>
566 {/* Device List */}
567 <div className={isFullScreen ? "flex flex-col gap-3 p-4" : "divide-y divide-[#2A2A28]"}>
568 {sweepResult.devices.map((device: any) => {
569 const isExpanded = expandedDevice === device.ip;
570 return (
571 <div key={device.ip} className={isFullScreen
572 ? "bg-[#0D0D0C] border border-[#2A2A28] rounded-lg overflow-hidden hover:border-[#3A3A38] transition-colors"
573 : "px-3 py-2.5 hover:bg-[rgba(255,255,255,0.02)] transition-colors"
574 }>
575 {/* Device Header */}
576 <div
577 className={isFullScreen
578 ? "flex items-center justify-between px-4 py-3 cursor-pointer hover:bg-[#151514] transition-colors"
579 : "flex items-center justify-between mb-1"
580 }
581 onClick={() => {
582 if (!isFullScreen) return;
583 const next = isExpanded ? null : device.ip;
584 setExpandedDevice(next);
585 if (next && device.vulns.length > 0) fetchCveDetails(device.vulns);
586 }}
587 >
588 <div className="flex items-center gap-3">
589 <div className="w-2.5 h-2.5 rounded-full flex-shrink-0" style={{ backgroundColor: device.device_color }} />
590 <span className={isFullScreen ? "text-[14px] font-mono font-bold text-[#E8E6E0]" : "text-[11px] font-mono text-[#E8E6E0]"}>{device.ip}</span>
591 {device.hostnames.length > 0 && (
592 <span className={`${isFullScreen ? "text-[11px]" : "text-[9px]"} font-mono text-[#5C5A54]`}>{device.hostnames[0]}</span>
593 )}
594 </div>
595 <div className="flex items-center gap-2">
596 {device.vulns.length > 0 && (
597 <span className={`${isFullScreen ? "text-[10px]" : "text-[8px]"} font-mono px-1.5 py-0.5 rounded bg-red-500/15 text-red-400 border border-red-500/30`}>
598 {device.vulns.length} CVEs
599 </span>
600 )}
601 <span className={`${isFullScreen ? "text-[10px]" : "text-[8px]"} font-mono px-1.5 py-0.5 rounded`} style={{ backgroundColor: device.device_color + '20', color: device.device_color, border: `1px solid ${device.device_color}40` }}>{device.device_type}</span>
602 {isFullScreen && (
603 <ChevronDown className={`w-4 h-4 text-[#5C5A54] transition-transform ${isExpanded ? 'rotate-180' : ''}`} />
604 )}
605 </div>
606 </div>
607
608 {/* Compact info (sidebar mode) */}
609 {!isFullScreen && (
610 <>
611 <div className="flex items-center gap-2 text-[9px] font-mono text-[#5C5A54]">
612 <span>Ports: {device.ports.slice(0, 8).join(', ')}{device.ports.length > 8 ? ` +${device.ports.length - 8}` : ''}</span>
613 {device.vulns.length > 0 && (
614 <div className="group relative flex items-center gap-1 cursor-help">
615 <span className="text-[#FF3D3D] flex items-center gap-1">
616 <AlertTriangle className="w-2.5 h-2.5" /> {device.vulns.length} CVEs
617 </span>
618 <div className="absolute bottom-full left-0 mb-1 hidden group-hover:block z-50 p-2 bg-[#1A1A18] border border-[#FF3D3D50] rounded-md shadow-xl min-w-[140px] max-w-[220px] max-h-[150px] overflow-y-auto styled-scrollbar">
619 <div className="text-[8px] font-mono text-[#FF3D3D] mb-1 tracking-wider uppercase border-b border-[#FF3D3D30] pb-1">Identified Vulnerabilities</div>
620 <div className="flex flex-col gap-0.5">
621 {device.vulns.map((cve: string) => (
622 <a key={cve} href={`https://nvd.nist.gov/vuln/detail/${cve}`} target="_blank" rel="noreferrer" className="text-[9px] font-mono text-[#E8E6E0] hover:text-[#FF3D3D] transition-colors truncate">
623 {cve}
624 </a>
625 ))}
626 </div>
627 </div>
628 </div>
629 )}
630 </div>
631 {device.hostnames.length > 0 && <div className="text-[9px] font-mono text-[#8A8880] mt-0.5 truncate">{device.hostnames[0]}</div>}
632 </>
633 )}
634
635 {/* Full-Screen Expanded Detail */}
636 {isFullScreen && isExpanded && (
637 <div className="border-t border-[#2A2A28]">
638 {/* Ports + Hostnames Row */}
639 <div className="grid grid-cols-1 md:grid-cols-2 gap-px bg-[#2A2A28]">
640 <div className="bg-[#0D0D0C] p-4">
641 <div className="text-[10px] font-mono text-[#5C5A54] tracking-widest uppercase mb-2">Open Ports</div>
642 <div className="flex flex-wrap gap-1.5">
643 {device.ports.map((port: number) => (
644 <span key={port} className="px-2 py-1 bg-[#1A1A18] border border-[#2A2A28] rounded text-[11px] font-mono text-[var(--cyan-primary)]">{port}</span>
645 ))}
646 </div>
647 </div>
648 <div className="bg-[#0D0D0C] p-4">
649 <div className="text-[10px] font-mono text-[#5C5A54] tracking-widest uppercase mb-2">Hostnames</div>
650 {device.hostnames.length > 0 ? (
651 <div className="flex flex-col gap-1">
652 {device.hostnames.map((h: string) => (
653 <span key={h} className="text-[11px] font-mono text-[#E8E6E0]">{h}</span>
654 ))}
655 </div>
656 ) : (
657 <span className="text-[11px] font-mono text-[#3A3A38]">No reverse DNS</span>
658 )}
659 </div>
660 </div>
661
662 {/* CVE Intelligence */}
663 {device.vulns.length > 0 && (
664 <div className="p-4 border-t border-[#2A2A28]">
665 <div className="text-[10px] font-mono text-[#5C5A54] tracking-widest uppercase mb-3">Vulnerabilities ({device.vulns.length})</div>
666 <div className="flex flex-col gap-2">
667 {device.vulns.map((cveId: string) => {
668 const info = cveCache[cveId];
669 const isLoading = !info || info.loading;
670 const severityColor = !info?.severity ? '#5C5A54'
671 : info.severity === 'CRITICAL' ? '#FF3D3D'
672 : info.severity === 'HIGH' ? '#FF6B00'
673 : info.severity === 'MEDIUM' ? '#FFD700'
674 : '#76FF03';
675 return (
676 <div key={cveId} className="bg-[#111] border border-[#2A2A28] rounded-lg p-3">
677 <div className="flex items-center justify-between mb-2">
678 <div className="flex items-center gap-2">
679 <span className="text-[12px] font-mono font-bold text-[#E8E6E0]">{cveId}</span>
680 {info?.cvss != null && (
681 <span className="text-[10px] font-mono px-1.5 py-0.5 rounded" style={{ backgroundColor: severityColor + '15', color: severityColor, border: `1px solid ${severityColor}40` }}>CVSS {info.cvss}</span>
682 )}
683 </div>
684 <div className="flex items-center gap-2">
685 {info?.severity && (
686 <span className="text-[9px] font-mono font-bold px-2 py-0.5 rounded" style={{ backgroundColor: severityColor + '15', color: severityColor, border: `1px solid ${severityColor}40` }}>{info.severity}</span>
687 )}
688 <a href={`https://nvd.nist.gov/vuln/detail/${cveId}`} target="_blank" rel="noreferrer" className="text-[#5C5A54] hover:text-[#E8E6E0] transition-colors">
689 <ExternalLink className="w-3.5 h-3.5" />
690 </a>
691 </div>
692 </div>
693 {isLoading ? (
694 <div className="flex items-center gap-2 py-1">
695 <Loader2 className="w-3 h-3 animate-spin text-[#5C5A54]" />
696 <span className="text-[10px] font-mono text-[#5C5A54]">Fetching vulnerability intelligence...</span>
697 </div>
698 ) : (
699 <>
700 <p className="text-[11px] font-mono text-[#8A8880] leading-relaxed">{info.description}</p>
701 {info.cwe && <div className="text-[10px] font-mono text-[#5C5A54] mt-2">Weakness: {info.cwe}</div>}
702 {info.affected && info.affected.length > 0 && (
703 <div className="mt-2 flex flex-wrap gap-1.5">
704 {info.affected.map((a: any, i: number) => (
705 <span key={i} className="text-[9px] font-mono px-1.5 py-0.5 bg-[#1A1A18] border border-[#2A2A28] rounded text-[#8A8880]">
706 {a.vendor}/{a.product}
707 </span>
708 ))}
709 </div>
710 )}
711 </>
712 )}
713 </div>
714 );
715 })}
716 </div>
717 </div>
718 )}
719 </div>
720 )}
721 </div>
722 );
723 })}
724 </div>
725 <div className="px-3 py-2 border-t border-[#2A2A28]">
726 <div className="text-[8px] font-mono text-[#5C5A54] tracking-wider">SWEPT {sweepResult.summary.total_hosts} HOSTS IN {(sweepResult.sweep_time_ms / 1000).toFixed(1)}s · ASN {sweepResult.center.asn}</div>
727 </div>
728 </div>
729 )}
730
731 {results && !(sweepResult && !loading) && (
732 <div className="bg-[var(--bg-primary)]/40 border border-[var(--border-primary)] rounded-lg p-3 max-h-[50vh] overflow-y-auto styled-scrollbar">
733 <div className="flex items-center justify-between mb-2">
734 <span className="text-[9px] font-mono tracking-widest" style={{ color: currentTab?.color }}>{currentTab?.label} RESULTS</span>
735 <span className="text-[8px] font-mono text-[var(--text-muted)] flex items-center gap-1"><Clock className="w-2.5 h-2.5" />{new Date().toLocaleTimeString()}</span>
736 </div>
737 {renderStructuredResults()}
738 </div>
739 )}
740
741 {history.length > 0 && !results && (
742 <div className="space-y-1">
743 <span className="text-[9px] font-mono tracking-widest text-[var(--text-muted)]">RECENT SCANS</span>
744 {history.slice(0, 5).map((h, i) => (
745 <button key={i} onClick={() => { setActiveTab(h.tab); setQuery(h.query); }}
746 className="w-full flex items-center justify-between px-2.5 py-1.5 rounded-lg hover:bg-[var(--hover-accent)] transition-colors text-left">
747 <div className="flex items-center gap-2">
748 <span className="text-[9px] font-mono" style={{ color: TABS.find(t => t.id === h.tab)?.color }}>{TABS.find(t => t.id === h.tab)?.label}</span>
749 <span className="text-[10px] font-mono text-[var(--text-secondary)]">{h.query}</span>
750 </div>
751 <span className="text-[8px] font-mono text-[var(--text-muted)]">{h.time}</span>
752 </button>
753 ))}
754 </div>
755 )}
756 </div>
757 );
758
759 if (isMobile) return renderContent();
760
761 if (isFullScreen) {
762 return (
763 <div className="fixed inset-4 z-[999] glass-panel bg-[#0a0a09]/95 backdrop-blur-2xl border border-[var(--cyan-primary)]/40 rounded-xl flex flex-col overflow-hidden shadow-2xl shadow-[var(--cyan-primary)]/20">
764 <div className="flex items-center justify-between px-6 py-4 border-b border-[var(--border-secondary)] bg-[#111]">
765 <div className="flex items-center gap-3">
766 <Radar className="w-5 h-5 text-[var(--cyan-primary)]" />
767 <span className="hud-text text-[16px] text-[var(--text-primary)]">OSIRIS RECON TOOLKIT</span>
768 <span className="gotham-tag gotham-tag--info" style={{ fontSize: '9px' }}>FULL SCREEN</span>
769 <span className="gotham-tag gotham-tag--classified" style={{ fontSize: '8px' }}>{TABS.length} MODULES</span>
770 </div>
771 <button onClick={() => setIsFullScreen(false)} className="p-2 hover:bg-white/5 rounded transition-colors text-[var(--text-muted)] hover:text-white">
772 <Minimize2 className="w-5 h-5" />
773 </button>
774 </div>
775 <div className="flex-1 overflow-y-auto p-6 styled-scrollbar">
776 {/* We wrap renderContent in a container that forces wider layouts if we want to target it with CSS */}
777 <div className="max-w-[1400px] mx-auto w-full full-screen-mode-content">
778 {renderContent()}
779 </div>
780 </div>
781 </div>
782 );
783 }
784
785 return (
786 <motion.div initial={{ opacity: 0, x: 20 }} animate={{ opacity: 1, x: 0 }} transition={{ delay: 0.3, duration: 0.6 }} className="glass-panel flex flex-col overflow-hidden pointer-events-auto">
787 <div className="flex items-center justify-between px-4 py-3 border-b border-transparent hover:bg-[var(--hover-accent)] transition-colors">
788 <button onClick={() => setExpanded(!expanded)} className="flex items-center gap-2 flex-1">
789 <Radar className="w-3.5 h-3.5 text-[var(--cyan-primary)]" />
790 <span className="hud-text text-[12px] text-[var(--text-primary)]">RECON TOOLKIT</span>
791 <span className="gotham-tag gotham-tag--info" style={{ fontSize: '7px', padding: '1px 5px' }}>{TABS.length} TOOLS</span>
792 </button>
793 <div className="flex items-center gap-3">
794 <button onClick={() => setIsFullScreen(true)} className="text-[var(--text-muted)] hover:text-[var(--text-primary)] transition-colors" title="Full Screen">
795 <Maximize2 className="w-3.5 h-3.5" />
796 </button>
797 <div className="w-1.5 h-1.5 rounded-full bg-[var(--cyan-primary)] animate-osiris-pulse" />
798 <button onClick={() => setExpanded(!expanded)}>
799 {expanded ? <ChevronUp className="w-3.5 h-3.5 text-[var(--text-muted)]" /> : <ChevronDown className="w-3.5 h-3.5 text-[var(--text-muted)]" />}
800 </button>
801 </div>
802 </div>
803 <AnimatePresence>
804 {expanded && (
805 <motion.div initial={{ height: 0, opacity: 0 }} animate={{ height: 'auto', opacity: 1 }} exit={{ height: 0, opacity: 0 }} transition={{ duration: 0.2 }} className="overflow-hidden px-3 pb-3">
806 {renderContent()}
807 </motion.div>
808 )}
809 </AnimatePresence>
810 </motion.div>
811 );
812}
813
814const OsintPanel = memo(OsintPanelInner);
815export default OsintPanel;