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 pyshark4 for protocol statistics, suspicious flow detection, DNS anomaly identification,5 and IOC extraction from PCAP files6domain: cybersecurity7subdomain: network-security8tags:9- tshark10- pyshark11- pcap12- packet-analysis13- network-forensics14- wireshark15- traffic-analysis16version: '1.0'17author: oyi7718license: Apache-2.019nist_csf:20- PR.IR-0121- DE.CM-0122- ID.AM-0323- PR.DS-0224category: cybersecurity25metadata:26 source: https://skillmd.com/skills/oyi77/performing-network-traffic-analysis-with-tshark27---282930# Performing Network Traffic Analysis with TShark3132## Overview3334This 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.353637## When to Use38**Trigger phrases:**39- "performing network traffic analysis with tshark"40- "Automate network traffic analysis using tshark and pyshark for protocol statisti"414243- When conducting security assessments that involve performing network traffic analysis with tshark44- When following incident response procedures for related security events45- When performing scheduled security testing or auditing activities46- When validating security controls through hands-on testing4748## Prerequisites4950- tshark (Wireshark CLI) installed and in PATH51- Python 3.8+ with pyshark library52- PCAP or PCAPNG capture file for analysis5354## Steps5556```python57# Example: IOC detection58import re5960IOC_PATTERNS = {61 "ip": r"\b(?:\d{1,3}\.){3}\d{1,3}\b",62 "domain": r"\b[a-z0-9-]+\.[a-z]{2,}\b",63 "hash_md5": r"\b[a-f0-9]{32}\b",64 "hash_sha256": r"\b[a-f0-9]{64}\b",65}6667def extract_iocs(text: str) -> dict:68 return {k: re.findall(v, text) for k, v in IOC_PATTERNS.items()}69```70711. **Extract Protocol Statistics** — Generate protocol hierarchy and conversation statistics from the capture722. **Identify Top Talkers** — Rank source/destination IPs by volume and connection count733. **Detect Suspicious Flows** — Flag port scanning patterns, unusual port usage, and high-frequency connections744. **Extract Network IOCs** — Pull unique IPs, domains from DNS queries, and URLs from HTTP traffic755. **Analyze DNS Traffic** — Detect DNS tunneling via high-entropy subdomain queries and excessive TXT records766. **Generate Analysis Report** — Produce structured report with flow summaries and threat indicators7778## Expected Output7980- JSON report with protocol statistics and top talkers81- Suspicious flow detections with severity ratings82- Extracted IOCs (IPs, domains, URLs)83- DNS anomaly analysis results84## When NOT to Use8586- You don't have explicit written authorization to test87- Task is about defense/detection, not offense (use detection skills)88- You need to implement security controls (use implementing-* skills)89- Task requires compliance auditing (use auditing-* skills)90- You're investigating an incident (use incident response skills)91- Target is out of scope for your engagement92- Task is about vulnerability scanning only (use scanning tools)939495## Red Flags9697- Performing actions without explicit written authorization from the asset owner98- Testing against production systems without a defined scope and rules of engagement99- Capturing traffic on networks without authorization or privacy considerations100- Leaving packet captures containing sensitive data unencrypted on disk101- Deploying inline blocking rules without testing for false positives first102103## Process1041051. **Design** — Define interface, identify patterns, plan implementation1061. **Implement** — Write code following existing conventions, add tests1071. **Verify** — Run tests, check integration, validate behavior108109## Verification110111- All steps executed successfully against a test environment before production use112- Output documented with screenshots or logs demonstrating expected behavior113- Captures verified as complete with no dropped packets114- Detection rules tested against known-benign traffic for false positive rate115- Alert thresholds validated and tuned to reduce noise116117## Anti-Rationalization Table118119| Rationalization | Reality |120|---|---|121| "We are too small to be targeted" | Automated attacks target everyone. Size does not matter. |122| "Security slows us down" | A breach slows you down 100x more. Build security in from the start. |123| "We will fix it after launch" | Vulnerabilities in production are exploited within hours. Fix before deploy. |