Python original socket programming requires the construction of an individual HTTP data packet in the experiment, and the use of SOCK_STREAM to send data packets requires complete TCP interaction.
Therefore, we want to use the original socket for programming, construct data packets directly, and send data at the IP layer, that is, use SOCK_RAW for data transmission.
The advantage of SOCK_RAW is that it can completely modify the data packets, process all data packets on the IP layer, and modify fields without the limitations of UDP and TCP.
The following describes how to construct an HTTP packet,
The IP layer and TCP layer use the python Impacket library, and fill in the http content.
#! /Usr/bin/env python # emerge # Name: raw_http.py # Purpose: construct a raw http get packet # Licence: PythonTab.com # export 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 ()