Python-Scapy之类的 - 如何在数据包级别创建HTTP GET请求

时间:2021-02-13 20:15:40

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.

为了提高我对网络的理解,我试图从数据包级别执行几个基本的HTTP操作。我的问题是:我如何使用SCAPY等库来构建HTTP GET请求和数据包级别的相关项目?我意识到这可能听起来很奇怪,但我似乎无法找到任何详细说明的信息,而我自己对PAROS和Ethereal的尝试一直......不尽如人意。

Thanks for any offered help!

感谢您提供的任何帮助!

Trimiert

2 个解决方案

#1


34  

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

如果您想进行完全三次握手,则必须手动完成。

Start with your SYN packet:

从您的SYN数据包开始:

>>> 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工作。然后发送您的HTTP GET请求:

>>> 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:

然后设置您的TCP序列和确认号码并发送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)

#2


1  

Have you had a look at the tutorial? Just copying and pasting, this looks like it's going to assemble an HTTP request:

你看过这个教程了吗?只是复制和粘贴,看起来它将组装一个HTTP请求:

>>>  a=Ether()/IP(dst="www.slashdot.org")/TCP()/"GET /index.html HTTP/1.0 \n\n"

#1


34  

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

如果您想进行完全三次握手,则必须手动完成。

Start with your SYN packet:

从您的SYN数据包开始:

>>> 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工作。然后发送您的HTTP GET请求:

>>> 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:

然后设置您的TCP序列和确认号码并发送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)

#2


1  

Have you had a look at the tutorial? Just copying and pasting, this looks like it's going to assemble an HTTP request:

你看过这个教程了吗?只是复制和粘贴,看起来它将组装一个HTTP请求:

>>>  a=Ether()/IP(dst="www.slashdot.org")/TCP()/"GET /index.html HTTP/1.0 \n\n"