“jspcap”模块已弃用并重命名为“pypcapkit”。

jspcap的Python项目详细描述


jspcap

jspcap项目是一个开源的python程序,专注于解析和分析pcap,它作为流pcap文件提取器工作。支持jsformat,支持多种输出报表格式。

< Buff行情>

请注意,整个项目仅支持Python3.6或更高版本。


关于

jspcap是一个独立的开源库,仅使用jsformat作为其格式化输出转储程序。

< Buff行情>

有一个名为jspcapy的项目在jspcap上工作,这是一个用于提取pcap的命令行工具。

与流行的PCAP文件提取器不同,例如scapydpktpyshark等,jspcap使用流式处理策略读取输入文件。即逐帧读取,减少内存占用,并以某种方式提高效率。

模块结构

jspcap中,所有文件可以描述为以下六个部分。

  • 基金会(<代码> JSPCAP,基金会<代码>)——综合文件I/O和协议分析,在所有网络层中协调信息交换
  • interface(jspcap.interface)--用于jspcap库的用户界面,用于标准化和简化此库的使用
  • 重新组装(jspcap.rejomby)——基于rfc815中描述的算法,实现数据报重新组装。IP和TCP数据包的组合
  • ipsuite(jspcap.ipsuite)——internet协议套件的构造函数集合
  • 协议(jspcap.protocols)——所有协议系列的集合,包括详细的实现和方法
  • 实用程序(jspcap.utilities)——四个实用程序函数和类的集合
  • coreKit(jspcap.coreKit)--用于jspcap实现的核心实用程序
  • dumpkit(jspcap.dumpkit)--用于jspcap实现的转储实用程序

 src=

发动机比较

此外,由于jspcap的复杂性,它的提取过程每包大约需要0.01秒,这还不够理想。因此,jspcap引入了替代的提取引擎来加速这个过程。到目前为止,jspcap支持scapydpkt,以及pyshark。另外,jspcap支持两种多处理策略(server&;pipeline)。有关详细信息,请参阅文档。

<表><广告>发动机 性能(每包秒数)< /广告><正文>默认值0.0145251388549805服务器0.12124489148457845管道0.01445042414863079scapy0.0024434357844035dpkt0.0003609057267506917pyshark0.0792640733718872

< /P>

安装

< Buff行情>

请注意,jspcap仅支持3.6以后的python版本

只需运行以下命令即可安装pypi的最新版本:

pip install jspcap

或从Git存储库安装:

$ git clone https://github.com/JarryShaw/jspcap.git
$ python setup.py install

< /P>

用法

文档

接口

<表><广告>名称说明 < /广告><正文>提取提取PCAP文件分析分析应用层数据包重新组合碎片数据报跟踪跟踪TCP数据包流

格式
<表><广告>名称说明 < /广告><正文>jsonjavascript对象表示法(json)格式plistMacOS属性列表(PLIST)格式 树状图文本格式 pcapPCAP格式
<表><广告>名称说明 < /广告><正文>raw没有特定层链接数据链路层 inet互联网层 传输传输层 应用程序应用程序层
发动机 <表><广告>名称说明 < /广告><正文>jspcap默认引擎 mpserver具有服务器处理策略的多处理引擎 mppipeline采用流水线策略的多处理引擎 dpkt引擎 引擎 pyshark引擎

协议 <表><广告>名称说明 < /广告><正文>raw原始数据包数据arp地址解析协议 以太网DE>以太网协议 第二层隧道协议 首先打开最短路径rarp反向地址解析协议 vlan802.1q客户VLAN标记类型 ah验证标题主机标识协议 hopoptIPv6逐跳选项 ip互联网协议 ipsec互联网协议安全性 ipv4互联网协议版本4 ipv6互联网协议版本6 ipv6框架IPv6的片段头 ipv6选项IPv6的目标选项 ipv6路由IPv6的路由头ipx网络数据包交换 mh机动性标题tcp传输控制协议 用户数据报协议 http超文本传输协议

文档可以在jspcap的子模块中找到。或者,您可以在test文件夹中找到使用示例。有关详细信息,请参阅源代码--docstrings应该可以帮助您:)

pshelppython中的函数应该总能帮助您解决问题。

cli用法

< Buff行情>

以下部分最初在jspcapy中描述,该部分现已弃用并合并到此存储库中。

如帮助手册中所示,它非常易于使用:

$ jspcapy --help
usage: jspcapy [-h] [-V] [-o file-name] [-f format] [-j] [-p] [-t] [-a] [-v]
               [-F] [-E PKG] [-P PROTOCOL] [-L LAYER]
               input-file-name

PCAP file extractor and formatted exporter

positional arguments:
  input-file-name       The name of input pcap file. If ".pcap" omits, it will
                        be automatically appended.

optional arguments:
  -h, --help            show this help message and exit
  -V, --version         show program's version number and exit
  -o file-name, --output file-name
                        The name of input pcap file. If format extension
                        omits, it will be automatically appended.
  -f format, --format format
                        Print a extraction report in the specified output
                        format. Available are all formats supported by
                        jsformat, e.g.: json, plist, and tree.
  -j, --json            Display extraction report as json. This will yield
                        "raw" output that may be used by external tools. This
                        option overrides all other options.
  -p, --plist           Display extraction report as macOS Property List
                        (plist). This will yield "raw" output that may be used
                        by external tools. This option overrides all other
                        options.
  -t, --tree            Display extraction report as tree view text. This will
                        yield "raw" output that may be used by external tools.
                        This option overrides all other options.
  -a, --auto-extension  If output file extension omits, append automatically.
  -v, --verbose         Show more information.
  -F, --files           Split each frame into different files.
  -E PKG, --engine PKG  Indicate extraction engine. Note that except default
                        or jspcap engine, all other engines need support of
                        corresponding packages.
  -P PROTOCOL, --protocol PROTOCOL
                        Indicate extraction stops after which protocol.
  -L LAYER, --layer LAYER
                        Indicate extract frames until which layer.

在大多数情况下,您应该指明输入PCAP文件的名称(扩展名可能省略),并且至少应指明输出格式(jsonplisttree)。一旦未指定格式,输出文件的名称必须具有正确的扩展名(*.json*.plist,或*.txt),否则将引发格式错误

对于verbose模式,提取时将打印详细信息(如下示例)。和自动扩展名标志对输出文件有效,指示是否应附加扩展名。

< /P>

样品

使用示例

test文件夹中所述,jspcap非常容易使用,只需三个动词作为其主界面。下面显示了几种情况。

  • 提取一个pcap文件并将结果转储到一个特定的文件(不需要重新组合)

    importjspcap# dump to a PLIST file with no frame storage (property frame disabled)plist=jspcap.extract(fin='in.pcap',fout='out.plist',format='plist',store=False)# dump to a JSON file with no extension auto-completejson=jspcap.extract(fin='in.cap',fout='out.json',format='json',extension=False)# dump to a folder with each tree-view text file per frametree=jspcap.extract(fin='in.pcap',fout='out',format='tree',files=True)
  • 提取PCAP文件并从帧中提取IP数据包(IPv4和IPv6)(无输出文件)

    >>>importjspcap>>>extraction=jspcap.extract(fin='in.pcap',nofile=True)>>>frame0=extraction.frame[0]# check if IP in this frame, otherwise ProtocolNotFound will be raised>>>flag=jspcap.IPinframe0>>>tcp=frame0[jspcap.IP]ifflagelseNone
  • 提取一个pcap文件并重新组装tcp负载(没有输出文件或帧存储)

    importjspcap# set strict to make sure full reassemblyextraction=jspcap.extract(fin='in.pcap',store=False,nofile=True,tcp=True,strict=True)# print extracted packet if HTTP in reassembled payloadsforpacketinextraction.reassembly.tcp:forreassemblyinpacket.packets:ifjspcap.HTTPinreassembly.protochain:print(reassembly.info)

cli示例

jspcap的cli(命令行界面)有两种不同的访问方式。

  • 通过控制台脚本--直接使用命令名jspcapy(如示例所示)
  • 通过python模块--python-m jspcap[…]的工作原理与上面的完全相同

下面是一些使用示例:

  • 导出到MacOS属性列表(xcode对此格式有特殊支持)
$ jspcapy in --format plist --verbose
?Loading file 'in.pcap'
 - Frame   1: Ethernet:IPv6:ICMPv6
 - Frame   2: Ethernet:IPv6:ICMPv6
 - Frame   3: Ethernet:IPv4:TCP
 - Frame   4: Ethernet:IPv4:TCP
 - Frame   5: Ethernet:IPv4:TCP
 - Frame   6: Ethernet:IPv4:UDP
?Report file stored in 'out.plist'
  • 导出到JSON文件(未指定格式)
$ jspcapy in --output out.json --verbose
?Loading file 'in.pcap'
 - Frame   1: Ethernet:IPv6:ICMPv6
 - Frame   2: Ethernet:IPv6:ICMPv6
 - Frame   3: Ethernet:IPv4:TCP
 - Frame   4: Ethernet:IPv4:TCP
 - Frame   5: Ethernet:IPv4:TCP
 - Frame   6: Ethernet:IPv4:UDP
?Report file stored in 'out.json'
  • 导出到文本树视图文件(不带扩展名自动更正)
$ jspcapy in --output out --format tree --verbose
?Loading file 'in.pcap'
 - Frame   1: Ethernet:IPv6:ICMPv6
 - Frame   2: Ethernet:IPv6:ICMPv6
 - Frame   3: Ethernet:IPv4:TCP
 - Frame   4: Ethernet:IPv4:TCP
 - Frame   5: Ethernet:IPv4:TCP
 - Frame   6: Ethernet:IPv4:UDP
?Report file stored in 'out'

< /P>

待办事项

  • [X]指定rawpacket
  • [X]介面动词
  • [X]查看文档字符串
  • [X]合并jspcapy
  • []编写文档
  • []实现IP和MAC地址容器
  • []实现选项列表提取器
  • []实施更多协议

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
Java分割字符串性能   java通过apache POI检索powerpoint文件(.PPTX)中超链接幻灯片的内容   java Dropwizard/Jersey为资源返回204   使用ObjectInputStream#readUnshared()时发生java意外OutOfMemoryError   if语句表示输入字符串之前的数字总和   java将Android应用程序连接到外部数据库(phpmyadmin)   java如何在JFrame中相对地定位项目?   java JSONObject。toMap()实现   java无法启动jboss服务。在船底。部署。默认服务器。默认主机。但课堂是有空的   java使用hamcrest将两个单独列表中的每个项目与自己的matcher进行比较   java我可以用@RepeatedTest注释JUnit5获得变量值吗   java小程序选项不会在每次更改选项项(列表)时调用项状态更改方法。为什么?   JavaPowerMock与依赖注入   通过网络解耦UI和计算的java简单示例   java PostgreSql在本地连接到远程服务器GCP   javascript无法将Json数据从Ajax发送到Servlet   java连接线程建立失败   数组如何对Java中的数据集进行排序