Skip to content

Commit 0fed7b2

Browse files
authored
Merge pull request #206 from SimardeepSingh-zsh/Simaroberfest
Initial commit of SYN Flood Protection Tool
2 parents d5da8fa + ee6080b commit 0fed7b2

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# SYN Flood Protection Tool
2+
A simple Python script to protect against SYN flood attacks by enabling SYN cookies.
3+
4+
## Overview
5+
6+
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.
7+
8+
**Features:**
9+
10+
- SYN flood protection using SYN cookies.
11+
- Customizable response message.
12+
- Basic error handling and logging.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import socket
2+
import os
3+
4+
def enable_syn_cookies():
5+
with open("/proc/sys/net/ipv4/tcp_syncookies", "w") as file:
6+
file.write("1")
7+
8+
def protect(target_ip, target_port):
9+
enable_syn_cookies()
10+
11+
# Create a socket
12+
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
13+
14+
# Bind the socket to the target IP and port
15+
s.bind((target_ip, target_port))
16+
17+
# Listen for incoming connections
18+
s.listen(5)
19+
20+
print(f"Listening on {target_ip}:{target_port}...")
21+
22+
while True:
23+
try:
24+
client_socket, addr = s.accept()
25+
print(f"Received connection from {addr[0]}:{addr[1]}")
26+
client_socket.send("Thank you for connecting.".encode())
27+
client_socket.close()
28+
except socket.error as e:
29+
print(f"Socket error: {str(e)}")
30+
31+
if __name__ == "__main__":
32+
target_ip = "0.0.0.0" # Use the IP address you want to protect
33+
target_port = 80 # Use the port you want to protect
34+
35+
protect(target_ip, target_port)

0 commit comments

Comments
 (0)