h3ll0 2023-02-13 11:00 采纳率: 45.2%
浏览 55

scapy抓取到的http响应包的内容不完整

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)

抓取到的数据包内容(不完整)

img

利用BurpSuite抓到的响应包内容

img

对比可见,代码只抓到的47行之前的内容,而且content length也是错的

  • 写回答

1条回答 默认 最新

  • Yang2023. 2023-02-13 13:28
    关注

    可以尝试修改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响应包。

    评论

报告相同问题?

问题事件

  • 创建了问题 2月13日

悬赏问题

  • ¥20 这张图页脚大概具体代码该怎么写?
  • ¥20 WPF MVVM模式 handycontrol 框架, hc:SearchBar 控件 Text="{Binding NavMenusKeyWords}" 绑定取不到值
  • ¥15 需要手写数字信号处理Dsp三个简单题 不用太复杂
  • ¥15 数字信号处理考试111
  • ¥15 allegro17.2生成bom表是空白的
  • ¥15 请问一下怎么打通CAN通讯
  • ¥20 如何在 rocky9.4 部署 CDH6.3.2?
  • ¥35 navicat将excel中的数据导入mysql出错
  • ¥15 rt-thread线程切换的问题
  • ¥15 高通uboot 打印ubi init err 22