“jspcap”模块已弃用并重命名为“pypcapkit”。
jspcap的Python项目详细描述
jspcap
jspcap项目是一个开源的python程序,专注于解析和分析pcap,它作为流pcap文件提取器工作。支持jsformat
,支持多种输出报表格式。
请注意,整个项目仅支持Python3.6或更高版本。
关于
jspcap
是一个独立的开源库,仅使用jsformat
作为其格式化输出转储程序。
有一个名为jspcapy
的项目在jspcap
上工作,这是一个用于提取pcap的命令行工具。
与流行的PCAP文件提取器不同,例如scapy
、dpkt
、pyshark
等,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
实现的转储实用程序
发动机比较
此外,由于jspcap的复杂性,它的提取过程每包大约需要0.01秒,这还不够理想。因此,jspcap
引入了替代的提取引擎来加速这个过程。到目前为止,jspcap
支持scapy
,dpkt
,以及pyshark
。另外,jspcap
支持两种多处理策略(server
&;pipeline
)。有关详细信息,请参阅文档。
默认值
0.0145251388549805
服务器
0.12124489148457845
管道
0.01445042414863079
scapy
0.0024434357844035
dpkt
0.0003609057267506917
pyshark
0.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>
用法
文档
接口
<表><广告>提取
分析
跟踪
宏
格式
<表><广告>json
plist
树
pcap
层
<表><广告>raw
链接
inet
传输
应用程序
发动机
<表><广告>名称 说明
< /广告><正文>jspcap
默认引擎
mpserver
具有服务器处理策略的多处理引擎
mppipeline
采用流水线策略的多处理引擎
dpkt
引擎
引擎
pyshark
引擎
协议
<表><广告>名称 说明
< /广告><正文>raw
原始数据包数据 arp
地址解析协议
以太网DE> 以太网协议
第二层隧道协议
首先打开最短路径 rarp
反向地址解析协议
vlan
802.1q客户VLAN标记类型
ah
验证标题 主机标识协议
hopopt
IPv6逐跳选项
ip
互联网协议
ipsec
互联网协议安全性
ipv4
互联网协议版本4
ipv6
互联网协议版本6
ipv6框架
IPv6的片段头
ipv6选项
IPv6的目标选项
ipv6路由
IPv6的路由头 ipx
网络数据包交换
mh
机动性标题 tcp
传输控制协议
用户数据报协议
http
超文本传输协议
jspcap
mpserver
mppipeline
dpkt
pyshark
raw
arp
rarp
vlan
ah
hopopt
ip
ipsec
ipv4
ipv6
ipv6框架
ipv6选项
ipv6路由
ipx
mh
tcp
http
文档可以在jspcap
的子模块中找到。或者,您可以在test
文件夹中找到使用示例。有关详细信息,请参阅源代码--docstrings应该可以帮助您:)
ps:help
python中的函数应该总能帮助您解决问题。
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文件的名称(扩展名可能省略),并且至少应指明输出格式(json
、plist
或tree
)。一旦未指定格式,输出文件的名称必须具有正确的扩展名(*.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]指定
raw
packet - [X]介面动词
- [X]查看文档字符串
- [X]合并
jspcapy
- []编写文档
- []实现IP和MAC地址容器
- []实现选项列表提取器
- []实施更多协议