Repository navigation
Expand file tree
/
Copy pathapi.py
More file actions
341 lines (293 loc) · 9 KB
/
Copy pathapi.py
File metadata and controls
341 lines (293 loc) · 9 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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
from fastapi import FastAPI, UploadFile, File, HTTPException
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel
from fastapi import WebSocket
import json
import uvicorn
import anyio
import trio
import logging
import warnings
import os
from dotenv import load_dotenv
import telethon
from core.name_checker import check_all_sites
from core.email_checker import check_all_emails
from core.email_checker import check_holehe
from core.email_checker import check_gravatar
from core.email_checker import validate_mx_records
from core.email_checker import is_disposable
from core.file_checker import extract_image_metadata
from core.phone_checker import search_google_dorks
from core.phone_checker import find_country_and_carrier
from core.phone_checker import check_if_valid
from core.phone_checker import open_viber_chat
from core.phone_checker import open_telegram_chat
from core.phone_checker import open_watsapp_chat
from core.phone_checker import check_telegram
warnings.filterwarnings("ignore", category=RuntimeWarning)
logging.getLogger("charsetnormalizer").setLevel(logging.ERROR)
logging.getLogger("bs4").setLevel(logging.ERROR)
logging.getLogger("httpx").setLevel(logging.ERROR)
load_dotenv()
API_ID = os.getenv("TELEGRAM_API_ID")
API_HASH = os.getenv("TELEGRAM_API_HASH")
_TG_CLIENT_ = None
app=FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"]
)
class UsernameRequest(BaseModel):
username: str
class EmailRequest(BaseModel):
email: str
class PhoneRequest(BaseModel):
phone: str
async def init_telegram_client():
global _TG_CLIENT_
if _TG_CLIENT_ is None:
_TG_CLIENT_ = telethon.TelegramClient('osint_session', API_ID, API_HASH)
await _TG_CLIENT_.start()
# usernames
"""
result = {
"service_name": "",
"status": "",
"error_message": "",
"url" : ""
}
"""
@app.websocket("/api/username")
async def search_by_username(websocket: WebSocket):
await websocket.accept()
try:
data = await websocket.receive_text()
payload = json.loads(data)
target_username = payload.get("username")
await check_all_sites(websocket, target_username)
await websocket.send_json({"status": "COMPLETED"})
except Exception as e:
await websocket.send_json({"status": "error", "error_message": str(e)})
finally:
# Кладем трубку
await websocket.close()
# emails
"""
result = {
"status": "",
"error_message" : "",
"target": email,
"is_disposable": False
}
"""
@app.post("/api/email/disposable")
async def email_is_disposable(payload: EmailRequest):
try:
results = is_disposable(payload.email)
return {"status": "success", "target": payload.email, "results": results}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
"""
result = {
"status": "",
"error_message" : "",
"target": email,
"is_valid": False
}
"""
@app.post("/api/email/validate")
async def email_validate(payload: EmailRequest):
try:
results = await validate_mx_records(payload.email)
return {"status": "success", "target": payload.email, "results": results}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
"""
result = {
"status": "",
"error_message" : "",
"target": ready_email,
"raw_json_url" : ready_url,
"name": "",
"location" : "",
"about_me" : "",
"job" : "",
"company" : "",
"profile_url" : "",
"profile_photo" : "",
"verified_accounts" : []
}
"""
@app.post("/api/email/gravatar")
async def email_gravatar(payload: EmailRequest):
try:
results = await check_gravatar(payload.email)
return {"status": "success", "target": payload.email, "results": results}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
"""
result = {
"name" : "",
"domain" : "",
"method" : "",
"frequent_rate_limit" : "",
"rateLimit" : "",
"exists" : "",
"emailrecovery" : "",
"phoneNumber" : "",
"other" : ""
}
"""
@app.post("/api/email/holehe")
async def email_holehe(payload: EmailRequest):
try:
def _execute_trio():
return trio.run(check_holehe, payload.email)
results = await anyio.to_thread.run_sync(_execute_trio)
# ВАЖНО: Оборачиваем список results в словарь!
return {"status": "success", "target": payload.email, "results": results}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
"""
result = {
"service_name": service_name,
"status": "",
"error_message": "",
"url" : url,
"leaks" : 0,
"leaks_source" : {}
}
"""
@app.websocket("/api/email")
async def search_by_email(websocket : WebSocket):
await websocket.accept()
try:
data = await websocket.receive_text()
payload = json.loads(data)
target_email = payload.get("email")
await check_all_emails(websocket, target_email)
await websocket.send_json({"status" : "COMPLETED"})
except Exception as e:
# raise HTTPException(status_code=500, detail=str(e))
await websocket.send_json({"status": "error", "error_message": str(e)})
finally:
# Кладем трубку
await websocket.close()
# phone numbers
"""
result = {
"url": ""
}
"""
@app.post("/api/phone/dorks")
async def search_by_phone(payload: PhoneRequest):
try:
results = search_google_dorks(payload.phone)
return {"status": "success", "target": payload.phone, "results": results}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
"""
result = {
"country" : "",
"carrier_name" : ""
}
"""
@app.post("/api/phone/country")
async def phone_country_and_carrier(payload: PhoneRequest):
try:
results = await find_country_and_carrier(payload.phone)
return {"status": "success", "target": payload.phone, "results": results}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
"""
result = {
"is_valid" : False
}
"""
@app.post("/api/phone/valid")
async def phone_valid(payload: PhoneRequest):
try:
results = check_if_valid(payload.phone)
return {"status": "success", "target": payload.phone, "results": results}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
"""
result = {
"url" : ""
}
"""
@app.post("/api/phone/viber/chat")
async def phone_viber_chat(payload: PhoneRequest):
try:
results = open_viber_chat(payload.phone)
return {"status": "success", "target": payload.phone, "results": results}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
"""
result = {
"url" : ""
}
"""
@app.post("/api/phone/telegram/chat")
async def phone_telegram_chat(payload: PhoneRequest):
try:
results = open_telegram_chat(payload.phone)
return {"status": "success", "target": payload.phone, "results": results}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
"""
result = {
"url" : ""
}
"""
@app.post("/api/phone/whatsapp/chat")
async def phone_whatsapp_chat(payload: PhoneRequest):
try:
results = open_watsapp_chat(payload.phone)
return {"status": "success", "target": payload.phone, "results": results}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
"""
result = {
"status" : "",
"error_message" : "",
"id" : "" ,
"username" : "",
"first_name" : "",
"last_name" : ""
}
"""
@app.post("/api/phone/telegram")
async def phone_telegram(payload: PhoneRequest):
try:
await init_telegram_client()
results = await check_telegram(payload.phone, _TG_CLIENT_)
return {"status": "success", "target": payload.phone, "results": results}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
# metadata
"""
result = {
"status":"processing",
"has_exif": False,
"raw_exif": {},
"error_message": "",
"hardware": {},
"software": {},
"gps": {}
}
"""
@app.post("/api/metadata")
async def extract_metadata(file: UploadFile = File(...)):
try:
file_bytes = await file.read()
metadata = extract_image_metadata(file_bytes)
return {"status": "success", "filename": file.filename, "results": metadata}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
if __name__ == "__main__":
uvicorn.run("api:app", host="127.0.0.1", port=8000, reload=True)