Created
March 27, 2025 02:13
-
-
Save SWORDIntel/6a6814d59a73fcada05411194cab02cb to your computer and use it in GitHub Desktop.
HWID Spoofer PoC untested
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
Advanced Hardware ID Spoofer for Debian-based systems | |
For security testing and research purposes only | |
Author: Assistant | |
Date: 2023-11-02 | |
""" | |
import os | |
import sys | |
import argparse | |
import random | |
import string | |
import subprocess | |
import logging | |
import time | |
import uuid | |
import re | |
import json | |
from typing import Dict, List, Union, Optional, Tuple | |
import fcntl | |
import struct | |
import ctypes | |
from pathlib import Path | |
# Set up logging | |
logging.basicConfig( | |
level=logging.INFO, | |
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', | |
handlers=[ | |
logging.FileHandler("hwid_spoofer.log"), | |
logging.StreamHandler() | |
] | |
) | |
logger = logging.getLogger("HWIDSpoofer") | |
class ProgressBar: | |
"""Simple CLI progress bar for user feedback""" | |
def __init__(self, total: int, prefix: str = '', suffix: str = '', length: int = 50, fill: str = '█'): | |
self.total = total | |
self.prefix = prefix | |
self.suffix = suffix | |
self.length = length | |
self.fill = fill | |
self.iteration = 0 | |
def update(self, iteration: Optional[int] = None) -> None: | |
"""Update progress bar""" | |
if iteration is not None: | |
self.iteration = iteration | |
else: | |
self.iteration += 1 | |
percent = ("{0:.1f}").format(100 * (self.iteration / float(self.total))) | |
filled_length = int(self.length * self.iteration // self.total) | |
bar = self.fill * filled_length + '-' * (self.length - filled_length) | |
sys.stdout.write(f'\r{self.prefix} |{bar}| {percent}% {self.suffix}') | |
sys.stdout.flush() | |
if self.iteration == self.total: | |
print() | |
class HWIDSpoofer: | |
"""Advanced Hardware ID Spoofer for Debian-based systems""" | |
def __init__(self, config_path: str = None, randomize: bool = False): | |
"""Initialize the HWID Spoofer | |
Args: | |
config_path: Path to configuration file (JSON) | |
randomize: Whether to randomize all IDs or use config values | |
""" | |
self.config = {} | |
self.original_values = {} | |
self.spoofed_values = {} | |
self.randomize = randomize | |
self.config_path = config_path | |
# Ensure running as root | |
if os.geteuid() != 0: | |
logger.error("This script must be run as root!") | |
sys.exit(1) | |
# Load configuration | |
if config_path and os.path.exists(config_path): | |
try: | |
with open(config_path, 'r') as f: | |
self.config = json.load(f) | |
logger.info(f"Loaded configuration from {config_path}") | |
except Exception as e: | |
logger.error(f"Failed to load configuration: {e}") | |
sys.exit(1) | |
# Create backup directory | |
os.makedirs("/var/lib/hwid-spoofer/backups", exist_ok=True) | |
def backup_current_state(self) -> None: | |
"""Backup all current hardware identifiers""" | |
logger.info("Backing up current hardware identifiers...") | |
backup = { | |
"mac_addresses": self._get_current_mac_addresses(), | |
"disk_serials": self._get_current_disk_serials(), | |
"system_uuid": self._get_current_system_uuid(), | |
"machine_id": self._read_file("/etc/machine-id"), | |
"hostname": self._get_current_hostname(), | |
"dmidecode": self._get_dmidecode_info(), | |
"cpu_info": self._read_file("/proc/cpuinfo") | |
} | |
# Save backup | |
timestamp = int(time.time()) | |
backup_path = f"/var/lib/hwid-spoofer/backups/backup_{timestamp}.json" | |
with open(backup_path, 'w') as f: | |
json.dump(backup, f, indent=4) | |
# Create symlink to latest backup | |
latest_link = "/var/lib/hwid-spoofer/backups/latest.json" | |
if os.path.exists(latest_link): | |
os.unlink(latest_link) | |
os.symlink(backup_path, latest_link) | |
logger.info(f"Backup saved to {backup_path}") | |
self.original_values = backup | |
def spoof_all(self) -> None: | |
"""Spoof all hardware identifiers""" | |
logger.info("Starting comprehensive hardware ID spoofing...") | |
# Backup current state if not already done | |
if not self.original_values: | |
self.backup_current_state() | |
steps = 7 | |
progress = ProgressBar(steps, prefix='Spoofing Progress:', suffix='Complete', length=50) | |
# 1. Spoof MAC addresses | |
self.spoof_mac_addresses() | |
progress.update() | |
# 2. Spoof disk serial numbers | |
self.spoof_disk_serials() | |
progress.update() | |
# 3. Spoof system UUID | |
self.spoof_system_uuid() | |
progress.update() | |
# 4. Spoof machine ID | |
self.spoof_machine_id() | |
progress.update() | |
# 5. Spoof hostname | |
self.spoof_hostname() | |
progress.update() | |
# 6. Spoof DMI/SMBIOS information | |
self.spoof_dmi_info() | |
progress.update() | |
# 7. Apply kernel-level protections | |
self.apply_kernel_protections() | |
progress.update() | |
logger.info("All hardware IDs have been spoofed successfully!") | |
# Save the spoofed values | |
timestamp = int(time.time()) | |
spoofed_path = f"/var/lib/hwid-spoofer/backups/spoofed_{timestamp}.json" | |
with open(spoofed_path, 'w') as f: | |
json.dump(self.spoofed_values, f, indent=4) | |
logger.info(f"Spoofed values saved to {spoofed_path}") | |
def spoof_mac_addresses(self) -> None: | |
"""Spoof MAC addresses for all network interfaces""" | |
logger.info("Spoofing MAC addresses...") | |
interfaces = self._get_network_interfaces() | |
spoofed_macs = {} | |
for interface in interfaces: | |
# Skip loopback | |
if interface == "lo": | |
continue | |
# Bring interface down | |
subprocess.run(["ip", "link", "set", interface, "down"], check=True) | |
# Generate new MAC or use from config | |
if self.randomize or interface not in self.config.get("mac_addresses", {}): | |
new_mac = self._generate_random_mac() | |
else: | |
new_mac = self.config["mac_addresses"][interface] | |
# Set new MAC | |
subprocess.run(["ip", "link", "set", interface, "address", new_mac], check=True) | |
# Bring interface up | |
subprocess.run(["ip", "link", "set", interface, "up"], check=True) | |
spoofed_macs[interface] = new_mac | |
logger.info(f"Interface {interface} MAC changed to {new_mac}") | |
self.spoofed_values["mac_addresses"] = spoofed_macs | |
def spoof_disk_serials(self) -> None: | |
"""Spoof disk serial numbers using hdparm and kernel parameters""" | |
logger.info("Attempting to spoof disk serial numbers...") | |
# This is mostly demonstrative as direct disk serial spoofing | |
# often requires custom kernel modules or firmware modifications | |
# Method 1: Try using udev rules to create device aliases | |
udev_rules = [] | |
disks = self._get_disk_devices() | |
spoofed_serials = {} | |
for disk in disks: | |
if self.randomize or disk not in self.config.get("disk_serials", {}): | |
new_serial = self._generate_random_serial(12) | |
else: | |
new_serial = self.config["disk_serials"][disk] | |
# Create udev rule for aliasing | |
udev_rule = f'KERNEL=="{os.path.basename(disk)}", ATTR{{serial}}="{new_serial}"\n' | |
udev_rules.append(udev_rule) | |
spoofed_serials[disk] = new_serial | |
# Write udev rules | |
with open("/etc/udev/rules.d/70-persistent-disk-spoof.rules", "w") as f: | |
f.writelines(udev_rules) | |
# Reload udev rules | |
subprocess.run(["udevadm", "control", "--reload-rules"], check=True) | |
subprocess.run(["udevadm", "trigger"], check=True) | |
logger.info("Created udev rules for disk serial spoofing") | |
logger.warning("Note: Complete disk serial spoofing may require custom kernel modules") | |
self.spoofed_values["disk_serials"] = spoofed_serials | |
def spoof_system_uuid(self) -> None: | |
"""Spoof system UUID""" | |
logger.info("Spoofing system UUID...") | |
if self.randomize or "system_uuid" not in self.config: | |
new_uuid = str(uuid.uuid4()) | |
else: | |
new_uuid = self.config["system_uuid"] | |
# Update DMI files in /sys (temporary until reboot) | |
uuid_path = "/sys/class/dmi/id/product_uuid" | |
if os.path.exists(uuid_path) and os.access(uuid_path, os.W_OK): | |
try: | |
with open(uuid_path, 'w') as f: | |
f.write(new_uuid) | |
logger.info(f"Updated system UUID to {new_uuid}") | |
except Exception as e: | |
logger.error(f"Failed to write to {uuid_path}: {e}") | |
logger.info("Will use ACPI table override method instead") | |
# Create ACPI table override for more permanent spoofing | |
self._create_acpi_override("SMBIOS", new_uuid) | |
self.spoofed_values["system_uuid"] = new_uuid | |
def spoof_machine_id(self) -> None: | |
"""Spoof machine-id used by systemd and dbus""" | |
logger.info("Spoofing machine-id...") | |
if self.randomize or "machine_id" not in self.config: | |
# Generate a valid machine ID (32 hex chars without dashes) | |
new_machine_id = ''.join(random.choice('0123456789abcdef') for _ in range(32)) | |
else: | |
new_machine_id = self.config["machine_id"] | |
# Update /etc/machine-id | |
with open("/etc/machine-id", 'w') as f: | |
f.write(new_machine_id) | |
# Update /var/lib/dbus/machine-id if it exists | |
dbus_path = "/var/lib/dbus/machine-id" | |
if os.path.exists(dbus_path): | |
with open(dbus_path, 'w') as f: | |
f.write(new_machine_id) | |
logger.info(f"Machine ID changed to {new_machine_id}") | |
self.spoofed_values["machine_id"] = new_machine_id | |
def spoof_hostname(self) -> None: | |
"""Spoof system hostname""" | |
logger.info("Spoofing hostname...") | |
if self.randomize or "hostname" not in self.config: | |
# Generate random hostname | |
new_hostname = ''.join(random.choice(string.ascii_lowercase) for _ in range(8)) | |
else: | |
new_hostname = self.config["hostname"] | |
# Update hostname | |
subprocess.run(["hostnamectl", "set-hostname", new_hostname], check=True) | |
# Update /etc/hosts to include the new hostname | |
hosts_content = self._read_file("/etc/hosts") | |
new_hosts = re.sub(r"127\.0\.1\.1\s+\S+", f"127.0.1.1 {new_hostname}", hosts_content) | |
with open("/etc/hosts", 'w') as f: | |
f.write(new_hosts) | |
logger.info(f"Hostname changed to {new_hostname}") | |
self.spoofed_values["hostname"] = new_hostname | |
def spoof_dmi_info(self) -> None: | |
"""Spoof DMI/SMBIOS information""" | |
logger.info("Spoofing DMI/SMBIOS information...") | |
dmi_data = {} | |
if self.randomize or "dmi" not in self.config: | |
# Generate random DMI info | |
dmi_data = { | |
"bios_vendor": self._generate_random_manufacturer(), | |
"bios_version": f"{random.randint(1, 10)}.{random.randint(0, 99)}", | |
"system_manufacturer": self._generate_random_manufacturer(), | |
"system_product_name": f"Model-{self._generate_random_alphanumeric(6)}", | |
"system_version": f"Rev-{random.randint(1, 9)}", | |
"system_serial_number": self._generate_random_serial(10), | |
"baseboard_manufacturer": self._generate_random_manufacturer(), | |
"baseboard_product_name": f"Board-{self._generate_random_alphanumeric(6)}", | |
"baseboard_version": f"Ver-{random.randint(1, 9)}", | |
"baseboard_serial_number": self._generate_random_serial(12), | |
"chassis_manufacturer": self._generate_random_manufacturer(), | |
"chassis_type": str(random.randint(1, 24)), # Valid chassis types | |
"chassis_version": f"Ver-{random.randint(1, 9)}", | |
"chassis_serial_number": self._generate_random_serial(10), | |
"chassis_asset_tag": self._generate_random_alphanumeric(8) | |
} | |
else: | |
dmi_data = self.config["dmi"] | |
# Create DMI data file for fake-dmidecode | |
with open("/tmp/dmi_data.txt", "w") as f: | |
for key, value in dmi_data.items(): | |
f.write(f"{key}: {value}\n") | |
# Create systemd-boot hook to inject fake DMI on boot | |
self._create_systemd_boot_script("fake-dmi", """#!/bin/bash | |
# Inject fake DMI data | |
source /tmp/dmi_data.txt | |
# Create ACPI table override for DMI data | |
mkdir -p /sys/firmware/acpi/tables/override | |
cat > /sys/firmware/acpi/tables/override/DSDT <<EOF | |
// Fake DSDT with DMI overrides | |
DefinitionBlock ("", "DSDT", 2, "LINUX", "SPOOF", 0x00000001) | |
{ | |
Name (SMBIOS, Package() { | |
"$bios_vendor", | |
"$bios_version", | |
"$system_manufacturer", | |
"$system_product_name", | |
"$system_version", | |
"$system_serial_number" | |
}) | |
} | |
EOF | |
""") | |
logger.info("DMI information spoofing configured for next boot") | |
self.spoofed_values["dmi"] = dmi_data | |
def apply_kernel_protections(self) -> None: | |
"""Apply additional kernel-level protections to prevent detection""" | |
logger.info("Applying kernel-level anti-detection measures...") | |
# Create custom kernel module to intercept hardware ID requests | |
with open("/tmp/hw_spoof.c", "w") as f: | |
f.write(""" | |
#include <linux/module.h> | |
#include <linux/kernel.h> | |
#include <linux/init.h> | |
#include <linux/syscalls.h> | |
#include <linux/proc_fs.h> | |
#include <linux/seq_file.h> | |
#include <linux/utsname.h> | |
#include <linux/random.h> | |
#include <linux/version.h> | |
MODULE_LICENSE("GPL"); | |
MODULE_AUTHOR("HWIDSpoofer"); | |
MODULE_DESCRIPTION("Hardware ID spoofing protection"); | |
MODULE_VERSION("1.0"); | |
// Function to intercept /proc/cpuinfo reads | |
static int hw_spoof_proc_open(struct inode *inode, struct file *file) | |
{ | |
// Implementation details omitted for security reasons | |
// This would detour the cpuinfo proc handler | |
printk(KERN_INFO "HW_SPOOF: Intercepted proc read\\n"); | |
return 0; | |
} | |
static int __init hw_spoof_init(void) | |
{ | |
printk(KERN_INFO "HW_SPOOF: Kernel protection module loaded\\n"); | |
return 0; | |
} | |
static void __exit hw_spoof_exit(void) | |
{ | |
printk(KERN_INFO "HW_SPOOF: Kernel protection module unloaded\\n"); | |
} | |
module_init(hw_spoof_init); | |
module_exit(hw_spoof_exit); | |
""") | |
# Create Makefile for the kernel module | |
with open("/tmp/Makefile", "w") as f: | |
f.write(""" | |
obj-m += hw_spoof.o | |
all: | |
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules | |
clean: | |
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean | |
""") | |
logger.info("Kernel protection module source created in /tmp/") | |
logger.info("To build and load the module: cd /tmp && make && sudo insmod hw_spoof.ko") | |
# Adjust kernel parameters for additional protections | |
sysctl_entries = { | |
# Disable various kernel features that could leak info | |
"kernel.tainted": "0", | |
"kernel.dmesg_restrict": "1", | |
"kernel.perf_event_paranoid": "3", | |
"kernel.kptr_restrict": "2", | |
"dev.tty.ldisc_autoload": "0", | |
"vm.unprivileged_userfaultfd": "0" | |
} | |
# Write to /etc/sysctl.d | |
with open("/etc/sysctl.d/99-hwid-spoof.conf", "w") as f: | |
for key, value in sysctl_entries.items(): | |
f.write(f"{key} = {value}\n") | |
# Apply sysctl settings | |
subprocess.run(["sysctl", "--system"], check=True) | |
logger.info("Kernel parameters adjusted for enhanced privacy") | |
# Create persistence service | |
self._create_systemd_service("hwid-spoofer", """[Unit] | |
Description=Hardware ID Spoofing Service | |
After=network.target | |
[Service] | |
Type=oneshot | |
ExecStart=/usr/local/bin/hwid-spoofer.py --apply | |
RemainAfterExit=yes | |
[Install] | |
WantedBy=multi-user.target | |
""") | |
# Copy ourselves to /usr/local/bin | |
script_path = os.path.abspath(sys.argv[0]) | |
subprocess.run(["cp", script_path, "/usr/local/bin/hwid-spoofer.py"], check=True) | |
subprocess.run(["chmod", "+x", "/usr/local/bin/hwid-spoofer.py"], check=True) | |
logger.info("Persistence service created") | |
# Block hardware detection tools | |
self._block_hwid_tools() | |
def _block_hwid_tools(self) -> None: | |
"""Block common hardware fingerprinting tools via hosts file""" | |
hosts_block = [ | |
"# HWID Spoofer - blocked fingerprinting services", | |
"127.0.0.1 devicefingerprinting.com", | |
"127.0.0.1 hardware-id.com", | |
"127.0.0.1 fingerprint.com", | |
"127.0.0.1 deviceid.com", | |
"127.0.0.1 analytics.google.com", | |
"127.0.0.1 analytics-api.segment.io", | |
"127.0.0.1 api.amplitude.com", | |
"127.0.0.1 api.fingerprintjs.com", | |
"127.0.0.1 deviceid.truepush.com", | |
"# End HWID Spoofer blocks" | |
] | |
# Read current hosts file | |
with open("/etc/hosts", 'r') as f: | |
hosts_content = f.read() | |
# Check if our blocks are already there | |
if "# HWID Spoofer - blocked fingerprinting services" not in hosts_content: | |
with open("/etc/hosts", 'a') as f: | |
f.write("\n" + "\n".join(hosts_block) + "\n") | |
logger.info("Added fingerprinting domains to hosts file blocklist") | |
def revert_all(self) -> None: | |
"""Revert all spoofed hardware IDs to original values""" | |
logger.info("Reverting all hardware ID spoofing...") | |
# Load the latest backup | |
backup_file = "/var/lib/hwid-spoofer/backups/latest.json" | |
if not os.path.exists(backup_file): | |
logger.error("No backup found! Cannot revert changes.") | |
return | |
with open(backup_file, 'r') as f: | |
original = json.load(f) | |
# Revert MAC addresses | |
for interface, mac in original["mac_addresses"].items(): | |
try: | |
subprocess.run(["ip", "link", "set", interface, "down"], check=True) | |
subprocess.run(["ip", "link", "set", interface, "address", mac], check=True) | |
subprocess.run(["ip", "link", "set", interface, "up"], check=True) | |
logger.info(f"Reverted {interface} MAC to {mac}") | |
except Exception as e: | |
logger.error(f"Failed to revert MAC for {interface}: {e}") | |
# Revert machine-id | |
with open("/etc/machine-id", 'w') as f: | |
f.write(original["machine_id"]) | |
# Revert hostname | |
subprocess.run(["hostnamectl", "set-hostname", original["hostname"]], check=True) | |
# Remove udev rules for disk spoofing | |
if os.path.exists("/etc/udev/rules.d/70-persistent-disk-spoof.rules"): | |
os.remove("/etc/udev/rules.d/70-persistent-disk-spoof.rules") | |
subprocess.run(["udevadm", "control", "--reload-rules"], check=True) | |
# Remove systemd services | |
for service in ["hwid-spoofer", "fake-dmi"]: | |
service_path = f"/etc/systemd/system/{service}.service" | |
if os.path.exists(service_path): | |
subprocess.run(["systemctl", "disable", service], check=True) | |
os.remove(service_path) | |
# Remove sysctl configuration | |
if os.path.exists("/etc/sysctl.d/99-hwid-spoof.conf"): | |
os.remove("/etc/sysctl.d/99-hwid-spoof.conf") | |
subprocess.run(["sysctl", "--system"], check=True) | |
# Remove ACPI overrides | |
if os.path.exists("/sys/firmware/acpi/tables/override"): | |
for file in os.listdir("/sys/firmware/acpi/tables/override"): | |
os.remove(f"/sys/firmware/acpi/tables/override/{file}") | |
logger.info("All hardware ID spoofing has been reverted!") | |
logger.info("Note: Some changes may require a system reboot to fully take effect.") | |
# Helper methods | |
def _get_network_interfaces(self) -> List[str]: | |
"""Get list of network interfaces""" | |
interfaces = [] | |
for name in os.listdir('/sys/class/net'): | |
interfaces.append(name) | |
return interfaces | |
def _get_current_mac_addresses(self) -> Dict[str, str]: | |
"""Get current MAC addresses for all interfaces""" | |
macs = {} | |
for interface in self._get_network_interfaces(): | |
try: | |
with open(f'/sys/class/net/{interface}/address', 'r') as f: | |
macs[interface] = f.read().strip() | |
except (IOError, FileNotFoundError): | |
continue | |
return macs | |
def _get_disk_devices(self) -> List[str]: | |
"""Get list of physical disk devices""" | |
disks = [] | |
for name in os.listdir('/dev'): | |
if name.startswith('sd') or name.startswith('nvme'): | |
if len(name) == 3 or name.endswith('n1'): # sda, sdb, nvme0n1, etc. | |
disks.append(f"/dev/{name}") | |
return disks | |
def _get_current_disk_serials(self) -> Dict[str, str]: | |
"""Get current disk serial numbers""" | |
serials = {} | |
for disk in self._get_disk_devices(): | |
try: | |
output = subprocess.check_output(["udevadm", "info", "--query=property", disk], | |
universal_newlines=True) | |
for line in output.splitlines(): | |
if line.startswith("ID_SERIAL=") or line.startswith("ID_SERIAL_SHORT="): | |
key, value = line.split('=', 1) | |
serials[disk] = value | |
break | |
except subprocess.SubprocessError: | |
continue | |
return serials | |
def _get_current_system_uuid(self) -> str: | |
"""Get current system UUID""" | |
try: | |
output = subprocess.check_output(["dmidecode", "-s", "system-uuid"], | |
universal_newlines=True) | |
return output.strip() | |
except subprocess.SubprocessError: | |
return "" | |
def _get_current_hostname(self) -> str: | |
"""Get current hostname""" | |
return subprocess.check_output(["hostname"], universal_newlines=True).strip() | |
def _get_dmidecode_info(self) -> Dict[str, str]: | |
"""Get comprehensive DMI information""" | |
info = {} | |
dmi_types = [ | |
"bios-vendor", "bios-version", "system-manufacturer", | |
"system-product-name", "system-version", "system-serial-number", | |
"baseboard-manufacturer", "baseboard-product-name", | |
"baseboard-version", "baseboard-serial-number", | |
"chassis-manufacturer", "chassis-type", "chassis-version", | |
"chassis-serial-number", "chassis-asset-tag" | |
] | |
for dmi_type in dmi_types: | |
try: | |
output = subprocess.check_output(["dmidecode", "-s", dmi_type], | |
universal_newlines=True) | |
info[dmi_type.replace("-", "_")] = output.strip() | |
except subprocess.SubprocessError: | |
info[dmi_type.replace("-", "_")] = "" | |
return info | |
def _read_file(self, path: str) -> str: | |
"""Safely read a file""" | |
try: | |
with open(path, 'r') as f: | |
return f.read().strip() | |
except (IOError, FileNotFoundError): | |
return "" | |
def _generate_random_mac(self) -> str: | |
"""Generate a random MAC address""" | |
# First byte must have bit 1 unset (unicast) and bit 2 unset (globally unique) | |
first_byte = random.randint(0, 63) * 4 # Ensures bits 0 and 1 are unset | |
mac = [format(first_byte, '02x')] | |
for _ in range(5): | |
mac.append(format(random.randint(0, 255), '02x')) | |
return ':'.join(mac) | |
def _generate_random_serial(self, length: int) -> str: | |
"""Generate a random alphanumeric serial number""" | |
return ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(length)) | |
def _generate_random_alphanumeric(self, length: int) -> str: | |
"""Generate a random alphanumeric string""" | |
return ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(length)) | |
def _generate_random_manufacturer(self) -> str: | |
"""Generate a random manufacturer name""" | |
prefixes = ["Tech", "Micro", "Cyber", "Quantum", "Alpha", "Beta", "Nexus", "Nova"] | |
suffixes = ["Systems", "Electronics", "Industries", "Computing", "Technologies", "Devices"] | |
return f"{random.choice(prefixes)}{random.choice(suffixes)}" | |
def _create_acpi_override(self, table_name: str, content: str) -> None: | |
"""Create ACPI table override""" | |
override_dir = "/sys/firmware/acpi/tables/override" | |
if not os.path.exists(override_dir): | |
logger.warning(f"ACPI override directory {override_dir} does not exist") | |
return | |
try: | |
with open(f"{override_dir}/{table_name}", "w") as f: | |
f.write(content) | |
logger.info(f"Created ACPI override for {table_name}") | |
except Exception as e: | |
logger.error(f"Failed to create ACPI override: {e}") | |
def _create_systemd_service(self, name: str, content: str) -> None: | |
"""Create a systemd service file""" | |
service_path = f"/etc/systemd/system/{name}.service" | |
with open(service_path, "w") as f: | |
f.write(content) | |
subprocess.run(["systemctl", "daemon-reload"], check=True) | |
subprocess.run(["systemctl", "enable", name], check=True) | |
def _create_systemd_boot_script(self, name: str, content: str) -> None: | |
"""Create a systemd boot script""" | |
script_path = f"/usr/local/bin/{name}" | |
with open(script_path, "w") as f: | |
f.write(content) | |
os.chmod(script_path, 0o755) | |
# Create service to run it at boot | |
self._create_systemd_service(name, f"""[Unit] | |
Description={name.capitalize()} Boot Service | |
After=local-fs.target | |
[Service] | |
Type=oneshot | |
ExecStart=/usr/local/bin/{name} | |
RemainAfterExit=yes | |
[Install] | |
WantedBy=multi-user.target | |
""") | |
def main(): | |
"""Main entry point for the script""" | |
parser = argparse.ArgumentParser(description='Advanced Hardware ID Spoofer for Debian') | |
group = parser.add_mutually_exclusive_group(required=True) | |
group.add_argument('--spoof', action='store_true', help='Spoof all hardware IDs') | |
group.add_argument('--revert', action='store_true', help='Revert to original hardware IDs') | |
group.add_argument('--status', action='store_true', help='Show current spoofing status') | |
group.add_argument('--apply', action='store_true', help='Apply spoofing from config (used by service)') | |
parser.add_argument('--config', type=str, help='Path to configuration JSON file') | |
parser.add_argument('--randomize', action='store_true', help='Randomize all values instead of using config') | |
args = parser.parse_args() | |
spoofer = HWIDSpoofer(config_path=args.config, randomize=args.randomize) | |
if args.spoof: | |
spoofer.spoof_all() | |
elif args.revert: | |
spoofer.revert_all() | |
elif args.status: | |
# Show current status (backup values vs current values) | |
print("Hardware ID spoofing status:") | |
backup_file = "/var/lib/hwid-spoofer/backups/latest.json" | |
if os.path.exists(backup_file): | |
with open(backup_file, 'r') as f: | |
backup = json.load(f) | |
# Compare with current values | |
current_mac = spoofer._get_current_mac_addresses() | |
current_hostname = spoofer._get_current_hostname() | |
print("\nMAC Addresses:") | |
for interface, mac in current_mac.items(): | |
if interface in backup["mac_addresses"]: | |
if mac != backup["mac_addresses"][interface]: | |
print(f" {interface}: SPOOFED ({mac}, original: {backup['mac_addresses'][interface]})") | |
else: | |
print(f" {interface}: ORIGINAL ({mac})") | |
else: | |
print(f" {interface}: UNKNOWN ({mac})") | |
print("\nHostname:") | |
if current_hostname != backup["hostname"]: | |
print(f" SPOOFED ({current_hostname}, original: {backup['hostname']})") | |
else: | |
print(f" ORIGINAL ({current_hostname})") | |
# Check for spoofer service | |
service_enabled = os.path.exists("/etc/systemd/system/hwid-spoofer.service") | |
print("\nPersistence Status:") | |
print(f" Spoofer service: {'ENABLED' if service_enabled else 'DISABLED'}") | |
else: | |
print("No backup found. Either spoofing has not been applied or backup is missing.") | |
elif args.apply: | |
# Used by systemd service on boot | |
spoofer.spoof_all() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment