The following starts to construct the HTTP packet,
The IP layer and the TCP layer use the Python impacket Library, and the HTTP content is filled out by itself.
Copy Code code as follows:
#!/usr/bin/env python
#-------------------------------------------------------------------------------
# Name:raw_http.py
# Purpose:construct a raw HTTP GET packet
#
# Author:yangjun
#
# created:08/02/2014
# Copyright: (c) Yangjun 2014
# Licence: <your licence>
#-------------------------------------------------------------------------------
Import Sys
Import socket
From Impacket import Impactdecoder, Impactpacket
def main ():
If Len (SYS.ARGV) < 3:
print ' use:%s <src ip> <dst ip> '% sys.argv[0]
print ' use:%s <src ip> <dst ip> <cnt> '% sys.argv[0]
Sys.exit (1)
Elif len (sys.argv) = = 3:
src = sys.argv[1]
DST = sys.argv[2]
CNT = 1
Elif Len (sys.argv) ==4:
src = sys.argv[1]
DST = sys.argv[2]
CNT = sys.argv[3]
Else
Print "Input error!"
Sys.exit (1)
#print SRC, DST
ip = Impactpacket.ip ()
IP.SET_IP_SRC (SRC)
IP.SET_IP_DST (DST)
# Create A new ICMP packet of type ECHO.
ICMP = impactpacket.icmp ()
TCP = IMPACTPACKET.TCP ()
Tcp.set_th_sport (55968)
Tcp.set_th_dport (80)
TCP.SET_TH_SEQ (1)
Tcp.set_th_ack (1)
Tcp.set_th_flags (0x18)
Tcp.set_th_win (64)
Tcp.contains (Impactpacket.data ("get/att/diylife/41264/528 http/1.1\r\nhost:192.168.111.1\r\naccept-encoding: identity\r\n\r\n "))
Ip.contains (TCP)
# Open a raw socket. Special permissions are usually required.
s = socket.socket (socket.af_inet, socket. SOCK_RAW, Socket. IPPROTO_TCP)
S.setsockopt (socket. IPPROTO_IP, Socket. IP_HDRINCL, 1)
seq_id = 0
While CNT >= 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 ()
after running, grab the bag as follows: