diff options
| author | gigagamerchaddhruv-spec <gigagamerchaddhruv@gmail.com> | 2026-05-02 20:44:22 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-05-02 20:44:22 +0530 |
| commit | d0429265f328ab46221411e4c0ae3d431350d872 (patch) | |
| tree | c83e69c72b28f5bc42c5b8d92f25133c1e9b715a | |
| parent | a09c2e299db868583415ff3da6f8929c5ad37187 (diff) | |
Refactor wiretrip.py for improved structure and clarity
| -rw-r--r-- | wiretrip.py | 273 |
1 files changed, 87 insertions, 186 deletions
diff --git a/wiretrip.py b/wiretrip.py index 74d38d7..f937ff6 100644 --- a/wiretrip.py +++ b/wiretrip.py @@ -1,235 +1,136 @@ -import os +from pathlib import Path +import random import time import hashlib -import json -import psutil from datetime import datetime -# ========================== +# ========================= # CONFIG -# ========================== - -CONFIG = { - "watch_dir": "wiretrip/decoys", - "log_dir": "wiretrip/logs", - "log_file": "wiretrip/logs/access.log", - "scan_interval": 2, - "decoy_files": [ - "passwords.txt", - "aws_keys.txt", - "server_backup.sql", - "admin_notes.txt", - "router_config_backup.cfg" - ] -} +# ========================= -file_hashes = {} +HOME = Path.home() -# ========================== -# SETUP -# ========================== - -def setup_environment(): - os.makedirs(CONFIG["watch_dir"], exist_ok=True) - os.makedirs(CONFIG["log_dir"], exist_ok=True) - - for name in CONFIG["decoy_files"]: - path = os.path.join(CONFIG["watch_dir"], name) - - if not os.path.exists(path): - with open(path, "w") as f: - f.write(generate_fake_content(name)) - - -# ========================== -# FAKE DATA GENERATOR -# ========================== - -def generate_fake_content(filename): - - fake_data = { - "passwords.txt": - """ -root:Sup3rSecret! -admin:LetMeIn123 -backup:Password123 -db_admin:qwertyuiop -""", - - "aws_keys.txt": - """ -AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE -AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY -""", - - "server_backup.sql": - """ -DATABASE: production - -users: -admin -backup -service_account -""", - - "admin_notes.txt": - """ -TODO: -- rotate server credentials -- update firewall rules -- remove old admin accounts -""", - - "router_config_backup.cfg": - """ -router admin password: admin123 -ssh enabled -vpn key: 89dhs92jds92jd -""" - } - - return fake_data.get(filename, "Confidential data\n") - - -# ========================== -# HASHING -# ========================== +TARGET_DIRS = [ + HOME / "Documents", + HOME / "Downloads", + HOME / "Desktop" +] -def hash_file(path): +BAIT_FILES = [ + "backup_passwords.txt", + "server_keys.txt", + "old_config.txt", + "notes_admin.txt", + "wallet_backup.txt" +] - h = hashlib.sha256() - - try: - with open(path, "rb") as f: - h.update(f.read()) - return h.hexdigest() - except: - return None +LOG_FILE = HOME / ".wiretrip_log.txt" +SCAN_INTERVAL = 2 +file_hashes = {} -# ========================== -# PROCESS DETECTION -# ========================== +# ========================= +# SETUP BAIT FILES +# ========================= -def find_process_using_file(filepath): +def deploy_decoys(): + for _ in range(len(BAIT_FILES)): - users = [] + folder = random.choice(TARGET_DIRS) + filename = random.choice(BAIT_FILES) - for proc in psutil.process_iter(['pid','name','open_files']): + path = folder / filename - try: - files = proc.info['open_files'] - if files: - for f in files: - if filepath in f.path: - users.append(f"{proc.info['name']} (PID {proc.info['pid']})") - except: - pass + if not path.exists(): + path.write_text("SYSTEM BACKUP FILE - DO NOT MODIFY\n") + print(f"[WireTrip] deployed -> {path}") - return users +# ========================= +# HASHING +# ========================= +def hash_file(path): + try: + h = hashlib.sha256() + h.update(path.read_bytes()) + return h.hexdigest() + except: + return None -# ========================== +# ========================= # LOGGING -# ========================== - -def log_event(file): - - processes = find_process_using_file(file) +# ========================= - with open(CONFIG["log_file"], "a") as log: +def log_event(path): + entry = f"[{datetime.now()}] ACCESS DETECTED -> {path}\n" - log.write("\n=========================\n") - log.write(f"TIME: {datetime.now()}\n") - log.write(f"FILE TRIGGERED: {file}\n") + with open(LOG_FILE, "a") as f: + f.write(entry) - if processes: - log.write("PROCESS USING FILE:\n") - for p in processes: - log.write(f" {p}\n") + print(entry.strip()) - else: - log.write("PROCESS: Unknown\n") +# ========================= +# INITIAL STATE +# ========================= +def init_state(): + for folder in TARGET_DIRS: + for file in folder.glob("*"): + if file.is_file(): + file_hashes[file] = hash_file(file) -# ========================== -# INITIAL HASH BASELINE -# ========================== +# ========================= +# MONITOR LOOP +# ========================= -def initialize_hashes(): - - for root, dirs, files in os.walk(CONFIG["watch_dir"]): - - for name in files: - - path = os.path.join(root, name) - file_hashes[path] = hash_file(path) - - -# ========================== -# SCANNER -# ========================== - -def scan_files(): - - for root, dirs, files in os.walk(CONFIG["watch_dir"]): - - for name in files: - - path = os.path.join(root, name) +def monitor(): + while True: - current_hash = hash_file(path) + for folder in TARGET_DIRS: + for file in folder.glob("*"): - if path not in file_hashes: - file_hashes[path] = current_hash - continue + if file.is_file(): - if file_hashes[path] != current_hash: + current = hash_file(file) - log_event(path) + if file not in file_hashes: + file_hashes[file] = current + continue - file_hashes[path] = current_hash + if file_hashes[file] != current: + log_event(file) + file_hashes[file] = current + time.sleep(SCAN_INTERVAL) -# ========================== +# ========================= # BANNER -# ========================== +# ========================= def banner(): - print(""" -██╗ ██╗██╗██████╗ ███████╗████████╗██████╗ ██╗██████╗ -██║ ██║██║██╔══██╗██╔════╝╚══██╔══╝██╔══██╗██║██╔══██╗ -██║ █╗ ██║██║██████╔╝█████╗ ██║ ██████╔╝██║██████╔╝ -██║███╗██║██║██╔══██╗██╔══╝ ██║ ██╔══██╗██║██╔═══╝ -╚███╔███╔╝██║██║ ██║███████╗ ██║ ██║ ██║██║██║ - ╚══╝╚══╝ ╚═╝╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═╝ ╚═╝╚═╝╚═╝ - -WireTrip Defensive Honeypot +======================== + WIRETRIP + Deception IDS (Lab Tool) +======================== """) - -# ========================== -# MAIN LOOP -# ========================== +# ========================= +# MAIN +# ========================= def main(): - banner() - print("[*] Setting up environment") - setup_environment() - - print("[*] Initializing baseline hashes") - initialize_hashes() + print("[*] Deploying decoy files...") + deploy_decoys() - print("[*] Monitoring decoy files...\n") - - while True: + print("[*] Initializing state...") + init_state() - scan_files() - time.sleep(CONFIG["scan_interval"]) + print("[*] Monitoring system...\n") + monitor() if __name__ == "__main__": main() |
