-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
225 lines (179 loc) · 8.5 KB
/
Copy pathmain.py
File metadata and controls
225 lines (179 loc) · 8.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
import asyncio
import os
import shutil
import subprocess
import sys
import sysconfig
import time
from urllib.parse import urlparse
import httpx
import whois
from fastapi import FastAPI, WebSocket, WebSocketDisconnect
from fastapi.staticfiles import StaticFiles
app = FastAPI(title="OSINT Aggregator")
# ── GitHub ────────────────────────────────────────────────────────────────────
async def run_github(username: str) -> dict:
try:
async with httpx.AsyncClient(timeout=10) as client:
resp = await client.get(
f"https://api.github.com/users/{username}",
headers={"Accept": "application/vnd.github+json"},
)
if resp.status_code == 404:
return {"status": "not_found", "findings": ["No GitHub account found"], "severity": "none"}
resp.raise_for_status()
d = resp.json()
findings = [f"https://github.com/{username}"]
if d.get("name"): findings.append(f"Name: {d['name']}")
if d.get("bio"): findings.append(f"Bio: {d['bio']}")
if d.get("location"): findings.append(f"Location: {d['location']}")
if d.get("email"): findings.append(f"Email: {d['email']}")
if d.get("blog"): findings.append(f"Website: {d['blog']}")
if d.get("company"): findings.append(f"Company: {d['company']}")
findings.append(f"Public repos: {d.get('public_repos', 0)} · Followers: {d.get('followers', 0)}")
if d.get("created_at"): findings.append(f"Account created: {d['created_at'][:10]}")
return {"status": "found", "findings": findings, "severity": "medium"}
except httpx.HTTPStatusError as e:
return {"status": "not_found", "findings": [f"GitHub API error {e.response.status_code}"], "severity": "none"}
except Exception as e:
return {"status": "not_found", "findings": [f"Error: {e}"], "severity": "none"}
# ── Dorking ──────────────────────────────────────────────────────────────────
async def run_dorking(username: str) -> dict:
def _blocking():
from ddgs import DDGS
with DDGS() as ddgs:
return list(ddgs.text(f'"{username}"', max_results=10)) or []
try:
results = await asyncio.to_thread(_blocking)
findings = []
seen = set()
for r in results:
url = r.get("href", "")
title = r.get("title", "").strip()
if not url or url in seen:
continue
if not urlparse(url).path.rstrip("/"):
continue
# GitHub is covered by its own agent
if "github.com" in url:
continue
# Drop fuzzy matches — username must appear in the URL or title
if username not in url.lower() and username not in title.lower():
continue
seen.add(url)
findings.append(f"{title} — {url}" if title else url)
if findings:
return {"status": "found", "findings": findings, "severity": "low"}
return {"status": "not_found", "findings": ["No indexed results found"], "severity": "none"}
except Exception as e:
return {"status": "not_found", "findings": [f"Error: {e}"], "severity": "none"}
# ── WHOIS ────────────────────────────────────────────────────────────────────
WHOIS_TLDS = ["com", "fi", "io", "net", "dev"]
async def run_whois(username: str) -> dict:
async def _check(domain: str):
def _blocking():
try:
w = whois.whois(domain)
return w if w.domain_name else None
except Exception:
return None
return domain, await asyncio.to_thread(_blocking)
results = await asyncio.gather(*[_check(f"{username}.{tld}") for tld in WHOIS_TLDS])
findings = []
for domain, w in results:
if not w:
continue
findings.append(f"https://{domain}")
if w.registrar:
findings.append(f"Registrar: {w.registrar}")
date = w.creation_date
if date:
if isinstance(date, list):
date = date[0]
findings.append(f"Created: {str(date)[:10]}")
exp = w.expiration_date
if exp:
if isinstance(exp, list):
exp = exp[0]
findings.append(f"Expires: {str(exp)[:10]}")
name = str(w.name or "")
if name and not any(x in name.lower() for x in ("redacted", "privacy", "protected", "withheld")):
findings.append(f"Registrant: {name}")
if findings:
return {"status": "found", "findings": findings, "severity": "medium"}
return {"status": "not_found", "findings": ["No domain registrations found"], "severity": "none"}
# ── Sherlock ──────────────────────────────────────────────────────────────────
def _find_sherlock() -> str:
if exe := shutil.which("sherlock"):
return exe
candidates = [
sysconfig.get_path("scripts"),
sysconfig.get_path("scripts", "nt_user"),
os.path.dirname(sys.executable),
]
for scripts_dir in filter(None, candidates):
for name in ("sherlock.exe", "sherlock"):
path = os.path.join(scripts_dir, name)
if os.path.isfile(path):
return path
return "sherlock"
async def run_sherlock(username: str) -> dict:
def _blocking():
result = subprocess.run(
[_find_sherlock(), username, "--print-found", "--no-color", "--timeout", "15"],
capture_output=True,
timeout=120,
)
return result.stdout.decode("utf-8", errors="replace")
try:
output = await asyncio.to_thread(_blocking)
findings = []
for line in output.splitlines():
if line.startswith("[+]"):
parts = line[4:].split(": ", 1)
if len(parts) == 2:
url = parts[1].strip()
if urlparse(url).path.rstrip("/"):
findings.append(url)
if findings:
return {"status": "found", "findings": findings, "severity": "medium"}
return {"status": "not_found", "findings": ["No accounts found on any platform"], "severity": "none"}
except subprocess.TimeoutExpired:
return {"status": "not_found", "findings": ["Scan timed out after 120s"], "severity": "none"}
except Exception as e:
return {"status": "not_found", "findings": [f"Error: {e}"], "severity": "none"}
# ── WebSocket handler ─────────────────────────────────────────────────────────
AGENTS = [
("GitHub", run_github),
("Dorking", run_dorking),
("WHOIS", run_whois),
("Sherlock", run_sherlock),
]
@app.websocket("/ws/search")
async def search_ws(websocket: WebSocket):
await websocket.accept()
try:
data = await websocket.receive_json()
query = data.get("query", "")
username = query.strip().lower().replace(" ", "")
await websocket.send_json({"type": "started", "query": query, "total": len(AGENTS)})
async def run_agent(name: str, fn):
await websocket.send_json({"type": "scanning", "agent": name})
t0 = time.perf_counter()
result = await fn(username)
elapsed = round(time.perf_counter() - t0, 1)
await websocket.send_json({"type": "result", "agent": name, **result, "elapsed": elapsed})
await asyncio.gather(*[run_agent(name, fn) for name, fn in AGENTS])
await websocket.send_json({"type": "complete"})
except WebSocketDisconnect:
pass
except Exception as e:
try:
await websocket.send_json({"type": "error", "message": str(e)})
except Exception:
pass
# Static files mount must come AFTER all route definitions
app.mount("/", StaticFiles(directory="frontend", html=True), name="static")
if __name__ == "__main__":
import uvicorn
uvicorn.run("main:app", host="0.0.0.0", port=9000, reload=True)