
محلل التقاط شبكة بسيط وموثوق وسريع بشكل معقول.
Sharker هو أداة قوية وقابلة للتوسع لاستخراج بيانات قيّمة من ملفات PCAP أو من الواجهات الحية. يستفيد من قوة tshark لتحليل التقاطات الشبكة بكفاءة، ويطبّق نظام تصفية مرنًا لتحديد واستخراج المعلومات الثمينة بدقة.
.pcap، أو مجلدات من التقاطات، أو حتى حركة مرور الشبكة الحية من واجهة.apt-get install tshark, brew install wireshark).requirements.txtpippipxيمكنك تثبيت 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)]
| Option | Description |
|---|---|
-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 | تفعيل جميع عوامل التصفية، سيكون أبطأ. |
| Option | Description |
|---|---|
-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 | تفعيل التسجيل المفصّل لتصحيح الأخطاء. |
1. تحليل ملف PCAP واحد وحفظ النتائج:
sharker my_capture.pcap
سيؤدي هذا إلى تشغيل جميع عوامل التصفية باستثناء تلك الموجودة في فئة heavy وحفظ المخرجات في مجلد sharker_out/. كما ستتم طباعة عوامل التصفية في فئة creds إلى stdout.
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 للحزمة لتحديد البيانات محل الاهتمام. سيستخدم Sharker هذه السمات لإخراج البيانات إذا لم تُعرّف دالة parser في عامل التصفية.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/.FilterConfigBase (المُعرّف في sharker/filters/base.py).name، description، pcap_filter، إلخ).parser() لاستخراج البيانات التي تحتاجها.
self.output مع البيانات المراد إخراجها.استوحى هذا المشروع من أعمال المشاريع مفتوحة المصدر الرائعة التالية: