Sharker 是一个功能强大且可扩展的工具,用于从 PCAP 文件或实时接口中提取有价值的数据。它利用 tshark 的强大功能来高效解析网络捕获,并应用灵活的过滤系统来精准定位和提取关键信息。
.pcap 文件、包含捕获文件的目录,甚至来自网络接口的实时流量。apt-get install tshark、brew install wireshark)。requirements.txt 中,可以通过 pip/pipx 安装。你可以使用 pipx(推荐)或标准的 pip 和 venv 环境来安装 Sharker。
pipx(推荐)# Install from this repository
pipx install git+https://github.com/synacktiv/sharker.git
# Verify the installation
sharker -h
pip 和 venv# Clone the repository
git clone https://github.com/synacktiv/sharker.git
cd sharker
# Create and activate a virtual environment
python3 -m venv venv
source venv/bin/activate
# Install Sharker
pip install .
# Verify the installation
sharker -h
Sharker 的基本语法为:
sharker [OPTIONS] [PCAP_FILE(s)]
1. 分析单个 PCAP 并保存结果:
sharker my_capture.pcap
这将运行除 heavy 类别之外的所有过滤器,并将输出保存到 sharker_out/ 目录中。creds 类别中的过滤器也会打印到标准输出。
2. 应用所有过滤器并尽可能快地运行:
sharker -A -F my_captures.pcap
这将应用所有过滤器并将所有内容输出到文件,不会有结果打印到控制台。
3. 分析目录中的 PCAP,重点关注凭据:
sharker -d /path/to/pcaps -c creds
该命令处理指定目录中的所有 PCAP 文件,但仅运行 creds 类别中的过滤器。
4. 捕获实时流量并将 HTTP 相关信息打印到控制台:
sudo sharker -i eth0 -c http -m console
这将从 eth0 接口捕获流量,仅运行 http 类别过滤器,并将所有结果直接打印到终端。
5. 列出所有可用过滤器:
sharker -L
$ sharker -h
Usage: sharker [OPTIONS] [PCAP[ PCAP[ ...]]
Sharker: A reasonably fast network protocol analysis tool with extensible
filters.
Options:
Input Source:
-d, --pcap-dir DIR Path to a directory containing PCAP files to
parse.
-i, --interface IFACE Network interface to capture live data from
(e.g., eth0, wlan0).
Output Handling: By default, everything is written to file,
and only creds category is printed to
console. For very large PCAPs, advised to
disable console output or at least colors,
since it slows down the parsing.
-m, --output-mode [file|console|both|develop]
Which output mode to enable. [default:
both]
-u, --unique Output only unique results, will gradually
take more and more RAM.
-F, --fast Fastest configuration (do not affect filter
selection).
Output file mode:
-o, --output-dir DIR Output directory.
-op, --output-prefix NAME Prefix to use for the output files, defaults
to the PCAP/interface name.
Output console mode:
-P Send all filters to console (default in
console output mode).
-C Do not use colors in console output, will
speed up sharker when lot of stuff is
printed.
-pf FILT[,FILT[...]] Send specific filters output to console.
-xpf FILT[,FILT[...]] Do not send specific filters to console.
-pc CAT[,CAT[...]] Send specific filter categories to console.
-xpc CAT[,CAT[...]] Do not send specific categories to console.
-nwf FILT[,FILT[...]] Do not write filters output to file.
-nwc CAT[,CAT[...]] Do not write filter categories to file.
Filter Selection:
-A, --all Enable all filters, will be slower.
-f, --filters FILT[,FILT[...]]
Only run specified filters.
-nf, --not-filters FILT[,FILT[...]]
Exclude specified filters.
-c, --categories CAT[,CAT[...]]
Only run specified categories of filters.
-nc, --not-categories CAT[,CAT[...]]
Exclude specified categories of filters.
Filter Information:
-l, --list-filters List filters that would be active with
current filtering options.
-L, --list-all-filters List all available filters.
-Lc, --list-all-filter-categories
List all available filter categories.
Debugging:
-v, --verbose Verbose mode.
-h, --help Show this message and exit.
Sharker 的强大之处在于其过滤器,它们位于 sharker/filters/ 目录中。每个过滤器都是一个 Python 类,定义了:
name:过滤器的唯一名称。description:对过滤器功能的简要说明。pcap_filter:一个 tshark 显示过滤器,用于为该过滤器选择相关的数据包。categories:该过滤器所属类别的列表(例如,creds、dns、http)。对于会匹配大量数据包或执行缓慢操作的过滤器,可以使用 heavy。mandatory_selectors 和 optional_selectors:在数据包的 JSON 表示中查找的键,以识别感兴趣的数据。如果过滤器中未定义 parser 函数,Sharker 将使用这些属性来输出数据。parser():处理数据包数据并返回提取信息的函数。默认情况下,Sharker 会运行除 heavy 类别之外的所有过滤器。你可以通过 -c、-nc、-f 和 -nf 选项自定义此行为。
from .base import FilterConfigBase
class FilterConfig(FilterConfigBase):
name = 'ntlmssp'
description = 'Extract Net-NTLM hashes for cracking purposes'
categories = [
'creds',
'windows'
]
pcap_filter = 'gss-api || ntlmssp'
mandatory_selectors = [
'ntlmssp'
]
def __init__(self, *args, **kwargs):
self.challenges = {}
super().__init__(*args, **kwargs)
def parser(self, data):
tcp_conn = data['tcp.stream'][0]
msg_type = int(data['ntlmssp.messagetype'][0], 16) if 'ntlmssp.messagetype' in data else 0
if msg_type == 1:
# NTLM NEGOTIATE: nothing to do
pass
elif msg_type == 2:
# NTLM CHALLENGE
self.challenges[tcp_conn] = data['ntlmssp.ntlmserverchallenge'][0].replace(':', '')
elif msg_type == 3:
if tcp_conn not in self.challenges:
self.log.error('Found an NTLM message type 3 (AUTH), but no type 2 (CHALLENGE) was received beforehand -> check in pcap if the challenge was not sent in an unsupported by tshark manner from the server, like in a Proxy-Authenticate HTTP header.')
return 0
ntresp = data['ntlmssp.auth.ntresponse'][0].replace(':', '')
lmresp = data['ntlmssp.auth.lmresponse'][0].replace(':', '')
user = data['ntlmssp.auth.username'][0]
domain = data['ntlmssp.auth.domain'][0]
workstation = data['ntlmssp.auth.hostname'][0]
ntlm_hash = ''
if len(ntresp) == 24 * 2:
# NTLMv1 response
if domain != '':
ntlm_hash = f'{user}::{domain}:{lmresp}:{ntresp}:{self.challenges[tcp_conn]}'
else:
ntlm_hash = f'{user}::{workstation}:{lmresp}:{ntresp}:{self.challenges[tcp_conn]}'
else:
# NTLMv2 response
if domain != '':
ntlm_hash = f'{user}::{domain}:{self.challenges[tcp_conn]}:{ntresp[:32]}:{ntresp[32:]}'
else:
ntlm_hash = f'{user}::{workstation}:{self.challenges[tcp_conn]}:{ntresp[:32]}:{ntresp[32:]}'
del self.challenges[tcp_conn]
self.output(ntlm_hash)
return 1
return 0
如果你想为 Sharker 做贡献或开发自己的过滤器,可以设置一个开发环境。
# Clone the repository
git clone https://github.com/synacktiv/sharker.git
cd sharker
# Create and activate a virtual environment
python3 -m venv venv
source venv/bin/activate
# Install in editable mode
pip install -e .
# Now you can run sharker and your changes will be reflected immediately
sharker -h
sharker/filters/ 目录中创建一个新的 Python 文件。FilterConfigBase(在 sharker/filters/base.py 中定义)的类。name、description、pcap_filter 等)。parser() 方法以提取所需数据。
self.output 方法来输出数据。该项目的灵感来自以下非常优秀的开源项目:
| 选项 | 描述 |
|---|
-i, --interface <IFACE> | 从网络接口捕获实时流量(例如,eth0)。 |
-d, --pcap-dir <DIR> | 分析目录中的所有 PCAP 文件。 |
-o, --output-dir <DIR> | 指定输出文件的目录(默认:./sharker_out)。 |
-m, --output-mode <MODE> | 设置输出模式:file、console、both 或 develop(默认:both)。 |
-u, --unique | 仅输出唯一结果。 |
-F, --fast | 最快配置(不影响过滤器选择)。 |
-A, --all | 启用所有过滤器,速度会变慢。 |
| 选项 | 描述 |
|---|
-c, --categories <CATS> | 要运行的过滤器类别列表,以逗号分隔(例如,creds,http)。 |
-nc, --not-categories <CATS> | 要排除的过滤器类别列表,以逗号分隔(例如,heavy)。默认情况下,会排除 heavy。 |
-f, --filters <FILTERS> | 要运行的特定过滤器列表,以逗号分隔。 |
-nf, --not-filters <FILTERS> | 要排除的特定过滤器列表,以逗号分隔。 |
-L, --list-all-filters | 显示所有可用过滤器及其描述的列表。 |
-Lc, --list-all-filter-categories | 显示所有可用过滤器类别的列表。 |
-l, --list-filters | 显示在当前命令行选项下将启用的过滤器。 |
-v, --verbose | 启用详细日志以进行调试。 |