π΅οΈββοΈ (2-in-1) Email & Username OSINT suite featuring native MCP support for deep data extraction just from a single Email/Username. Analyzes 2720+ actively maintained scan vectors (210+ email / 2510+ username) for security research, investigations, and digital footprinting.
Python cybersecuritycybersecurity-toolsemail-osintethical-hackingethical-hacking-toolsidentificationinfosecosintosint-emailosint-toolosint-toolsosint-usernamepentestingpythonredteam-toolsredteamingthreat-intelligence
feat: refactor config helpers and implement Hudson Rock scan
kaifcodeca3a237684a80
diff --git a/tests/test_helpers.py b/tests/test_helpers.pyindex d034b8a..6bd91d0 100644--- a/tests/test_helpers.py+++ b/tests/test_helpers.py@@ -1,5 +1,6 @@import sysimport threading+import jsonfrom types import SimpleNamespacefrom unittest.mock import MagicMock, patch@@ -8,6 +9,7 @@ import pytestfrom user_scanner.__main__ import mainfrom user_scanner.core import helpersfrom user_scanner.core.result import Result+from user_scanner.core.helpers import _get_config_path, load_config, save_config_value, CONFIG_PATHdef test_generate_permutations():@@ -364,3 +366,75 @@ http://3""")t.join()assert len(results) == 50+++def test_get_config_path_default(monkeypatch):+ """Test that it returns the default path when no environment variable is set."""+ monkeypatch.delenv("USER_SCANNER_CONFIG", raising=False)+ path = _get_config_path()+ # This matches your default CONFIG_PATH logic+ assert path == CONFIG_PATH++def test_get_config_path_env_override(monkeypatch, tmp_path):+ """Test that environment variable USER_SCANNER_CONFIG overrides the default path."""+ custom_path = tmp_path / "custom_config.json"+ monkeypatch.setenv("USER_SCANNER_CONFIG", str(custom_path))+ path = _get_config_path()+ assert path == custom_path++def test_load_config_creates_default(tmp_path):+ """Test that a default config is created with correct keys if the file doesn't exist."""+ config_file = tmp_path / "new_config.json"+ data = load_config(path=config_file)++ assert config_file.exists()+ assert data["auto_update_status"] is True+ assert data["auto_hudson_prompt"] is True++def test_load_config_reads_existing(tmp_path):+ """Test that existing config data is correctly loaded from the file."""+ config_file = tmp_path / "existing.json"+ existing_data = {+ "auto_update_status": False,+ "auto_hudson_prompt": False+ }+ config_file.write_text(json.dumps(existing_data))++ data = load_config(path=config_file)+ assert data == existing_data++def test_save_config_value_updates_keys(tmp_path):+ """Test that save_config_value updates specific keys without losing others."""+ config_file = tmp_path / "test_save.json"++ # 1. Update update_status to False+ save_config_value("auto_update_status", False, path=config_file)+ data = load_config(path=config_file)+ assert data["auto_update_status"] is False+ assert data["auto_hudson_prompt"] is True # Should remain default++ # 2. Update hudson_prompt to False+ save_config_value("auto_hudson_prompt", False, path=config_file)+ data = load_config(path=config_file)+ assert data["auto_hudson_prompt"] is False+ assert data["auto_update_status"] is False # Should remain False from previous step++def test_load_config_handles_corrupt_json(tmp_path):+ """Test that corrupted JSON in the config file triggers a reset to defaults."""+ config_file = tmp_path / "corrupt.json"+ # Write invalid JSON content+ config_file.write_text("{ 'broken': true, }")++ # load_config should catch JSONDecodeError and return default dict+ data = load_config(path=config_file)+ assert data["auto_update_status"] is True+ assert data["auto_hudson_prompt"] is True++def test_save_config_value_creates_directory(tmp_path):+ """Test that the helper creates the parent directory if it doesn't exist."""+ nested_path = tmp_path / "subdir" / "nested_config.json"++ save_config_value("auto_update_status", True, path=nested_path)++ assert nested_path.exists()+ assert nested_path.parent.is_dir()diff --git a/tests/test_update.py b/tests/test_update.pyindex 8091152..63ff741 100644--- a/tests/test_update.py+++ b/tests/test_update.py@@ -1,15 +1,18 @@from user_scanner.utils import updater_logic as ul+from user_scanner.core import helpers as hl+def test_default_config():- configs = ul.load_config()+ configs = hl.load_config()assert "auto_update_status" in configs# Make sure config.json has "auto_update_status" set to trueassert configs["auto_update_status"]+def test_config_json(tmp_path, monkeypatch):cfg = tmp_path / "config.json"monkeypatch.setenv("USER_SCANNER_CONFIG", str(cfg))- configs = ul.load_config()+ configs = hl.load_config()assert "auto_update_status" in configs# Should be default Trueassert configs["auto_update_status"] is True@@ -20,10 +23,10 @@ def test_config_set(tmp_path, monkeypatch):monkeypatch.setenv("USER_SCANNER_CONFIG", str(cfg))def get_status():- return ul.load_config()["auto_update_status"]+ return hl.load_config()["auto_update_status"]- ul.save_config_change(False)+ hl.save_config_value("auto_update_status", False)assert get_status() is False- ul.save_config_change(True)+ hl.save_config_value("auto_update_status", True)assert get_status() is Truediff --git a/user_scanner/config.json b/user_scanner/config.jsonindex 27a07c8..5199379 100644--- a/user_scanner/config.json+++ b/user_scanner/config.json@@ -1,3 +1,4 @@{- "auto_update_status": true+ "auto_update_status": true,+ "auto_hudson_prompt": false}diff --git a/user_scanner/core/helpers.py b/user_scanner/core/helpers.pyindex badbedf..e559117 100644--- a/user_scanner/core/helpers.py+++ b/user_scanner/core/helpers.py@@ -1,6 +1,8 @@import importlibimport importlib.utilimport inspect+import json+import osimport randomimport threadingfrom concurrent.futures import ThreadPoolExecutor, as_completed@@ -26,6 +28,9 @@ LOUD_MODULES: Dict[str, List[str]] = {],}+CONFIG_PATH = Path(__file__).parent.parent / "config.json"++@dataclass(frozen=True)class ScanConfig:allow_loud: bool = False@@ -262,3 +267,47 @@ def get_random_user_agent():"""return random"""random_agent = random.choice(agents)return random_agent+++def _get_config_path(path: str | Path | None = None) -> Path:+ """+ Determine the config path in this order:+ 1. explicit path argument (if provided)+ 2. environment variable USER_SCANNER_CONFIG (if set)+ 3. default CONFIG_PATH+ """+ if path:+ return Path(path)+ env = os.environ.get("USER_SCANNER_CONFIG")+ if env:+ return Path(env)+ return CONFIG_PATH+++def load_config(path: str | Path | None = None) -> dict:+ cp = _get_config_path(path)+ if cp.exists():+ try:+ return json.loads(cp.read_text())+ except json.JSONDecodeError:+ # This prevents the crash on corrupted JSON+ pass++ default = {+ "auto_update_status": True,+ "auto_hudson_prompt": True+ }+ cp.parent.mkdir(parents=True, exist_ok=True)+ cp.write_text(json.dumps(default, indent=2))+ return default++++def save_config_value(key: str, value: Any, path: str | Path | None = None):+ """Generic helper to update any specific key in the config."""+ cp = _get_config_path(path)+ content = load_config(path)+ content[key] = value+ cp.parent.mkdir(parents=True, exist_ok=True)+ cp.write_text(json.dumps(content, indent=2))+diff --git a/user_scanner/core/hudson.py b/user_scanner/core/hudson.pyindex 0e5652b..b76dfd7 100644--- a/user_scanner/core/hudson.py+++ b/user_scanner/core/hudson.py@@ -1,5 +1,7 @@import httpx-from colorama import Fore+import json+from colorama import Fore, Style+from user_scanner.core.helpers import load_config, _get_config_path# Color configsR = Fore.RED@@ -7,19 +9,56 @@ G = Fore.GREENC = Fore.CYANY = Fore.YELLOWM = Fore.MAGENTA-X = Fore.RESET+X = Style.RESET_ALL++def update_hudson_preference(show_prompt: bool):+ """Updates the config file using your existing helper logic."""+ cp = _get_config_path()+ content = load_config()+ content["auto_hudson_prompt"] = show_prompt+ cp.write_text(json.dumps(content, indent=2))++def check_hudson_permission(target: str) -> bool:+ """Disclaimers and prompts based on user config."""+ config = load_config()++ # If the user already set this to false, skip the prompt and run+ if not config.get("auto_hudson_prompt", True):+ return True++ print(f"\n{Y}[!] PRIVACY NOTICE & DISCLAIMER:{X}")+ print(" Hudson Rock is a third-party intelligence service.")+ print(f" By proceeding, the identifier '{C}{target}{Y}' will be sent to their API.")+ print(f" They may log queries. We are not responsible for their data handling.{X}")++ while True:+ choice = input(f"\n{C}Query Hudson Rock? (y/n/d for don't ask again): {X}").lower().strip()+ if choice == 'y':+ return True+ elif choice == 'n':+ print(f"{Y}[i] Hudson Rock scan skipped.{X}")+ return False+ elif choice == 'd':+ update_hudson_preference(False)+ print(f"{G}[+] Preference saved. You won't be prompted again.{X}")+ return True+ else:+ print(f"{R}[!] Please enter 'y', 'n', or 'd'.{X}")def run_hudson_scan(target: str, is_email: bool = False):"""Fetch and display intelligence from Hudson Rock's OSINT API.- This integration is strictly optional and provided for additional intelligence."""+ # Permission check using the new logic+ if not check_hudson_permission(target):+ return+base_url = "https://cavalier.hudsonrock.com/api/json/v2/osint-tools/"endpoint = "search-by-email" if is_email else "search-by-username"param = "email" if is_email else "username"-+url = f"{base_url}{endpoint}?{param}={target}"-+print(f"\n{M}== HUDSON ROCK INFOSTEALER INTELLIGENCE =={X}")print(f"{C}[i] Attribution: Data provided by Hudson Rock (https://www.hudsonrock.com){X}")print(f"{C}[*] Querying Hudson Rock for {target}...{X}")@@ -27,29 +66,29 @@ def run_hudson_scan(target: str, is_email: bool = False):try:with httpx.Client(timeout=10.0) as client:response = client.get(url)-+if response.status_code == 200:data = response.json()stealers = data.get("stealers", [])-+if not stealers:print(f"{G}[β] No infostealer infections found for this {param}.{X}")returntotal_stealers = len(stealers)print(f"{R}[!] FOUND {total_stealers} INFOSTEALER INFECTION(S) ASSOCIATED WITH THIS {param.upper()}!{X}")-+for i, stealer in enumerate(stealers, 1):print(f"\n {Y}Infection #{i}:{X}")print(f" - Stealer Family: {stealer.get('stealer_family', 'Unknown')}")print(f" - Date Compromised: {stealer.get('date_compromised', 'Unknown')}")print(f" - Operating System: {stealer.get('operating_system', 'Unknown')}")print(f" - Computer Name: {stealer.get('computer_name', 'Unknown')}")-+antiviruses = stealer.get('antiviruses', [])if antiviruses:print(f" - Antiviruses: {', '.join(antiviruses)}")-+top_logins = stealer.get('top_logins', [])if top_logins:print(f" - Sample Logins Found: {', '.join(top_logins[:3])}...")@@ -58,9 +97,9 @@ def run_hudson_scan(target: str, is_email: bool = False):print(f"{Y}[!] Visit https://www.hudsonrock.com/free-tools for more info.{X}")elif response.status_code == 404:- print(f"{G}[β] No data found for this {param} in Hudson Rock database.{X}")+ print(f"{G}[β] No data found for this {param} in Hudson Rock database.{X}")else:- print(f"{R}[β] Hudson Rock API error: HTTP {response.status_code}{X}")+ print(f"{R}[β] Hudson Rock API error: HTTP {response.status_code}{X}")except Exception as e:print(f"{R}[β] Error connecting to Hudson Rock: {e}{X}")diff --git a/user_scanner/utils/updater_logic.py b/user_scanner/utils/updater_logic.pyindex 1b00493..84deb7e 100644--- a/user_scanner/utils/updater_logic.py+++ b/user_scanner/utils/updater_logic.py@@ -1,11 +1,10 @@-from pathlib import Pathfrom colorama import Foreimport sys-import json-import os++from user_scanner.core.version import get_pypi_version, load_local_versionfrom user_scanner.utils.update import update_self-+from user_scanner.core.helpers import load_config, save_config_value# Color configsR = Fore.REDG = Fore.GREEN@@ -13,43 +12,6 @@ C = Fore.CYANY = Fore.YELLOWX = Fore.RESET-CONFIG_PATH = Path(__file__).parent.parent / "config.json"---def _get_config_path(path: str | Path | None = None) -> Path:- """- Determine the config path in this order:- 1. explicit path argument (if provided)- 2. environment variable USER_SCANNER_CONFIG (if set)- 3. default CONFIG_PATH- """- if path:- return Path(path)- env = os.environ.get("USER_SCANNER_CONFIG")- if env:- return Path(env)- return CONFIG_PATH---def load_config(path: str | Path | None = None) -> dict:- cp = _get_config_path(path)- if cp.exists():- return json.loads(cp.read_text())-- default = {"auto_update_status": True}- # Ensure parent exists- cp.parent.mkdir(parents=True, exist_ok=True)- cp.write_text(json.dumps(default, indent=2))- return default---def save_config_change(status: bool, path: str | Path | None = None):- cp = _get_config_path(path)- content = load_config(path)- content["auto_update_status"] = status- cp.parent.mkdir(parents=True, exist_ok=True)- cp.write_text(json.dumps(content, indent=2))-def check_for_updates():if not load_config().get("auto_update_status", False):@@ -76,7 +38,7 @@ def check_for_updates():sys.exit(0)elif choice == "d":- save_config_change(False)+ save_config_value(False)print(f"[{Y}*{X}] {R}Auto-update checks disabled.{X}")except Exception as e: