diff --git a/week02/easy/client.py b/week02/easy/client.py index 8ed1bc5..9fd2922 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 @@ -27,12 +27,18 @@ def generate_syn_cookie(client_ip: str, client_port: int, server_secret: str): def handle_packet(packet: Packet): # 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": + 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) resp = (ip / syn) 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 def start_sniffing(): diff --git a/week02/easy/stop_autot_reset.sh b/week02/easy/stop_autot_reset.sh new file mode 100644 index 0000000..a3ccbc9 --- /dev/null +++ b/week02/easy/stop_autot_reset.sh @@ -0,0 +1 @@ +sudo iptables-legacy -A OUTPUT -p tcp -d 131.159.15.68 --tcp-flags RST RST -j DROP \ No newline at end of file