Hello. This is Akako. Continuing from the last time, this time I would like to summarize up to the packet transmission that made Scapy.
Please see Previous article. Again, we'll assume that you're running line by line on an interactive shell that launches scapy directly.
ICMP(PING)
#Creating ICMP packets for google server
#Image of ICMP on top of IP packet
packet = IP(dst='www.google.com')/ICMP()
#Show the contents of the packet
packet.show()
#Send packet
#& Display of returned packets
sr1(packet)
TCP(HTTP)
'''Connection flow in TCP'''
'''Creating a basic packet'''
#Creating an IP packet
ip = IP(dst='www.google.com')
# TCP(HTTP)Packet creation
# sport,seq is appropriate
#dport is a standard 80th edition port,flag is'S'
tcp = TCP(sport=50000,dport=80,flags='S',seq=100)
'''3 Implementation of handshake'''
#Create SYN packet
syn= ip/tcp
#Send SYN packet
#& Receive SYN ACK
syn_ack = sr1(syn)
'''Creating an HTTP request(Creating an ACK packet)'''
#ACK packet settings
tcp.seq += 1
tcp.ack = syn_ack.seq + 1
#The flag of the ACK packet is'A'
tcp.flags = 'A'
#ACK packet transmission
ack = ip/tcp
send(ack)
#Can carry HTTP GET packets
get = 'GET / HTTP/1.1\r\nHost: www.google.com\r\n\r\n'
http = ip/tcp/get
#Send request
response = sr(http, multi=1, timeout=1)
tcp.seq += len(get)
#Displaying the response
response[0][1][1]["Raw"].load
'''Disconnect'''
#Continuation of the above code
#Sending FINACK packets with FA flag
tcp.flags = 'FA'
fin_ack = sr1(ip/tcp)
tcp.seq += 1
#Returns ACK at the end
tcp.ack = fin_ack.seq + 1
tcp.flags = 'A'
send(ip/tcp)
Recommended Posts