gitlab.com/rknall/wiresharktraining
🔍

Extending Wireshark

Scripting for Analysis and Automation

45-Minuten Hands-On Workshop

Agenda

Zeit
Thema
Aktivität
0:00-0:03
Einführung & Überblick
Vorstellung, Ziele, Werkzeuge
0:03-0:15
Lua für Wireshark-Plugins
Demo + Hands-On Übung
0:15-0:25
Python für externe Analyse
Live-Coding + Übung
0:25-0:35
tshark Automatisierung
Praktische Beispiele
0:35-0:43
Bash-Scripting Integration
Framework-Demo
0:43-0:45
Best Practices & Q&A
Zusammenfassung

Workshop-Ziele

🤖 Automatisierung

Praktische Automatisierung von wiederkehrenden Netzwerk-Analyse-Aufgaben

🔗 Integration

Nahtlose Integration verschiedener Scripting-Sprachen mit Wireshark

💻 Hands-On Erfahrung

Praktische Übungen mit realen Anwendungsfällen aus der Praxis

📊 Best Practices

Bewährte Methoden für Production-Umgebungen und große Netzwerke

Environment Check

$ wireshark --version
Wireshark 4.0.3
$ tshark --version
TShark (Wireshark) 4.0.3
$ lua -v
Lua 5.4.4
$ python3 --version
Python 3.10.6
🌙

Lua für Wireshark

Native Integration & Custom Dissectors

Warum Lua?

  • Native Integration in Wireshark
  • Kein Kompilieren notwendig
  • Zugriff auf alle Wireshark APIs
  • Hot-Reload von Plugins
  • Perfekt für Custom Protocols

HTTP Monitor Plugin

local http_monitor = Proto("HTTPMon", "HTTP Performance Monitor")

-- Felder definieren
local f_response_time = ProtoField.float("httpmon.response_time", "Response Time (ms)")
local f_status_code = ProtoField.uint16("httpmon.status", "Status Code")

function http_monitor.dissector(tvb, pinfo, tree)
    -- Response-Zeit berechnen und anzeigen
    if response_time > 1000 then
        pinfo.cols.info:append(" [SLOW!]")
    end
end

register_postdissector(http_monitor)

Hands-On: Chat Protocol

Entwickeln Sie einen Dissector für ein einfaches Chat-Protokoll

-- Protokoll-Format:
-- Bytes 0-1: Message Length (uint16)
-- Byte 2: Message Type (0x01=Text, 0x02=Status)
-- Bytes 3-n: Message Content (string)

Lösung verfügbar: samples/simple_chat.lua

🐍

Python für Analyse

PyShark, Scapy & Machine Learning

Python-Bibliotheken

Bibliothek Performance Use Case
PyShark Mittel Detailanalyse, Wireshark-Features
Scapy Gut Security Testing, Packet Crafting
dpkt Exzellent Große Dateien, Performance

Traffic Analyzer

import pyshark

class TrafficAnalyzer:
    def analyze_packet(self, packet):
        if 'IP' in packet:
            src_ip = packet.ip.src
            self.traffic_stats[src_ip]['bytes'] += int(packet.length)
            
            if 'HTTP' in packet:
                print(f"HTTP {packet.http.request_method}: {packet.http.host}")
    
    def generate_report(self):
        top_talkers = sorted(self.traffic_stats.items(), 
                           key=lambda x: x[1]['bytes'], 
                           reverse=True)[:10]

ML-basierte Anomalie-Erkennung

from sklearn.ensemble import IsolationForest

class AnomalyDetector:
    def __init__(self):
        self.model = IsolationForest(contamination=0.1)
        
    def detect_anomaly(self, packet):
        features = self.extract_features(packet)
        prediction = self.model.predict([features])
        
        if prediction[0] == -1:
            print(f"🚨 ANOMALIE: {packet.ip.src}")
📟

tshark Automatisierung

Command-Line Power

tshark Essentials

Capture-Optionen

-i eth0
-f "tcp port 80"
-c 1000
-a duration:60

Output-Optionen

-T json
-e ip.src
-E header=y
-q

Security Monitoring

# Port-Scan Erkennung
tshark -i eth0 -a duration:60 \
    -Y "tcp.flags.syn==1 && tcp.flags.ack==0" \
    -T fields -e ip.src -e tcp.dstport | \
awk '{
    src_counts[$1]++
    if (src_counts[$1] > 20) {
        print "🚨 Port-Scan von " $1
    }
}'

Performance-Analyse

# TCP-Performance-Metriken
tshark -i eth0 -a duration:300 \
    -Y "tcp.analysis.ack_rtt || tcp.analysis.retransmission" \
    -T fields \
    -e ip.src -e ip.dst \
    -e tcp.analysis.ack_rtt \
    -e tcp.analysis.retransmission \
    -E header=y -E separator='|' > tcp_performance.csv
🔨

Bash Integration

Production-Ready Frameworks

Modulares Framework

network_monitor/
├── monitor.sh          # Haupt-Framework
├── monitor.conf        # Konfiguration
├── plugins/            # Erweiterbare Plugins
│   ├── ddos_detector.sh
│   ├── anomaly_detector.sh
│   └── performance_monitor.sh
├── logs/               # Strukturierte Logs
└── data/               # Capture-Dateien

DDoS-Erkennungs-Plugin

DDOS_THRESHOLD_PPS=10000

monitor_ddos() {
    pps=$(tshark -i "$interface" -a duration:1 -q | \
          grep -oE '[0-9]+ packets' | awk '{print $1}')
    
    if [[ $pps -gt $DDOS_THRESHOLD_PPS ]]; then
        alert "DDOS" "Interface $interface: $pps packets/sec"
        activate_mitigation
    fi
}

Full Stack Integration

LuaPythontsharkBash

Alle Tools arbeiten nahtlos zusammen für maximale Effizienz

Best Practices

Aufgabe Tool Grund
Custom Protocols Lua Native Integration
Große Datenmengen Python + dpkt Beste Performance
Automatisierung tshark + Bash CLI Power

Performance-Tipps

  • BPF-Filter statt Display-Filter verwenden
  • Ring-Buffer für Langzeit-Monitoring
  • Parallele Verarbeitung mit GNU Parallel
  • JSON-Output für strukturierte Daten
  • Capture-Hardware-Offloading nutzen

Ressourcen

gitlab.com/rknall/wiresharktraining

  • Alle Code-Beispiele
  • Dokumentation
  • Übungsaufgaben
  • Best Practice Guides
🙋

Fragen?

Zeit für Diskussion

Vielen Dank!

Viel Erfolg mit Wireshark-Automatisierung

gitlab.com/rknall/wiresharktraining

1 / 25
Pfeiltasten: Navigation | F: Vollbild | ESC: Beenden