
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
tcp-builder
Advanced tools
Multi-protocol packet builder for network analysis, OS detection, and security research
A comprehensive Node.js library for building and parsing custom TCP packets with advanced options support. Designed for network security research, OS fingerprinting, and protocol analysis.
npm install tcp-builder
Or clone this repository:
git clone https://github.com/Jram2001/tcp-builder.git
cd tcp-builder
const TCP = require('tcp-builder');
// Create a basic SYN packet
const synPacket = TCP.Encode(
'192.168.1.10', // Source IP
'192.168.1.20', // Destination IP
40000, // Source Port
80, // Destination Port
123456, // Sequence Number
0, // Acknowledgment Number
{ syn: true }, // Flags
65535, // Window Size
0, // Urgent Pointer
Buffer.alloc(0), // Options
Buffer.alloc(0) // Data
);
console.log('Packet hex:', synPacket.toString('hex'));
// Decode the packet
const decoded = TCP.Decode(synPacket);
console.log('Decoded:', decoded);
Builds a complete TCP packet with proper header structure and checksum.
Parameters:
srcIp (string): Source IP address for checksum calculationdestIp (string): Destination IP address for checksum calculationsrcPort (number): Source port number (0-65535)destPort (number): Destination port number (0-65535)seqNumber (number): Sequence number (32-bit, default: 0)ackNumber (number): Acknowledgment number (32-bit, default: 0)flags (object): TCP flags object with boolean properties:
fin: Connection terminationsyn: Synchronize sequence numbersrst: Reset connectionpsh: Push data to applicationack: Acknowledgment field validurg: Urgent pointer validece: ECN Echocwr: Congestion Window ReducedwindowSize (number): Receive window size (16-bit, default: 65535)urgentPointer (number): Urgent pointer (16-bit, default: 0)options (Buffer): TCP options (variable length)data (Buffer): Payload dataReturns: Buffer containing the complete TCP packet
Parses a TCP packet and extracts all header fields.
Parameters:
packet (Buffer): TCP packet buffer to decodeskipIPHeader (boolean): If true, skips first 20 bytes (IP header)Returns: Object containing:
sourcePort: Source port numberdestinationPort: Destination port numbersequenceNumber: Sequence numberacknowledgmentNumber: Acknowledgment numberdataOffset: Header length in 32-bit wordsflags: Array of active flag nameswindowSize: Window size valuechecksum: Checksum valueurgentPointer: Urgent pointer valueoptions: Array of parsed option objectsdataPayload: Data payload bufferconst { OptionBuilders } = require('tcp-builder');
// Maximum Segment Size
const mssOption = OptionBuilders.optMSS(1460);
// Window Scale
const windowScale = OptionBuilders.optWScale(7);
// SACK Permitted
const sackPermitted = OptionBuilders.optSACK();
// Timestamps
const timestamp = OptionBuilders.optTimestamp(0xFFFFFFFF, 0);
// No Operation (padding)
const nop = OptionBuilders.optNOP();
// End of Options List
const eol = OptionBuilders.optEOL();
// Combine options with proper padding
const options = OptionBuilders.optPadding(
Buffer.concat([mssOption, windowScale, sackPermitted, timestamp])
);
| Option | Kind | Description | RFC |
|---|---|---|---|
| EOL | 0 | End of Option List | 793 |
| NOP | 1 | No Operation (padding) | 793 |
| MSS | 2 | Maximum Segment Size | 793 |
| WScale | 3 | Window Scale | 7323 |
| SACK | 4 | SACK Permitted | 2018 |
| Timestamps | 8 | Timestamp Option | 7323 |
The library includes pre-configured probe options for OS detection:
const { Probes } = require('tcp-builder');
// Nmap-style probes
const t1Packet = TCP.Encode(
'192.168.1.10', '192.168.1.20', 40000, 80,
123456, 0, { syn: true }, 65535, 0,
Probes.T1options, // Pre-built T1 probe options
Buffer.alloc(0)
);
// Available probe types:
// T1options - T7options: Standard Nmap TCP probes
// ECNoptions: ECN probe configuration
// MSSonly, WSCALEonly, SACKonly: Single option probes
// LINUXprobe, WINDOWSprobe, BSDprobe: OS-specific probes
const { OptionBuilders } = require('tcp-builder');
// Build custom options
const options = OptionBuilders.optPadding(Buffer.concat([
OptionBuilders.optMSS(1460),
OptionBuilders.optWScale(7),
OptionBuilders.optSACK(),
OptionBuilders.optTimestamp()
]));
const packet = TCP.Encode(
'10.0.0.1', '10.0.0.2', 12345, 443,
1000000, 0, { syn: true }, 29200, 0,
options, Buffer.alloc(0)
);
const data = Buffer.from('GET / HTTP/1.1\r\nHost: example.com\r\n\r\n');
const packet = TCP.Encode(
'192.168.1.100', '93.184.216.34', 54321, 80,
2000000, 1000000, { psh: true, ack: true }, 65535, 0,
Buffer.alloc(0), data
);
// Assuming you have a raw TCP packet buffer
const rawPacket = Buffer.from('504f...', 'hex');
const parsed = TCP.Decode(rawPacket);
console.log('Source Port:', parsed.sourcePort);
console.log('Flags:', parsed.flags);
console.log('Options:', parsed.options);
The library automatically calculates proper TCP checksums using the pseudo-header approach:
const { TCPChecksum } = require('tcp-builder');
// Manual checksum calculation (usually not needed)
const checksum = TCPChecksum('192.168.1.1', '192.168.1.2', tcpSegmentBuffer);
node test.js
Example test output:
Decoded fields: {
sourcePort: 40000,
destinationPort: 80,
sequenceNumber: 123456,
acknowledgmentNumber: 0,
dataOffset: 5,
flags: [ 'SYN' ],
windowSize: 65535,
checksum: 44449,
urgentPointer: 0,
options: [],
dataPayload: <Buffer >
}
MIT License - see LICENSE file for details.
This library has zero external dependencies and uses only Node.js built-in modules.
FAQs
Multi-protocol packet builder for network analysis, OS detection, and security research
We found that tcp-builder demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.