Python-Scapy 之类的-如何在数据包级别创建 HTTP GET 请求 [英] Python-Scapy or the like-How can I create an HTTP GET request at the packet level

查看:26
本文介绍了Python-Scapy 之类的-如何在数据包级别创建 HTTP GET 请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个中等程序员,刚开始接触网络编程.

为了提高我对网络的总体理解,我尝试从数据包级别执行几个基本的 HTTP 操作.我的问题是:如何使用 SCAPY 之类的库在数据包级别构建 HTTP GET 请求和关联项目?我意识到这听起来很奇怪,但我似乎无法找到任何详细信息,而且我自己对 PAROS 和 Ethereal 的尝试......不太令人满意.

感谢您提供的任何帮助!

特里米特

解决方案

如果要进行完整的三向握手,则必须手动进行.

从您的 SYN 数据包开始:

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

然后收到服务器发来的SYN-ACK包,sr1工作.然后发送您的 HTTP GET 请求:

<预><代码>>>>syn_ack = sr1(syn)开始发射:发完1个包.*收到 1 个数据包,得到 1 个答案,剩余 0 个数据包>>>同步确认<IP 版本=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=[] |运动=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='x00x00' |>>>

然后设置您的 TCP 序列和确认号码并发送 GET:

getStr = 'GET/HTTP/1.1
主机:www.google.com

'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回复 = sr1(请求)

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

解决方案

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='x00x00' |>>>

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

getStr = 'GET / HTTP/1.1
Host: www.google.com

'
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)

这篇关于Python-Scapy 之类的-如何在数据包级别创建 HTTP GET 请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆