The source code is as follows:
1 fromScapy.allImport*2 3 4 ImportLogging5Logging.getlogger ('Scapy.runtime'). SetLevel (Logging. ERROR)6 7TARGET_IP ='192.168.1.1'8Target_port = 809data ='get/http/1.0 \r\n\r\n'Ten One defstart_tcp (target_ip,target_port): A GlobalSport,s_seq,d_seq#used primarily for TCP3 this handshake to continue sending data after the connection is established - Try: - #first handshake, send SYN packet theAns = SR1 (IP (DST=TARGET_IP)/tcp (Dport=target_port,sport=randshort (), Seq=randint (), flags='S'), verbose=False) -Sport = Ans[tcp].dport#Source Random Port -S_seq = Ans[tcp].ack#Source serial Number (in fact the initial value has been added to the server 1) -D_seq = ans[tcp].seq + 1#Confirmation number, you need to add the serial number of the server 1 + #third handshake, send ACK Confirmation package -Send (IP (DST=TARGET_IP)/tcp (dport=target_port,sport=sport,ack=d_seq,seq=s_seq,flags='A'), verbose=False) + exceptexception,e: A Print '[-] There are errors, please pay attention to check! ' at Printe - - defTrans_data (target_ip,target_port,data): - #establish a TCP connection first -START_TCP (target_ip=target_ip,target_port=target_port) - #Print Sport,s_seq,d_seq in #initiating a GET request -Ans = SR1 (IP (DST=TARGET_IP)/tcp (dport=target_port,sport=sport,seq=s_seq,ack=d_seq,flags=24)/data,verbose=False) to #ans.show () + #read data sent from the service side -RCV =Ans[raw] the PrintRCV * $ if __name__=='__main__':Panax Notoginseng #start_tcp (Target_ip,target_port) -Trans_data (Target_ip,target_port,data)
The results of the operation are as follows:
1 #python exp3.py2<meta http-equiv="Pragma"Content="No-cache">3<meta http-equiv="Expires"Content="Wed, 1997 08:21:57 GMT">4 notsupported</title> notSupportedWireshark grab bag as follows:
Simulate TCP3 handshake connection and send data with Python