Performing Network Traffic Analysis with TShark
Overview
This skill automates packet capture analysis using tshark (Wireshark CLI) and pyshark (Python wrapper). It extracts protocol distribution statistics, identifies suspicious network flows (port scans, beaconing, data exfiltration), extracts IOCs (IPs, domains, URLs), and detects DNS tunneling patterns from PCAP files.
When to Use
Trigger phrases:
"performing network traffic analysis with tshark"
"Automate network traffic analysis using tshark and pyshark for protocol statisti"
When conducting security assessments that involve performing network traffic analysis with tshark
When following incident response procedures for related security events
When performing scheduled security testing or auditing activities
When validating security controls through hands-on testing
Prerequisites
- tshark (Wireshark CLI) installed and in PATH
- Python 3.8+ with pyshark library
- PCAP or PCAPNG capture file for analysis
Steps
# Example: IOC detection
import re
IOC_PATTERNS = {
"ip": r"\b(?:\d{1,3}\.){3}\d{1,3}\b",
"domain": r"\b[a-z0-9-]+\.[a-z]{2,}\b",
"hash_md5": r"\b[a-f0-9]{32}\b",
"hash_sha256": r"\b[a-f0-9]{64}\b",
}
def extract_iocs(text: str) -> dict:
return {k: re.findall(v, text) for k, v in IOC_PATTERNS.items()}
- Extract Protocol Statistics — Generate protocol hierarchy and conversation statistics from the capture
- Identify Top Talkers — Rank source/destination IPs by volume and connection count
- Detect Suspicious Flows — Flag port scanning patterns, unusual port usage, and high-frequency connections
- Extract Network IOCs — Pull unique IPs, domains from DNS queries, and URLs from HTTP traffic
- Analyze DNS Traffic — Detect DNS tunneling via high-entropy subdomain queries and excessive TXT records
- Generate Analysis Report — Produce structured report with flow summaries and threat indicators
Expected Output
- JSON report with protocol statistics and top talkers
- Suspicious flow detections with severity ratings
- Extracted IOCs (IPs, domains, URLs)
- DNS anomaly analysis results
When NOT to Use
- You don't have explicit written authorization to test
- Task is about defense/detection, not offense (use detection skills)
- You need to implement security controls (use implementing-* skills)
- Task requires compliance auditing (use auditing-* skills)
- You're investigating an incident (use incident response skills)
- Target is out of scope for your engagement
- Task is about vulnerability scanning only (use scanning tools)
Red Flags
- Performing actions without explicit written authorization from the asset owner
- Testing against production systems without a defined scope and rules of engagement
- Capturing traffic on networks without authorization or privacy considerations
- Leaving packet captures containing sensitive data unencrypted on disk
- Deploying inline blocking rules without testing for false positives first
Process
- Design — Define interface, identify patterns, plan implementation
- Implement — Write code following existing conventions, add tests
- Verify — Run tests, check integration, validate behavior
Verification
- All steps executed successfully against a test environment before production use
- Output documented with screenshots or logs demonstrating expected behavior
- Captures verified as complete with no dropped packets
- Detection rules tested against known-benign traffic for false positive rate
- Alert thresholds validated and tuned to reduce noise
Anti-Rationalization Table
| Rationalization |
Reality |
| "We are too small to be targeted" |
Automated attacks target everyone. Size does not matter. |
| "Security slows us down" |
A breach slows you down 100x more. Build security in from the start. |
| "We will fix it after launch" |
Vulnerabilities in production are exploited within hours. Fix before deploy. |
1---2name: performing-network-traffic-analysis-with-tshark3description: Use when automating network traffic analysis using tshark and pyshark for protocol statistics, suspicious flow detection, DNS anomaly identification, and IOC extraction from PCAP files4license: Apache-2.05---678# Performing Network Traffic Analysis with TShark910## Overview1112This skill automates packet capture analysis using tshark (Wireshark CLI) and pyshark (Python wrapper). It extracts protocol distribution statistics, identifies suspicious network flows (port scans, beaconing, data exfiltration), extracts IOCs (IPs, domains, URLs), and detects DNS tunneling patterns from PCAP files.131415## When to Use16**Trigger phrases:**17- "performing network traffic analysis with tshark"18- "Automate network traffic analysis using tshark and pyshark for protocol statisti"192021- When conducting security assessments that involve performing network traffic analysis with tshark22- When following incident response procedures for related security events23- When performing scheduled security testing or auditing activities24- When validating security controls through hands-on testing2526## Prerequisites2728- tshark (Wireshark CLI) installed and in PATH29- Python 3.8+ with pyshark library30- PCAP or PCAPNG capture file for analysis3132## Steps3334```python35# Example: IOC detection36import re3738IOC_PATTERNS = {39 "ip": r"\b(?:\d{1,3}\.){3}\d{1,3}\b",40 "domain": r"\b[a-z0-9-]+\.[a-z]{2,}\b",41 "hash_md5": r"\b[a-f0-9]{32}\b",42 "hash_sha256": r"\b[a-f0-9]{64}\b",43}4445def extract_iocs(text: str) -> dict:46 return {k: re.findall(v, text) for k, v in IOC_PATTERNS.items()}47```48491. **Extract Protocol Statistics** — Generate protocol hierarchy and conversation statistics from the capture502. **Identify Top Talkers** — Rank source/destination IPs by volume and connection count513. **Detect Suspicious Flows** — Flag port scanning patterns, unusual port usage, and high-frequency connections524. **Extract Network IOCs** — Pull unique IPs, domains from DNS queries, and URLs from HTTP traffic535. **Analyze DNS Traffic** — Detect DNS tunneling via high-entropy subdomain queries and excessive TXT records546. **Generate Analysis Report** — Produce structured report with flow summaries and threat indicators5556## Expected Output5758- JSON report with protocol statistics and top talkers59- Suspicious flow detections with severity ratings60- Extracted IOCs (IPs, domains, URLs)61- DNS anomaly analysis results62## When NOT to Use6364- You don't have explicit written authorization to test65- Task is about defense/detection, not offense (use detection skills)66- You need to implement security controls (use implementing-* skills)67- Task requires compliance auditing (use auditing-* skills)68- You're investigating an incident (use incident response skills)69- Target is out of scope for your engagement70- Task is about vulnerability scanning only (use scanning tools)717273## Red Flags7475- Performing actions without explicit written authorization from the asset owner76- Testing against production systems without a defined scope and rules of engagement77- Capturing traffic on networks without authorization or privacy considerations78- Leaving packet captures containing sensitive data unencrypted on disk79- Deploying inline blocking rules without testing for false positives first8081## Process82831. **Design** — Define interface, identify patterns, plan implementation841. **Implement** — Write code following existing conventions, add tests851. **Verify** — Run tests, check integration, validate behavior8687## Verification8889- All steps executed successfully against a test environment before production use90- Output documented with screenshots or logs demonstrating expected behavior91- Captures verified as complete with no dropped packets92- Detection rules tested against known-benign traffic for false positive rate93- Alert thresholds validated and tuned to reduce noise9495## Anti-Rationalization Table9697| Rationalization | Reality |98|---|---|99| "We are too small to be targeted" | Automated attacks target everyone. Size does not matter. |100| "Security slows us down" | A breach slows you down 100x more. Build security in from the start. |101| "We will fix it after launch" | Vulnerabilities in production are exploited within hours. Fix before deploy. |