Spaces:
Runtime error
Runtime error
File size: 7,364 Bytes
48922fa 88f5d78 48922fa 048fa41 88f5d78 048fa41 88f5d78 48922fa 88f5d78 48922fa 88f5d78 048fa41 88f5d78 48922fa 88f5d78 1f9ba54 88f5d78 48922fa 88f5d78 48922fa 88f5d78 048fa41 88f5d78 48922fa 88f5d78 048fa41 88f5d78 048fa41 48922fa 88f5d78 1f9ba54 88f5d78 1f9ba54 88f5d78 048fa41 88f5d78 1f9ba54 88f5d78 1f9ba54 88f5d78 048fa41 88f5d78 48922fa 88f5d78 048fa41 88f5d78 048fa41 88f5d78 48922fa 88f5d78 048fa41 88f5d78 048fa41 88f5d78 |
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 |
"""
OSINT engine for comprehensive information gathering.
"""
from typing import Dict, List, Any, Optional
import asyncio
import json
from dataclasses import dataclass
import holehe.core as holehe
import subprocess
import tempfile
import os
import face_recognition
import numpy as np
from PIL import Image
import io
import requests
from geopy.geocoders import Nominatim
from geopy.exc import GeocoderTimedOut
import whois
from datetime import datetime
from tenacity import retry, stop_after_attempt, wait_exponential
@dataclass
class PersonInfo:
name: str
age: Optional[int] = None
location: Optional[str] = None
gender: Optional[str] = None
social_profiles: List[Dict[str, str]] = None
images: List[str] = None
def to_dict(self) -> Dict[str, Any]:
return {
"name": self.name,
"age": self.age,
"location": self.location,
"gender": self.gender,
"social_profiles": self.social_profiles or [],
"images": self.images or []
}
class OSINTEngine:
def __init__(self):
self.geolocator = Nominatim(user_agent="intelligent_search_engine")
self.known_platforms = [
"Twitter", "Instagram", "Facebook", "LinkedIn", "GitHub",
"Reddit", "YouTube", "TikTok", "Pinterest", "Snapchat",
"Twitch", "Medium", "Dev.to", "Stack Overflow"
]
@retry(stop=stop_after_attempt(3), wait=wait_exponential(multiplier=1, min=4, max=10))
async def search_username(self, username: str) -> Dict[str, Any]:
"""Search for username across multiple platforms."""
results = {
"username": username,
"found_on": []
}
# Create a temporary file for sherlock results
with tempfile.NamedTemporaryFile(mode='w+', delete=False, suffix='.txt') as tmp:
tmp_path = tmp.name
try:
# Run sherlock as a subprocess
process = subprocess.Popen(
["sherlock", username, "--output", tmp_path],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
stdout, stderr = process.communicate()
# Read results from the temporary file
if os.path.exists(tmp_path):
with open(tmp_path, 'r') as f:
for line in f:
if "[+]" in line: # Found profile
platform = line.split("[+]")[1].split(":")[0].strip()
url = line.split(":")[-1].strip()
results["found_on"].append({
"platform": platform,
"url": url
})
elif "[-]" in line: # Not found
platform = line.split("[-]")[1].split(":")[0].strip()
results["found_on"].append({
"platform": platform,
"url": ""
})
# Clean up temp file
os.unlink(tmp_path)
except Exception as e:
print(f"Error running sherlock: {e}")
# Use holehe for email-based search
email = f"{username}@gmail.com" # Example email
holehe_results = await holehe.check_email(email)
# Combine results
for platform, data in holehe_results.items():
if data.get("exists", False):
results["found_on"].append({
"platform": platform,
"url": data.get("url", ""),
"confidence": data.get("confidence", "high")
})
return results
async def search_person(self, name: str, location: Optional[str] = None,
age: Optional[int] = None, gender: Optional[str] = None) -> PersonInfo:
"""Search for information about a person."""
person = PersonInfo(
name=name,
age=age,
location=location,
gender=gender
)
# Initialize social profiles list
person.social_profiles = []
# Search for social media profiles
username_variants = [
name.replace(" ", ""),
name.replace(" ", "_"),
name.replace(" ", "."),
name.lower().replace(" ", "")
]
for username in username_variants:
results = await self.search_username(username)
person.social_profiles.extend(results.get("found_on", []))
return person
@retry(stop=stop_after_attempt(3), wait=wait_exponential(multiplier=1, min=4, max=10))
async def analyze_image(self, image_data: bytes) -> Dict[str, Any]:
"""Analyze an image for faces and other identifiable information."""
try:
# Load image
image = face_recognition.load_image_file(io.BytesIO(image_data))
# Detect faces
face_locations = face_recognition.face_locations(image)
face_encodings = face_recognition.face_encodings(image, face_locations)
results = {
"faces_found": len(face_locations),
"faces": []
}
# Analyze each face
for i, (face_encoding, face_location) in enumerate(zip(face_encodings, face_locations)):
face_data = {
"location": {
"top": face_location[0],
"right": face_location[1],
"bottom": face_location[2],
"left": face_location[3]
}
}
results["faces"].append(face_data)
return results
except Exception as e:
return {"error": str(e)}
async def search_location(self, location: str) -> Dict[str, Any]:
"""Gather information about a location."""
try:
# Geocode the location
location_data = self.geolocator.geocode(location, timeout=10)
if not location_data:
return {"error": "Location not found"}
return {
"address": location_data.address,
"latitude": location_data.latitude,
"longitude": location_data.longitude,
"raw": location_data.raw
}
except GeocoderTimedOut:
return {"error": "Geocoding service timed out"}
except Exception as e:
return {"error": str(e)}
async def analyze_domain(self, domain: str) -> Dict[str, Any]:
"""Analyze a domain for WHOIS and other information."""
try:
w = whois.whois(domain)
return {
"registrar": w.registrar,
"creation_date": w.creation_date,
"expiration_date": w.expiration_date,
"last_updated": w.updated_date,
"status": w.status,
"name_servers": w.name_servers
}
except Exception as e:
return {"error": str(e)}
|