scapy抓取到的http响应包的内容不完整
附代码
from scapy.all import *
from scapy.layers.http import *
def get_http_response(response_packet):
if response_packet.haslayer(HTTPResponse):
print("\nNew packet")
print(response_packet)
print("[*]The Content_Length: ", response_packet.Content_Length)
print("[*]The load: ", response_packet.getlayer(Raw).load)
sniff(iface="VMware Virtual Ethernet Adapter for VMnet8", prn=get_http_response)
抓取到的数据包内容(不完整)
利用BurpSuite抓到的响应包内容
对比可见,代码只抓到的47行之前的内容,而且content length也是错的
可以尝试修改sniff函数的参数,如添加store参数。
在scapy官网上可以查看详细的资料,sniff函数的传入参数包括store,它的作用是指定一个Boolean,让sniff能够把包储存到内存中以供回调使用,就不会有包的内容不完整的问题了。可以尝试将store设置为True,并将参数prn改为None,这样scapy就能把所有抓到的包都存储到列表packets中,你可以通过遍历packets并调用get_httpresponse函数来获取完整的http响应包,例如:
```python
packets =sniff(iface="VMware Virtual Ethernet Adapter for VMnet8", store=True, prn=None)
for packet in packets:
get_http_response(packet)
此外,也可以使用Scapy内置的混杂模式(promiscuous mode)来获取完整的HTTP响应包。要使用混杂模式,只需要将snif函数调用时的参数promisc设置为True即可,示例代码如下:
sniff(iface="VMware Virtual Ethernet Adapter for VMnet8",
store=True,
prn=None,
promisc = True
)
```
混杂模式能够帮助你抓取到更多的包,即使是非目标机发出的包也能被捕获,这样就可以更容易地获取完整的HTTP响应包。