Python-Scapy 之类的-如何在数据包级别创建 HTTP GET 请求
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4750793/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python-Scapy or the like-How can I create an HTTP GET request at the packet level
提问by Trimiert
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
特里米尔特
采纳答案by nmichaels
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)
回答by Thomas K
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"
回答by Cukic0d
FTR, as of Scapy 2.4.3, dissection of HTTP packets was implemented, among a util called "TCP_client" to do the 3 handshake automatically.
FTR,从 Scapy 2.4.3 开始,实现了对 HTTP 数据包的剖析,其中一个名为“TCP_client”的实用程序可以自动进行 3 次握手。
While it's not as teaching as the above answer, it doesn't hurt to have a look: https://scapy.readthedocs.io/en/latest/layers/http.html#use-scapy-to-send-receive-http-1-x
虽然它不像上面的答案那样教学,但看看它并没有什么坏处:https: //scapy.readthedocs.io/en/latest/layers/http.html#use-scapy-to-send-receive- http-1-x
load_layer("http")
req = HTTP()/HTTPRequest(
Accept_Encoding=b'gzip, deflate',
Cache_Control=b'no-cache',
Connection=b'keep-alive',
Host=b'www.secdev.org',
Pragma=b'no-cache'
)
a = TCP_client.tcplink(HTTP, "www.secdev.org", 80)
answser = a.sr1(req)
a.close()

