File size: 7,216 Bytes
48922fa
f6b5fd2
48922fa
 
 
048fa41
88f5d78
f6b5fd2
88f5d78
f6b5fd2
 
88f5d78
f6b5fd2
48922fa
 
 
f6b5fd2
 
88f5d78
f6b5fd2
 
 
88f5d78
048fa41
48922fa
f6b5fd2
1f9ba54
f6b5fd2
 
 
48922fa
 
f6b5fd2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48922fa
f6b5fd2
48922fa
f6b5fd2
 
 
 
 
 
 
 
 
 
 
 
 
88f5d78
f6b5fd2
48922fa
f6b5fd2
048fa41
 
48922fa
88f5d78
f6b5fd2
 
 
 
 
 
 
 
 
 
88f5d78
f6b5fd2
 
 
 
 
 
 
 
 
 
 
 
88f5d78
f6b5fd2
 
 
 
 
 
88f5d78
f6b5fd2
 
 
88f5d78
f6b5fd2
 
 
 
 
 
 
 
 
 
 
 
 
88f5d78
 
f6b5fd2
 
 
88f5d78
f6b5fd2
 
 
88f5d78
 
048fa41
f6b5fd2
88f5d78
 
 
f6b5fd2
88f5d78
f6b5fd2
 
 
 
 
 
 
 
 
048fa41
88f5d78
 
f6b5fd2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
OSINT engine for username and person search.
"""
from typing import Dict, List, Any, Optional
import asyncio
import json
import requests
from bs4 import BeautifulSoup
import whois
from holehe.core import *
from geopy.geocoders import Nominatim
from tenacity import retry, stop_after_attempt, wait_exponential
from duckduckgo_search import DDGS

class OSINTEngine:
    def __init__(self):
        self.geolocator = Nominatim(user_agent="ise_search")
        self.holehe_modules = import_submodules("holehe.modules")
        self.known_platforms = [
            "twitter.com", "facebook.com", "instagram.com", "linkedin.com",
            "github.com", "youtube.com", "reddit.com", "pinterest.com",
            "medium.com", "tumblr.com", "flickr.com", "vimeo.com"
        ]
    
    async def search_username(self, username: str) -> Dict[str, Any]:
        """Search for username across platforms."""
        results = {
            "found": [],
            "not_found": [],
            "error": []
        }
        
        # Manual platform check
        for platform in self.known_platforms:
            try:
                url = f"https://{platform}/{username}"
                response = requests.head(url, timeout=5, allow_redirects=True)
                if response.status_code == 200:
                    results["found"].append({
                        "platform": platform.split(".")[0].title(),
                        "url": url
                    })
                else:
                    results["not_found"].append(platform.split(".")[0].title())
            except Exception as e:
                results["error"].append({
                    "platform": platform,
                    "error": str(e)
                })
        
        # Run holehe checks
        try:
            holehe_results = []
            for module in self.holehe_modules:
                try:
                    check_func = getattr(module, "check")
                    out = await check_func(username)
                    if out and out.get("exists"):
                        results["found"].append({
                            "platform": out["name"],
                            "url": out.get("url", ""),
                            "email": out.get("email", "")
                        })
                except Exception as e:
                    print(f"Error in holehe module {module.__name__}: {e}")
            
            results["holehe"] = holehe_results
        except Exception as e:
            print(f"Error running holehe: {e}")
        
        return results
    
    @retry(stop=stop_after_attempt(3), wait=wait_exponential(multiplier=1, min=4, max=10))
    async def search_person(self, name: str, location: Optional[str] = None, age: Optional[int] = None) -> Dict[str, Any]:
        """Search for person information."""
        results = {
            "basic_info": {},
            "social_profiles": [],
            "locations": [],
            "possible_relatives": [],
            "error": None
        }
        
        try:
            # Geocode location if provided
            if location:
                try:
                    loc = self.geolocator.geocode(location)
                    if loc:
                        results["locations"].append({
                            "address": loc.address,
                            "latitude": loc.latitude,
                            "longitude": loc.longitude
                        })
                except Exception as e:
                    print(f"Error geocoding location: {e}")
            
            # Basic search query
            search_query = f"{name}"
            if location:
                search_query += f" {location}"
            if age:
                search_query += f" {age} years old"
            
            # Use DuckDuckGo for initial search
            with DDGS() as ddgs:
                search_results = [r for r in ddgs.text(search_query, max_results=10)]
            
            for result in search_results:
                try:
                    url = result["link"]
                    # Check if URL is from a known social platform
                    if any(platform in url.lower() for platform in self.known_platforms):
                        platform = next(p for p in self.known_platforms if p in url.lower())
                        results["social_profiles"].append({
                            "platform": platform.split(".")[0].title(),
                            "url": url,
                            "title": result.get("title", "")
                        })
                except Exception as e:
                    print(f"Error processing search result: {e}")
            
        except Exception as e:
            results["error"] = str(e)
        
        return results
    
    @retry(stop=stop_after_attempt(3), wait=wait_exponential(multiplier=1, min=4, max=10))
    async def domain_lookup(self, domain: str) -> Dict[str, Any]:
        """Perform WHOIS lookup for a domain."""
        try:
            w = whois.whois(domain)
            return {
                "domain_name": w.domain_name,
                "registrar": w.registrar,
                "creation_date": w.creation_date,
                "expiration_date": w.expiration_date,
                "name_servers": w.name_servers,
                "status": w.status,
                "emails": w.emails,
                "dnssec": w.dnssec,
                "name": w.name,
                "org": w.org,
                "address": w.address,
                "city": w.city,
                "state": w.state,
                "zipcode": w.zipcode,
                "country": w.country
            }
        except Exception as e:
            return {"error": str(e)}
    
    async def analyze_social_profile(self, url: str) -> Dict[str, Any]:
        """Analyze a social media profile."""
        results = {
            "profile_info": {},
            "recent_activity": [],
            "connections": [],
            "error": None
        }
        
        try:
            headers = {
                "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
            }
            response = requests.get(url, headers=headers, timeout=10)
            response.raise_for_status()
            
            soup = BeautifulSoup(response.text, "html.parser")
            
            # Extract basic profile info
            results["profile_info"]["title"] = soup.title.string if soup.title else None
            
            # Extract meta information
            for meta in soup.find_all("meta"):
                property = meta.get("property", "")
                content = meta.get("content", "")
                
                if "og:title" in property:
                    results["profile_info"]["og_title"] = content
                elif "og:description" in property:
                    results["profile_info"]["og_description"] = content
                elif "og:image" in property:
                    results["profile_info"]["og_image"] = content
            
        except Exception as e:
            results["error"] = str(e)
        
        return results