TCP 3 Way Basics
s_ip = IP ; s_port = port ; s_seq = seq # ; s_ack = ack #
d_ip = IP ; d_port = port ; d_seq = seq # ; d_ack = ack #
handshake
s_ip_port -> d_ip:d_port, SYN, s_seq, s_ack
d:ip:d_port -> s_ip_port, SYN/ACK, d_seq, d_ack=(s_seq + 1)
s_ip_port -> d_ip:d_port, ACK, d_seq + 1, s_ack=(d_seq + 1)
Sample Script
#!/usr/bin/python
from scapy.all import *
ip=IP(src="10.0.0.1", dst="20.0.0.2")
TCP_SYN=TCP(sport=1500, dport=80, flags="S", seq=100)
TCP_SYNACK=sr1(ip/TCP_SYN)
my_ack = TCP_SYNACK.seq + 1
TCP_ACK=TCP(sport=1500, dport=80, flags="A", seq=101, ack=my_ack)
send(ip/TCP_ACK)
my_payload="space for rent!"
TCP_PUSH=TCP(sport=1500, dport=80, flags="PA", seq=102, ack=my_ack)
send(ip/TCP_PUSH/my_payload)
s_ip = IP ; s_port = port ; s_seq = seq # ; s_ack = ack #
d_ip = IP ; d_port = port ; d_seq = seq # ; d_ack = ack #
handshake
s_ip_port -> d_ip:d_port, SYN, s_seq, s_ack
d:ip:d_port -> s_ip_port, SYN/ACK, d_seq, d_ack=(s_seq + 1)
s_ip_port -> d_ip:d_port, ACK, d_seq + 1, s_ack=(d_seq + 1)
Sample Script
#!/usr/bin/python
from scapy.all import *
ip=IP(src="10.0.0.1", dst="20.0.0.2")
TCP_SYN=TCP(sport=1500, dport=80, flags="S", seq=100)
TCP_SYNACK=sr1(ip/TCP_SYN)
my_ack = TCP_SYNACK.seq + 1
TCP_ACK=TCP(sport=1500, dport=80, flags="A", seq=101, ack=my_ack)
send(ip/TCP_ACK)
my_payload="space for rent!"
TCP_PUSH=TCP(sport=1500, dport=80, flags="PA", seq=102, ack=my_ack)
send(ip/TCP_PUSH/my_payload)