Update ping_of_death_simulation.py

Этот коммит содержится в:
Sylvester Kaczmarek 2023-10-11 18:52:27 +01:00 коммит произвёл GitHub
родитель 27a972b6ae
Коммит d752c0e93f
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23

Просмотреть файл

@ -1,70 +1,98 @@
import socket
import time
def simulate_large_icmp_packet(target_ip, packet_size=70000, duration=10):
"""
Simulates sending a large ICMP packet in a loop for a specified duration.
def introduction():
"""Provides a brief introduction to the 'Ping of Death' attack."""
print("Welcome to the 'Ping of Death' attack simulation!")
print("\nThe 'Ping of Death' attack involves sending oversized ICMP packets to a target system.")
print("Historically, some systems were unable to handle these oversized packets, leading to buffer overflows and system crashes.")
print("This simulation will demonstrate the concept of the attack without causing actual harm.\n")
Args:
- target_ip (str): The target IP address.
- packet_size (int, optional): The size of the ICMP packet. Default is 70000 bytes.
- duration (int, optional): The duration in seconds for which the simulation runs. Default is 10 seconds.
"""
print(f"Attempting to create an ICMP packet of size {packet_size} bytes to {target_ip}...")
def choose_mode():
"""Allows the user to choose a simulation mode."""
print("Choose a mode of simulation:")
print("1. Single Packet Mode: Send a single oversized packet.")
print("2. Continuous Packet Mode: Send packets in a loop.")
print("3. Safe Packet Mode: Send a packet of a typical size to demonstrate normal behavior.")
choice = input("Enter your choice (1/2/3): ")
return choice
def feedback_on_packet_size(packet_size):
"""Provides feedback based on the chosen packet size."""
if packet_size > 65535:
print("Warning: The specified packet size exceeds the standard limit of 65535 bytes for ICMP.")
print("\nWarning: The specified packet size exceeds the standard limit of 65535 bytes for ICMP.")
print("In a real-world scenario, this could lead to buffer overflows and potential system crashes.")
else:
print("\nThe specified packet size is within the typical range for ICMP packets.")
print("In most modern systems, this would not cause any issues.\n")
# Create a dummy packet of the specified size
def potential_outcomes(mode, packet_size):
"""Displays potential outcomes based on the chosen mode and packet size."""
if mode == "1" and packet_size > 65535:
print("\nPotential Outcome: The target system might become unresponsive or crash due to the oversized packet.")
elif mode == "2":
print("\nPotential Outcome: Continuous sending of oversized packets might lead to sustained unresponsiveness or crashes.")
else:
print("\nPotential Outcome: The target system should handle the packet without any issues.")
def recommendations():
"""Provides recommendations on defending against the 'Ping of Death' attack."""
print("\nRecommendations:")
print("- Keep systems and software updated to ensure vulnerabilities are patched.")
print("- Monitor network traffic for unusual patterns or sizes of ICMP packets.")
print("- Implement network rules or firewalls to block or limit ICMP traffic if necessary.")
print("- Educate network users about the risks and signs of potential attacks.\n")
def simulate_large_icmp_packet(target_ip, packet_size, mode):
"""Simulates sending ICMP packets based on the chosen mode and packet size."""
packet = b'O' * packet_size
print(f"Starting simulation for {duration} seconds...")
start_time = time.time()
packet_count = 0
while time.time() - start_time < duration:
# Simulate sending the packet
if mode == "1":
packet_count += 1
print(f"Simulated sending packet {packet_count} to {target_ip}...")
time.sleep(1) # Pause for a second between packets for readability
print(f"\nSimulated sending packet {packet_count} to {target_ip}...")
print(f"Simulation complete. Sent a total of {packet_count} packets.")
print("In a real-world scenario, the target system might become unresponsive or crash if it cannot handle the continuous stream of oversized packets.")
elif mode == "2":
duration = 10
print(f"\nStarting continuous packet simulation for {duration} seconds...")
start_time = time.time()
while time.time() - start_time < duration:
packet_count += 1
print(f"Simulated sending packet {packet_count} to {target_ip}...")
time.sleep(1)
else:
packet_count += 1
print(f"\nSimulated sending safe packet {packet_count} to {target_ip}...")
print("\nSimulation complete.")
def main():
"""
Main function to interact with the user and gather input for the simulation.
"""
"""Main function to guide the user through the simulation."""
introduction()
# Get target IP from the user
target_ip = input("Enter the target IP address: ")
mode = choose_mode()
# Validate IP address format
target_ip = input("\nEnter the target IP address: ")
try:
socket.inet_aton(target_ip)
except socket.error:
print("Invalid IP address format.")
return
# Get packet size from the user
try:
packet_size = int(input("Enter the desired packet size (default is 70000 bytes): "))
except ValueError:
print("Invalid packet size. Using default value of 70000 bytes.")
packet_size = 70000
if mode in ["1", "2"]:
try:
packet_size = int(input("Enter the desired packet size (default is 70000 bytes): "))
except ValueError:
print("Invalid packet size. Using default value of 70000 bytes.")
packet_size = 70000
else:
packet_size = 1400 # Typical size for a safe ICMP packet
# Get simulation duration from the user
try:
duration = int(input("Enter the duration in seconds for the simulation (default is 10 seconds): "))
except ValueError:
print("Invalid duration. Using default value of 10 seconds.")
duration = 10
# Run the simulation
simulate_large_icmp_packet(target_ip, packet_size, duration)
feedback_on_packet_size(packet_size)
simulate_large_icmp_packet(target_ip, packet_size, mode)
potential_outcomes(mode, packet_size)
recommendations()
if __name__ == "__main__":
main()