Skip to content
/ ps Public

Rust - packet sniffer. A new long-term project, packet sniffing, filtering traffic, captures, real-time processing, threat detection, etc.

Notifications You must be signed in to change notification settings

Rubix982/ps

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

New Rust

Thinking

  1. Core Components
    1. Packet Capture - How will I collect network data? (e.g., use Rust crates like pnet or external tools like libpcap.)
    2. Threat Detection,
      1. Rule-based detection (e.g., suspicious IPs or patterns)?
      2. AI/ML-based anomaly detection (e.g., DDoS patterns)?
    3. Visualization/Reporting - How will you show results to users? (CLI, GUI, or dashboard?)
    4. Notification System - What kind of alerts? (e.g., emails, desktop notifications, Slack integrations.)
    5. Performance Considerations - How will you ensure it works well on both high- and low-bandwidth systems?
  2. Goals
    1. MVP - a cli tool that monitors basic packet data and flags suspicious activity
    2. Long-term Vision - a desktop/web based dashboard
    3. Ideas,
      1. Packet Capture,
        1. Protocol Decoding,
          1. Add decoding for more protocols beyond HTTP/S and DNS, such as FTP, SMTP, or SSH.
          2. Highlight suspicious payloads (e.g., encoded data in HTTP headers or commands in SSH traffic).
        2. Filter Traffic,
          1. Allow users to filter captured packets by source/destination IP, port, or protocol.
        3. Save Captures,
          1. Add functionality to save raw packet captures in .pcap format for further analysis with tools like Wireshark.
        4. Real-Time Processing,
          1. Enable streaming capture and analysis for real-time threat detection.
      2. Basic Threat Detection
        1. Enhanced Rule-Based Detection,
          1. Use community-maintained blocklists for known malicious IPs or domains (e.g., AbuseIPDB, Threat Intelligence feeds).
          2. Add rules for specific attack patterns, such as SQL injection attempts in HTTP traffic.
        2. Anomaly Detection,
          1. Incorporate simple anomaly detection based on traffic patterns, e.g.,
            1. Large bursts of traffic.
            2. Traffic to unusual ports for a given time of day.
        3. Detection Scoring,
          1. Assign a "threat score" to detected events based on severity (e.g., minor, medium, critical).
          2. Allow users to customize alert thresholds based on these scores.
        4. Pluggable Rules,
          1. Enable users to add custom detection rules via configuration files.
      3. Alerts
        1. Flexible Notification Methods,
          1. Add support for multiple alert types,
            1. Email notifications.
            2. Push notifications (via services like Pushbullet or Pushover).
            3. Integration with Slack or Discord.
        2. Customizable Alerts:
          1. Let users specify which threats trigger alerts (e.g., port scans but not DNS anomalies).
        3. Interactive Alerts:
          1. Provide suggestions for mitigation in the alert messages (e.g., "Block IP 192.168.1.100 using your firewall").
        4. Alert Aggregation:
          1. Group similar alerts to prevent spamming the user with repetitive notifications.
      4. Lightweight CLI
        1. Interactive Mode:
          • Add an interactive mode where users can run commands step-by-step, view live traffic, and inspect packet details.
        2. Profiles for Common Scenarios:
          1. Predefine CLI profiles for common use cases:
          2. Example: threat-monitor --profile "home-wifi" for home network threats.
        3. Command Autocompletion:
          1. Implement shell autocompletion for commands and flags to enhance usability.
        4. CLI with Colorized Output:
          1. Highlight critical alerts or unusual traffic in color-coded text for better readability.
      5. Simple Reporting
        1. Detailed Report Formats:
          1. Offer multiple formats for reports:
          2. Text files for terminal output.
          3. JSON for machine-readability and integration with external tools.
          4. HTML for visually appealing, shareable reports.
        2. Aggregated Statistics:
          1. Include summary statistics in the report:
            1. Total packets analyzed.
            2. Number of threats detected by category.
            3. Geographic information for source IPs (using GeoIP databases).
        3. Periodic Reports:
          1. Schedule automatic generation of reports (e.g., daily or weekly).
          2. Example: threat-monitor --report --frequency daily
        4. Threat Visualizations:
          1. Incorporate basic visualizations using ASCII graphs in the CLI or export options for external tools (e.g., CSV/JSON for dashboards).
      6. Conversational AI,
        1. Can we integarte a sample AI chatbot that answers based on what data it has access to or can see?

Priorities

Packet Capture

The first priority is the "Packet Capture" goal. We want to figure out a CLI mechanism that allows us to explore the nature of capturing packets via a cli and via many available configurations and options.

For a CLI tool focusing on packet capture and configuration options, it's essential to offer a feature set that is flexible, interactive, and easy to use while catering to different user needs. Here’s a breakdown of options and features you can implement for your CLI:

Interface Selection

  • Option: --interface <name>
  • Description: Allow users to specify which network interface to capture packets from.
  • Interactive Mode: List available interfaces and let the user select one.

Protocol Filtering

  • Option: --protocol <TCP|UDP|ICMP|ALL>
  • Description: Enable filtering by specific protocols (e.g., capture only TCP, UDP, or ICMP packets).
  • Interactive Mode: Use a menu to select the desired protocol(s).

Port Filtering

  • Option: --port <port_number>
  • Description: Capture packets targeting specific ports.
  • Interactive Mode: Prompt the user to enter one or more port numbers.

IP Filtering

  • Option: --source-ip or --destination-ip
  • Description: Filter packets based on source or destination IP addresses.
  • Interactive Mode: Let users input IP addresses interactively or choose from a pre-defined list.

Packet Limit

  • Option: --limit
  • Description: Specify the maximum number of packets to capture.
  • Interactive Mode: Prompt the user for the number of packets.

Capture Duration

  • Option: --duration
  • Description: Set a time limit for the capture session.
  • Interactive Mode: Ask the user for a capture duration.

Save Captures

  • Option: --output <file.pcap>
  • Description: Save captured packets to a .pcap file for further analysis.
  • Interactive Mode: Prompt for a filename and format.

Packet Display Options

  • Option: --verbose, --summary
  • Description: Toggle between detailed packet information or just a summary (e.g., source/destination, protocol, and port).
  • Interactive Mode: Ask the user which display mode they prefer.

Real-Time Analysis

  • Option: --realtime
  • Description: Display packets in real-time as they are captured.
  • Interactive Mode: Confirm whether the user wants real-time output.

Capture Filters

  • Option: --filter ""
  • Description: Advanced users can specify Berkeley Packet Filter (BPF) syntax for complex filtering.
  • Interactive Mode: Provide examples of BPF filters or allow users to input custom filters.

Threat Detection

  • Option: --detect
  • Description: Load a rule file for detecting suspicious patterns (e.g., known malicious IPs).
  • Interactive Mode: Offer a selection of pre-defined rule files or upload custom ones.

Packet Size Filtering

  • Option: --min-size and --max-size
  • Description: Capture packets within a specific size range.
  • Interactive Mode: Let users specify minimum and maximum packet sizes interactively.

Log Levels

  • Option: --log (e.g., info, warn, error)
  • Description: Set the verbosity level for logs.
  • Interactive Mode: Provide a menu for selecting log levels.

Notification and Alerts

  • Option: --alert
  • Description: Send alerts for flagged packets via email, Slack, or desktop notifications.
  • Interactive Mode: Allow users to configure alert methods interactively.

Summary Report

  • Option: --summary-report
  • Description: Generate a summary report after the capture session.
  • Interactive Mode: Prompt for a filename and preferred format (e.g., txt, json, html).

Interactive Help

  • Option: --interactive-help
  • Description: Offer detailed explanations of each option interactively.
  • Interactive Mode: Provide step-by-step guidance for each feature.

Example Interactive Workflow

  1. Interface Selection
    • CLI: --interface eth0
    • Interactive: List all available interfaces and select one.
  2. Protocol Filtering
    • CLI: --protocol TCP
    • Interactive: "Which protocol do you want to monitor?" (User selects TCP).
  3. Port Filtering
    • CLI: --port 80
    • Interactive: "Enter a port to monitor: (default: ALL)"
  4. Save to File
    • CLI: --output capture.pcap
    • Interactive: "Save captured packets? (y/n)" → Prompt for filename.
  5. Real-Time View
    • CLI: --realtime
    • Interactive: "Display packets in real-time? (y/n)"

Advanced Filtering Features

  1. Protocol Stacking Analysis
    • Description: Analyze multiple protocol layers in a single packet (e.g., TCP over IPv4 over Ethernet).
    • Use Case: Helps hobbyists explore how different protocol layers interact.
  2. Custom Filters
    • Feature: Support logical operators in filters (e.g., --filter "src_ip=192.168.1.1 AND protocol=TCP").
    • Interactive Mode: Let users build filters with an intuitive interface.
  3. Regex Matching
    • Feature: Use regex for payload filtering (e.g., detect specific text patterns in HTTP headers or payloads).
    • Use Case: Identify HTTP headers with suspicious commands or strings.

Enhanced Packet Analysis

  1. Payload Decoding Feature: Decode payloads for supported protocols (e.g., HTTP, DNS, FTP). Use Case: Show the content of HTTP headers, DNS queries/responses, or FTP commands.
  2. Traffic Flow Analysis Feature: Reconstruct TCP streams to visualize full client-server interactions. Use Case: Reassemble HTTP requests and responses or SSH sessions.
  3. Packet Timing Analysis Feature: Measure inter-packet arrival times to detect anomalies like latency spikes. Use Case: Identify patterns indicative of DoS or connection issues.
  4. Entropy Analysis Feature: Calculate entropy of packet payloads to detect potential encrypted or obfuscated data. Use Case: Highlight unusual traffic like data exfiltration attempts.

Reporting and Summarization

  1. Protocol Usage Stats
    • Feature: Summarize protocol usage (e.g., percentage of TCP, UDP, ICMP).
    • Use Case: Provide a quick overview of traffic distribution.
  2. Source/Destination Stats
    • Feature: List the most frequent source and destination IPs or ports.
    • Use Case: Identify top talkers in the network.
  3. Topology Map
    • Feature: Visualize communication flows between IPs in a CLI-based ASCII art or generate a graph file (e.g., Graphviz DOT format).
    • Use Case: Understand network communication patterns.
  4. Session Export
    • Feature: Export session data (e.g., all packets belonging to a single TCP connection).
    • Use Case: Isolate and analyze individual conversations.

Real-Time Enhancements

  1. Anomaly Detection
    • Feature: Flag packets with unusual behavior (e.g., high TTL values, malformed headers).
    • Use Case: Detect potential malicious activity or configuration issues.
  2. Rate Limiting
    • Feature: Limit the number of packets displayed per second in real-time mode.
    • Use Case: Prevent flooding the CLI output on busy networks.
  3. Color-Coded Output
    • Feature: Use colors to categorize packets (e.g., red for suspicious, green for normal).
    • Use Case: Quickly identify packet types or anomalies.

Deep Protocol Inspection

  1. DNS Analysis
    • Feature: Decode DNS queries and responses, highlighting suspicious domains.
    • Use Case: Help hobbyists track down malicious or misconfigured DNS activity.
  2. HTTP Inspection
    • Feature: Extract and display HTTP methods, URLs, and headers.
    • Use Case: Inspect web traffic and spot anomalies.
  3. TLS/SSL Analysis
    • Feature: Extract and display TLS handshake details (e.g., certificates, cipher suites).
    • Use Case: Ensure secure communication and detect improper configurations.

Utility Features

  1. Packet Size Distribution
    • Feature: Display a histogram of packet sizes.
    • Use Case: Spot traffic patterns, like large file transfers or attacks with tiny packets.
  2. Time-Based Filtering
    • Feature: Capture packets only within a specific time window.
    • Use Case: Analyze traffic for a particular event or interval.
  3. Geolocation
    • Feature: Map IP addresses to geographical locations using GeoIP databases.
    • Use Case: Understand the global distribution of traffic.

Integration and Extensibility

  1. Scriptable Output
    • Feature: Export results in JSON or CSV for integration with other tools.
    • Use Case: Analyze data further with Python or other scripts.
  2. Webhook Integration
    • Feature: Send packet summaries or alerts to a webhook.
    • Use Case: Notify hobbyists when suspicious traffic is detected.
  3. Plugin Support
    • Feature: Allow users to write custom packet handlers in Rust or other languages.
    • Use Case: Extend functionality without modifying the core code.

Educational Features

  1. Packet Replay
    • Feature: Save captured packets and replay them in a virtual network.
    • Use Case: Help hobbyists practice analyzing specific traffic patterns.
  2. Protocol Learning Mode
    • Feature: Annotate packets with educational notes (e.g., explain headers and flags).
    • Use Case: Teach beginners how network protocols work.
  3. Simulation Mode
    • Feature: Generate synthetic traffic for testing and learning.
    • Use Case: Simulate attacks or specific network behaviors.

Security-Oriented Features

  1. Signature-Based Detection
    • Feature: Match packets against known malicious signatures (e.g., Snort rules).
    • Use Case: Highlight traffic matching malware or attack signatures.
  2. DDoS Pattern Detection
    • Feature: Identify patterns indicative of DDoS attacks (e.g., SYN flood, UDP flood).
    • Use Case: Alert hobbyists to potential attack scenarios.
  3. Malware Sandbox Integration
    • Feature: Allow users to export payloads for analysis in malware sandboxes.
    • Use Case: Investigate suspicious traffic further.

Performance Tuning

  1. Low-Bandwidth Mode
    • Feature: Optimize for low-power devices by reducing processing overhead.
    • Use Case: Run efficiently on Raspberry Pi or similar hardware.
  2. Asynchronous Processing
    • Feature: Process packets asynchronously to maximize performance.
    • Use Case: Improve capture rates on busy networks.

About

Rust - packet sniffer. A new long-term project, packet sniffing, filtering traffic, captures, real-time processing, threat detection, etc.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published