From ee6080b55ba972d106183d353d7674ea3e9d59e9 Mon Sep 17 00:00:00 2001 From: Simardeep Singh <1003simar@gmail.com> Date: Sat, 14 Oct 2023 21:33:08 -0600 Subject: [PATCH] Initial commit of SYN Flood Protection Tool --- Python Projects/Port Scanner/Readme.MD | 12 ++++++++ Python Projects/Port Scanner/syn_flood.py | 35 +++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 Python Projects/Port Scanner/Readme.MD create mode 100644 Python Projects/Port Scanner/syn_flood.py diff --git a/Python Projects/Port Scanner/Readme.MD b/Python Projects/Port Scanner/Readme.MD new file mode 100644 index 00000000..bf9c2f00 --- /dev/null +++ b/Python Projects/Port Scanner/Readme.MD @@ -0,0 +1,12 @@ +# SYN Flood Protection Tool +A simple Python script to protect against SYN flood attacks by enabling SYN cookies. + +## Overview + +This Python script enables SYN cookies to protect against SYN flood attacks. It listens on a specified IP address and port and responds to incoming connections with a customizable message. + +**Features:** + +- SYN flood protection using SYN cookies. +- Customizable response message. +- Basic error handling and logging. \ No newline at end of file diff --git a/Python Projects/Port Scanner/syn_flood.py b/Python Projects/Port Scanner/syn_flood.py new file mode 100644 index 00000000..0b3ffd4a --- /dev/null +++ b/Python Projects/Port Scanner/syn_flood.py @@ -0,0 +1,35 @@ +import socket +import os + +def enable_syn_cookies(): + with open("/proc/sys/net/ipv4/tcp_syncookies", "w") as file: + file.write("1") + +def protect(target_ip, target_port): + enable_syn_cookies() + + # Create a socket + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + + # Bind the socket to the target IP and port + s.bind((target_ip, target_port)) + + # Listen for incoming connections + s.listen(5) + + print(f"Listening on {target_ip}:{target_port}...") + + while True: + try: + client_socket, addr = s.accept() + print(f"Received connection from {addr[0]}:{addr[1]}") + client_socket.send("Thank you for connecting.".encode()) + client_socket.close() + except socket.error as e: + print(f"Socket error: {str(e)}") + +if __name__ == "__main__": + target_ip = "0.0.0.0" # Use the IP address you want to protect + target_port = 80 # Use the port you want to protect + + protect(target_ip, target_port)