#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# ==============================================================================
#    _____                  __ _                 
#   / ____|                / _(_)                
#  | (___  _ __   ___   ___| |_ _ _ __   __ _    
#   \___ \| '_ \ / _ \ / _ \  _| | '_ \ / _` |   
#   ____) | |_) | (_) | (_) | | | | | | | (_| |  
#  |_____/| .__/ \___/ \___/|_| |_|_| |_|\__, |  
#         | |                             __/ |  
#         |_|                            |___/   
#                    SPOOFING.CC                 
# ==============================================================================
# The Ultimate IP Header Modification Testing Script
# Buy High-Performance Spoofing Servers at https://spoofing.cc
# ==============================================================================

import sys
import random
import os

# Enforce root privileges on Unix-like operating systems
if os.name == 'posix' and os.geteuid() != 0:
    print("\n[!] Error: Raw packet injection requires root/administrator privileges.")
    print("    Please re-run this script using 'sudo':")
    print(f"    sudo python3 {os.path.basename(__file__)} <target_ip>\n")
    sys.exit(1)

try:
    from scapy.all import send, IP, ICMP
    import scapy.config
except ImportError:
    print("\n[!] Error: Scapy not found.")
    print("    Please install Scapy manually:")
    print("    Linux:   sudo apt-get install python3-scapy OR pip install scapy")
    print("    Windows: pip install scapy\n")
    sys.exit(1)
except OSError as e:
    if "Interface" in str(e) or "pcap" in str(e).lower():
         print("\n[!] Error: Scapy requires Npcap or Winpcap to be installed on Windows.")
         print("    Download Npcap from: https://npcap.com/\n")
         sys.exit(1)
    raise

if len(sys.argv) < 2:
    print("\n[!] Error: Target IP required.")
    print(f"Usage: sudo python3 {os.path.basename(__file__)} <target_ip>\n")
    sys.exit(1)

target_ip = sys.argv[1]

print("\n[+] SPOOFING.CC - IPHM Verification Initiated")
print(f"[+] Target IP: {target_ip}")
print("[+] Firing 5000 randomized ICMP packets...")
print("[!] Ensure you are listening on the target server using:")
print("    tcpdump -i any icmp -nn -c 5000\n")

def randomIP():
    return ".".join(map(str, (random.randint(0, 255) for _ in range(4))))

try:
    send(IP(src=randomIP(), dst=target_ip)/ICMP()/"SPOOFTESTICMP", count=5000, verbose=0)
    print("\n[+] Attack emulation complete.")
    print("[+] Check your target server's tcpdump output.")
    print("[*] Need a server that can spoof? Visit https://spoofing.cc\n")
except PermissionError:
    print("\n[!] Permission Error: Failed to open raw network socket for injection.")
    print("    Please re-run this script with sudo/root privileges.\n")
except Exception as e:
    err_str = str(e)
    if "Microsoft KM-TEST Loopback Adapter" in err_str or "pcap" in err_str.lower():
        print("\n[!] Error: Scapy cannot find a valid network interface for packet injection.")
        print("[!] This is common on Windows machines missing Npcap.")
        print("[!] Fix: Install Npcap from https://npcap.com/ and check 'Support loopback traffic'")
    else:
        print(f"\n[!] Error during execution: {err_str}")

