Scapy - 来自数据包列表的 TCPSession

Scapy - TCPSession from list of packets

我正在尝试使用 TCPSession 功能(例如:sniff(offline="./my_file.pcap", prn=func, store=False, session=TCPSession))但没有创建 PCAP 文件。

我收到了一个 RAW 数据包列表,因此我可以构建一个 Scapy 数据包列表,但我需要 TCPSession 功能,因为 HTTP 数据包:没有 TCPSession headers 和 body 位于不同的数据包中,因此 HTTP 层 Class 无法识别 body 部分。

所以我有这段代码可以找到 HTTP 请求:

import pickle
from scapy.all import *
from scapy.layers import http
load_layer("http")

def expand(x):
    yield x
    while x.payload:
        x = x.payload
        yield x

file_pickle = open('prueba.pkl','rb')
pkt_list = pickle.load(file_pickle)

for pkt_raw in pkt_list:
    p = Ether(pkt_raw)
    if p.haslayer(IP):
        srcIP = p[IP].src
        if p.haslayer(HTTP):
            if p.haslayer(HTTPRequest):
                print(list(expand(p)), end="\n---------------------------------------------------\n")

此代码的执行找到了 HTTP 请求,但没有 POST 请求的 Body 部分:

[...]<HTTPRequest  Method='POST' Path='/NP3POCF.jsp' Http_Version='HTTP/1.1' Accept='*/*' Accept_Encoding='gzip, deflate' Connection='keep-alive' Content_Length='56' Content_Type='application/x-www-form-urlencoded' Host='172.16.191.129' User_Agent='python-requests/2.7.0 CPython/3.7.5 Linux/5.3.0-kali2-amd64' |>]

使用带有 TCPSession 的嗅探器(例如 Scapy 嗅探功能),数据包具有包含请求的 body 的原始层。

申请TCPSession有什么帮助吗?谢谢。

您可以用 X 调用 sniff(offline=X) 数据包列表、数据包、文件名或文件列表。 确保您使用的是 github 开发版(参见 https://scapy.readthedocs.io/en/latest/installation.html#current-development-version),因为我不确定它是否已发布。