Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python-Scapy or the like-How can I create an HTTP GET request at the packet level

Tags:

I am a moderate programmer, just getting into network programming.

As an attempt to improve my understanding of networks in general, I am trying to perform several basic HTTP actions from the packet level. My question is this: How might I use a library such as SCAPY to build an HTTP GET request and assosciated items at the packet level? I realise this may sound odd, but I can't seem to find any information detailing it, and my own attempts with PAROS and Ethereal have been... Less than satisfactory.

Thanks for any offered help!

Trimiert

like image 615
Trimiert Avatar asked Jan 20 '11 18:01

Trimiert


People also ask

Which command in Scapy would help you send a packet you just created?

Sending packets The send() function will send packets at layer 3. That is to say, it will handle routing and layer 2 for you. The sendp() function will work at layer 2. It's up to you to choose the right interface and the right link layer protocol.


1 Answers

If you want to do a full three-way handshake, you'll have to do it manually.

Start with your SYN packet:

>>> syn = IP(dst='www.google.com') / TCP(dport=80, flags='S') >>> syn <IP  frag=0 proto=tcp dst=Net('www.google.com') |<TCP  dport=www flags=S |>> 

Then receive the SYN-ACK packet from the server, sr1 works. Then send your HTTP GET request:

>>> syn_ack = sr1(syn) Begin emission: Finished to send 1 packets. * Received 1 packets, got 1 answers, remaining 0 packets  >>> syn_ack <IP  version=4L ihl=5L tos=0x0 len=44 id=424 flags= frag=0L ttl=55 proto=tcp chksum=0x2caa src=74.125.226.148 dst=10.20.30.40 options=[] |<TCP  sport=www dport=ftp_data seq=3833491143 ack=1 dataofs=6L reserved=0L flags=SA window=5720 chksum=0xd8b6 urgptr=0 options=[('MSS', 1430)] |<Padding  load='\x00\x00' |>>> 

Then set your TCP sequence and ack numbers and send the GET:

getStr = 'GET / HTTP/1.1\r\nHost: www.google.com\r\n\r\n' request = IP(dst='www.google.com') / TCP(dport=80, sport=syn_ack[TCP].dport,              seq=syn_ack[TCP].ack, ack=syn_ack[TCP].seq + 1, flags='A') / getStr reply = sr1(request) 
like image 167
nmichaels Avatar answered Sep 25 '22 02:09

nmichaels