Skip to content

Myth7x/ts-packet-interceptor

Repository files navigation

TypeScript/Node.js Packet Interceptor

CI

A powerful packet interceptor that captures network packets, holds them in a queue (chokes them), and releases them when the Left Alt key is pressed.

Features

  • 🔒 Packet Choking: Automatically queues incoming network packets
  • 🔓 Manual Release: Press and hold Left Alt to release all queued packets
  • 📊 Real-time Stats: Monitor queue size and packet flow status
  • 🎯 Protocol Support: Supports ICMP, TCP, and UDP protocols
  • 💻 Cross-platform: Works on Windows, Linux, and macOS

Prerequisites

  • Node.js 14+ and npm
  • Administrator/Root privileges (required for raw socket access)
    • Windows: Run PowerShell/CMD as Administrator
    • Linux/Mac: Use sudo

Installation

npm install

Usage

Windows (Run as Administrator)

npm run dev

Linux/Mac (Run with sudo)

sudo npm run dev

How It Works

  1. Packet Capture: The application creates a raw socket to capture network packets (default: ICMP/ping packets)
  2. Packet Queuing: All captured packets are queued instead of being forwarded
  3. Manual Release:
    • Press and hold Left Alt to release all queued packets
    • Release Left Alt to start choking packets again
  4. Real-time Monitoring: View packet statistics every 5 seconds

Testing

To generate network traffic and test the interceptor:

  1. Start the packet interceptor (as administrator/root)
  2. In another terminal, run: ping 8.8.8.8
  3. Watch as packets are queued
  4. Press Left Alt to release them

Project Structure

ts-packet-interceptor/
├── src/
│   ├── index.ts              # Main application entry point
│   ├── PacketInterceptor.ts  # Packet capture and queue management
│   ├── KeyboardListener.ts   # Global keyboard event listener
│   └── types/
│       └── raw-socket.d.ts   # TypeScript definitions for raw-socket
├── tsconfig.json             # TypeScript configuration
├── package.json              # Project dependencies and scripts
└── README.md                 # This file

Scripts

  • npm run build - Compile TypeScript to JavaScript
  • npm run start - Build and run the compiled application
  • npm run dev - Run the application directly with ts-node
  • npm run clean - Remove the dist folder

Technical Details

Packet Interceptor

  • Uses raw sockets to capture network packets at the IP layer
  • Maintains a queue with a maximum size of 10,000 packets
  • Tracks packet metadata (source address, timestamp, length)

Keyboard Listener

  • Uses node-global-key-listener for system-wide key detection
  • Specifically monitors Left Alt key press/release events
  • Works even when the terminal is not in focus

Troubleshooting

"Failed to create raw socket"

  • Make sure you're running with administrator/root privileges
  • Windows: Right-click PowerShell → "Run as Administrator"
  • Linux/Mac: Use sudo npm run dev

No packets being captured

  • Try generating network traffic: ping 8.8.8.8
  • Check your firewall settings
  • Ensure the network interface is active

Left Alt key not detected

  • The keyboard listener should work system-wide
  • Try pressing and holding Left Alt for 1-2 seconds
  • Check console output for debug messages

Security Notice

This application requires elevated privileges to access raw sockets. Use with caution and only in controlled environments.

License

ISC

Contributing

Feel free to submit issues and pull requests!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published