
シンプルで信頼性が高く、比較的高速なネットワークキャプチャ解析ツール。
Sharkerは、PCAPファイルやライブインターフェースから価値あるデータを抽出するための、強力で拡張可能なツールです。tshark のパワーを活用してネットワークキャプチャを効率的に解析し、柔軟なフィルタリングシステムを適用して、有益な情報を正確に特定・抽出します。
.pcap ファイル、キャプチャのディレクトリ、さらにはインターフェースからのライブネットワークトラフィックを解析できます。apt-get install tshark、brew install wireshark)。requirements.txt にリストされており、pip/pipx でインストールできます。Sharker は、pipx(推奨)または標準の pip と venv 環境を使用してインストールできます。
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 | デバッグ用の詳細ログを有効にします。 |