In the experiment, it is necessary to construct a separate HTTP data packet, and to send the packet using SOCK_STREAM, the full TCP interaction is required.
So you want to use the original socket programming, directly construct the packet, and send at the IP layer, that is, using SOCK_RAW for data transmission.
The advantage of using SOCK_RAW is that the packet can be fully modified to handle all packets on the IP layer and modify the fields without the limitation of UDP and TCP.
The following begins the construction of the HTTP packet,
The IP layer and TCP layer use Python's impacket Library, and the HTTP content is self-populated.
#!/usr/bin/env Python #-------------------------------------------------------------------------------# Name : raw_http.py# Purpose: construct a raw HTTP GET packet## Licence: pythontab.com #------------------- ------------------------------------------------------------ Import sysimport socketfrom impacket Import Impactdecoder, Impactpacket def main (): If Len (sys.argv) = 1: # Calculate its checksum. seq_id = seq_id + 1 tcp.set_th_seq (seq_id) tcp.calculate_checksum () # Send it to the target host. S.sendto (Ip.get_packet (), (dst,80)) cnt= cnt-1 if __name__ = = ' __main__ ': Main ()