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 socket
import time import time
def simulate_large_icmp_packet(target_ip, packet_size=70000, duration=10): def introduction():
""" """Provides a brief introduction to the 'Ping of Death' attack."""
Simulates sending a large ICMP packet in a loop for a specified duration. 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: def choose_mode():
- target_ip (str): The target IP address. """Allows the user to choose a simulation mode."""
- packet_size (int, optional): The size of the ICMP packet. Default is 70000 bytes. print("Choose a mode of simulation:")
- duration (int, optional): The duration in seconds for which the simulation runs. Default is 10 seconds. 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.")
print(f"Attempting to create an ICMP packet of size {packet_size} bytes to {target_ip}...") 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: 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.") 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 packet = b'O' * packet_size
print(f"Starting simulation for {duration} seconds...")
start_time = time.time()
packet_count = 0 packet_count = 0
while time.time() - start_time < duration: if mode == "1":
# Simulate sending the packet
packet_count += 1 packet_count += 1
print(f"Simulated sending packet {packet_count} to {target_ip}...") print(f"\nSimulated sending packet {packet_count} to {target_ip}...")
time.sleep(1) # Pause for a second between packets for readability
print(f"Simulation complete. Sent a total of {packet_count} packets.") elif mode == "2":
print("In a real-world scenario, the target system might become unresponsive or crash if it cannot handle the continuous stream of oversized packets.") 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(): def main():
""" """Main function to guide the user through the simulation."""
Main function to interact with the user and gather input for the simulation. introduction()
"""
# Get target IP from the user mode = choose_mode()
target_ip = input("Enter the target IP address: ")
# Validate IP address format target_ip = input("\nEnter the target IP address: ")
try: try:
socket.inet_aton(target_ip) socket.inet_aton(target_ip)
except socket.error: except socket.error:
print("Invalid IP address format.") print("Invalid IP address format.")
return return
# Get packet size from the user if mode in ["1", "2"]:
try: try:
packet_size = int(input("Enter the desired packet size (default is 70000 bytes): ")) packet_size = int(input("Enter the desired packet size (default is 70000 bytes): "))
except ValueError: except ValueError:
print("Invalid packet size. Using default value of 70000 bytes.") print("Invalid packet size. Using default value of 70000 bytes.")
packet_size = 70000 packet_size = 70000
else:
packet_size = 1400 # Typical size for a safe ICMP packet
# Get simulation duration from the user feedback_on_packet_size(packet_size)
try: simulate_large_icmp_packet(target_ip, packet_size, mode)
duration = int(input("Enter the duration in seconds for the simulation (default is 10 seconds): ")) potential_outcomes(mode, packet_size)
except ValueError: recommendations()
print("Invalid duration. Using default value of 10 seconds.")
duration = 10
# Run the simulation
simulate_large_icmp_packet(target_ip, packet_size, duration)
if __name__ == "__main__": if __name__ == "__main__":
main() main()