upated bash

This commit is contained in:
2024-11-10 18:50:30 +09:00
parent 7f126ce5f8
commit ca0fd21d73
2 changed files with 10 additions and 3 deletions

View File

@ -14,8 +14,8 @@ from random import randrange
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
TCP_CLIENTS = {} # ((IP, port) -> [sent_packets]) TCP_CLIENTS = {} # ((IP, port) -> [sent_packets])
# SERVER_IP = '131.159.15.68' # don't use the domain name in this case SERVER_IP = '131.159.15.68' # don't use the domain name in this case
SERVER_IP = '192.168.1.4' # don't use the domain name in this case # SERVER_IP = '192.168.1.4' # don't use the domain name in this case
SERVER_PORT = 20102 SERVER_PORT = 20102
COOKIE_SECRET = 'TASTY_COOKIES123' COOKIE_SECRET = 'TASTY_COOKIES123'
INITIAL_SEQ = 1337 INITIAL_SEQ = 1337
@ -27,12 +27,18 @@ def generate_syn_cookie(client_ip: str, client_port: int, server_secret: str):
def handle_packet(packet: Packet): def handle_packet(packet: Packet):
# TODO: please implement me! # TODO: please implement me!
packet.show()
if packet.haslayer(TCP) and packet[TCP].sport == SERVER_PORT and packet[TCP].dport == SRC_PORT and packet[TCP].flags == "SA": if packet.haslayer(TCP) and packet[TCP].sport == SERVER_PORT and packet[TCP].dport == SRC_PORT and packet[TCP].flags == "SA":
print("received SA packett")
ip = IP(dst=SERVER_IP) ip = IP(dst=SERVER_IP)
syn = TCP(sport=SRC_PORT, dport=SERVER_PORT, flags='SA', seq=COOKIE, ack=packet[TCP].seq) syn = TCP(sport=SRC_PORT, dport=SERVER_PORT, flags='SA', seq=COOKIE, ack=packet[TCP].seq)
resp = (ip / syn) resp = (ip / syn)
send(resp) send(resp)
packet.show() if packet.haslayer(TCP) and packet[TCP].sport == SERVER_PORT and packet[TCP].dport == SRC_PORT and packet[TCP].flags == "A":
print("received acknowledgement")
payload = bytes(packet[TCP].payload).decode(errors='ignore')
print("Extracted flag:", payload) # This should print "hello world"
# Function to start the packet sniffing # Function to start the packet sniffing
def start_sniffing(): def start_sniffing():

View File

@ -0,0 +1 @@
sudo iptables-legacy -A OUTPUT -p tcp -d 131.159.15.68 --tcp-flags RST RST -j DROP