【问题标题】:HTTPResponse packet in Scapy only has partial responseScapy 中的 HTTPResponse 数据包只有部分响应
【发布时间】:2022-07-20 07:03:35
【问题描述】:

我有以下代码来使用 Scapy 嗅探 HTTPRequest 和 HTTPResponse:

from scapy.all import *
from scapy.layers.http import *
from bs4 import BeautifulSoup


def inspect(a):
    if HTTPRequest in a:
        print("\n{} ----HTTPRequest----> {}:{}:\n{}".format(a[IP].src, a[IP].dst, a[IP].dport, str(bytes(a[TCP].payload))))
    if HTTPResponse in a:
        response = str(bytes(a[TCP].payload))
        soup = BeautifulSoup(response, "html.parser")
        print("\n{} ----HTTPResponse----> {}:{}:\n{}".format(a[IP].src, a[IP].dst, a[IP].dport, soup))

sniff(prn=inspect)

但是响应仅包含部分 HTTP 响应。我如何获得其余的响应。

请指教。

【问题讨论】:

    标签: python python-3.x http httpresponse scapy


    【解决方案1】:

    因为 HTTP 帧是在多个 TCP 帧上分段的。你只需要

    >>> sniff(prn=inspect, session=TCPSession)
    

    (见https://scapy.readthedocs.io/en/latest/usage.html?highlight=tlssession#advanced-sniffing-sniffing-sessions

    【讨论】:

      猜你喜欢
      • 2016-10-22
      • 1970-01-01
      • 2021-06-03
      • 2017-05-26
      • 2011-01-15
      • 1970-01-01
      • 1970-01-01
      • 2012-07-04
      • 1970-01-01
      相关资源
      最近更新 更多