diff --git a/week02/easy/client.py b/week02/easy/client.py index 58924dd..9bb3051 100644 --- a/week02/easy/client.py +++ b/week02/easy/client.py @@ -14,8 +14,8 @@ from random import randrange log = logging.getLogger(__name__) TCP_CLIENTS = {} # ((IP, port) -> [sent_packets]) -# 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 = '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_PORT = 20102 COOKIE_SECRET = 'TASTY_COOKIES123' INITIAL_SEQ = 1337 @@ -31,7 +31,7 @@ def handle_packet(packet: Packet): 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) - 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='A', seq=COOKIE, ack=packet[TCP].seq) resp = (ip / syn) send(resp) if packet.haslayer(TCP) and packet[TCP].sport == SERVER_PORT and packet[TCP].dport == SRC_PORT and packet[TCP].flags == "A": @@ -48,7 +48,7 @@ def start_sniffing(): prn=handle_packet, store=False, monitor=True, - iface='eth0', # set to your interface. IMPORTANT: SET TO enX0 FOR AUTOGRADER!!! + iface='enX0', # set to your interface. IMPORTANT: SET TO enX0 FOR AUTOGRADER!!! ) COOKIE = generate_syn_cookie(SERVER_IP, SERVER_PORT, COOKIE_SECRET) diff --git a/week02/easy/server.py b/week02/easy/server.py index b9ab53d..d5efb75 100644 --- a/week02/easy/server.py +++ b/week02/easy/server.py @@ -73,7 +73,7 @@ def handle_packet(packet: Packet): send(initial_syn) else: - if (0x02 in packet[TCP].flags) or (not seq == expected_cookie) or (not ack == INITIAL_SEQ): + if ("S" in packet[TCP].flags) or (not seq == expected_cookie) or (not ack == INITIAL_SEQ): print(f'Invalid cookie {seq}, expected {expected_cookie}') rst = get_rst(src_ip, src_port, seq) send(rst)