• Stars
    star
    400
  • Rank 107,843 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 10 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

SOCKS protocol version 5 server and client implementations for node.js

Description

SOCKS protocol version 5 server and client implementations for node.js

Requirements

Install

npm install socksv5

Examples

  • Server with no authentication and allowing all connections:
var socks = require('socksv5');

var srv = socks.createServer(function(info, accept, deny) {
  accept();
});
srv.listen(1080, 'localhost', function() {
  console.log('SOCKS server listening on port 1080');
});

srv.useAuth(socks.auth.None());
  • Server with username/password authentication and allowing all (authenticated) connections:
var socks = require('socksv5');

var srv = socks.createServer(function(info, accept, deny) {
  accept();
});
srv.listen(1080, 'localhost', function() {
  console.log('SOCKS server listening on port 1080');
});

srv.useAuth(socks.auth.UserPassword(function(user, password, cb) {
  cb(user === 'nodejs' && password === 'rules!');
}));
  • Server with no authentication and redirecting all connections to localhost:
var socks = require('socksv5');

var srv = socks.createServer(function(info, accept, deny) {
  info.dstAddr = 'localhost';
  accept();
});
srv.listen(1080, 'localhost', function() {
  console.log('SOCKS server listening on port 1080');
});

srv.useAuth(socks.auth.None());
  • Server with no authentication and denying all connections not made to port 80:
var socks = require('socksv5');

var srv = socks.createServer(function(info, accept, deny) {
  if (info.dstPort === 80)
    accept();
  else
    deny();
});
srv.listen(1080, 'localhost', function() {
  console.log('SOCKS server listening on port 1080');
});

srv.useAuth(socks.auth.None());
  • Server with no authentication, intercepting all connections to port 80, and passing through all others:
var socks = require('socksv5');

var srv = socks.createServer(function(info, accept, deny) {
  if (info.dstPort === 80) {
    var socket;
    if (socket = accept(true)) {
      var body = 'Hello ' + info.srcAddr + '!\n\nToday is: ' + (new Date());
      socket.end([
        'HTTP/1.1 200 OK',
        'Connection: close',
        'Content-Type: text/plain',
        'Content-Length: ' + Buffer.byteLength(body),
        '',
        body
      ].join('\r\n'));
    }
  } else
    accept();
});
srv.listen(1080, 'localhost', function() {
  console.log('SOCKS server listening on port 1080');
});

srv.useAuth(socks.auth.None());
  • Client with no authentication:
var socks = require('socksv5');

var client = socks.connect({
  host: 'google.com',
  port: 80,
  proxyHost: '127.0.0.1',
  proxyPort: 1080,
  auths: [ socks.auth.None() ]
}, function(socket) {
  console.log('>> Connection successful');
  socket.write('GET /node.js/rules HTTP/1.0\r\n\r\n');
  socket.pipe(process.stdout);
});
  • HTTP(s) client requests using a SOCKS Agent:
var socks = require('socksv5');
var http = require('http');

var socksConfig = {
  proxyHost: 'localhost',
  proxyPort: 1080,
  auths: [ socks.auth.None() ]
};

http.get({
  host: 'google.com',
  port: 80,
  method: 'HEAD',
  path: '/',
  agent: new socks.HttpAgent(socksConfig)
}, function(res) {
  res.resume();
  console.log(res.statusCode, res.headers);
});

// and https too:
var https = require('https');

https.get({
  host: 'google.com',
  port: 443,
  method: 'HEAD',
  path: '/',
  agent: new socks.HttpsAgent(socksConfig)
}, function(res) {
  res.resume();
  console.log(res.statusCode, res.headers);
});

API

Exports

  • Server - A class representing a SOCKS server.

  • createServer([< function >connectionListener]) - Server - Similar to net.createServer().

  • Client - A class representing a SOCKS client.

  • connect(< object >options[, < function >connectListener]) - Client - options must contain port, proxyHost, and proxyPort. If host is not provided, it defaults to 'localhost'.

  • createConnection(< object >options[, < function >connectListener]) - Client - Aliased to connect().

  • auth - An object containing built-in authentication handlers for Client and Server instances:

    • (Server usage)

      • None() - Returns an authentication handler that permits no authentication.

      • UserPassword(< function >validateUser) - Returns an authentication handler that permits username/password authentication. validateUser is passed the username, password, and a callback that you call with a boolean indicating whether the username/password is valid.

    • (Client usage)

      • None() - Returns an authentication handler that uses no authentication.

      • UserPassword(< string >username, < string >password) - Returns an authentication handler that uses username/password authentication.

  • HttpAgent - An Agent class you can use with http.request()/http.get(). Just pass in a configuration object like you would to the Client constructor or connect().

  • HttpsAgent - Same as HttpAgent except it is for use with https.request()/https.get().

Server events

These are the same as net.Server events, with the following exception(s):

  • connection(< object >connInfo, < function >accept, < function >deny) - Emitted for each new (authenticated, if applicable) connection request. connInfo has the properties:

    • srcAddr - string - The remote IP address of the client that sent the request.

    • srcPort - integer - The remote port of the client that sent the request.

    • dstAddr - string - The destination address that the client has requested. This can be a hostname or an IP address.

    • dstPort - integer - The destination port that the client has requested.

    accept has a boolean parameter which if set to true, will return the underlying net.Socket for you to read from/write to, allowing you to intercept the request instead of proxying the connection to its intended destination.

Server methods

These are the same as net.Server methods, with the following exception(s):

  • (constructor)([< object >options[, < function >connectionListener]]) - Similar to net.Server constructor with the following extra options available:

    • auths - array - A pre-defined list of authentication handlers to use (instead of manually calling useAuth() multiple times).
  • useAuth(< function >authHandler) - Server - Appends the authHandler to a list of authentication methods to allow for clients. This list's order is preserved and the first authentication method to match that of the client's list "wins." Returns the Server instance for chaining.

Client events

  • connect(< Socket >connection) - Emitted when handshaking/negotiation is complete and you are free to read from/write to the connected socket.

  • error(< Error >err) - Emitted when a parser, socket (during handshaking/negotiation), or DNS (if localDNS and strictLocalDNS are true) error occurs.

  • close(< boolean >had_error) - Emitted when the client is closed (due to error and/or socket closed).

Client methods

  • (constructor)(< object >config) - Returns a new Client instance using these possible config properties:

    • proxyHost - string - The address of the proxy to connect to (defaults to 'localhost').

    • proxyPort - integer - The port of the proxy to connect to (defaults to 1080).

    • localDNS - boolean - If true, the client will try to resolve the destination hostname locally. Otherwise, the client will always pass the destination hostname to the proxy server for resolving (defaults to true).

    • strictLocalDNS - boolean - If true, the client gives up if the destination hostname cannot be resolved locally. Otherwise, the client will continue and pass the destination hostname to the proxy server for resolving (defaults to true).

    • auths - array - A pre-defined list of authentication handlers to use (instead of manually calling useAuth() multiple times).

  • connect(< mixed >options[, < function >connectListener]) - Client - Similar to net.Socket.connect(). Additionally, if options is an object, you can also set the same settings passed to the constructor.

  • useAuth(< function >authHandler) - Server - Appends the authHandler to a list of authentication methods to allow for clients. This list's order is preserved and the first authentication method to match that of the client's list "wins." Returns the Server instance for chaining.

More Repositories

1

ssh2

SSH2 client and server modules written in pure JavaScript for node.js
JavaScript
5,493
star
2

busboy

A streaming parser for HTML form data for node.js
JavaScript
2,825
star
3

node-imap

An IMAP client module for node.js.
JavaScript
2,149
star
4

node-ftp

An FTP client module for node.js
JavaScript
1,128
star
5

mmmagic

An async libmagic binding for node.js for detecting content types by data inspection
C++
617
star
6

node-mariasql

A node.js binding to MariaDB's non-blocking (MySQL-compatible) client library
C++
485
star
7

node-ncurses

An ncurses binding for node.js
C++
385
star
8

cap

A cross-platform binding for performing packet capturing with node.js
JavaScript
360
star
9

ssh2-streams

SSH2 and SFTP client/server protocol streams for node.js
JavaScript
204
star
10

node-xxhash

An xxhash binding for node.js
C++
193
star
11

sipster

A pjsip/pjsua2 binding for node.js
C++
190
star
12

dicer

A very fast streaming multipart parser for node.js
JavaScript
186
star
13

httpolyglot

Serve http and https connections over the same port with node.js
JavaScript
181
star
14

connect-busboy

Connect middleware for busboy
JavaScript
155
star
15

node-asterisk

An Asterisk module for node.js
JavaScript
96
star
16

spellcheck

An async hunspell binding for node.js
C++
82
star
17

node-nntp

An NNTP client module for node.js
JavaScript
74
star
18

streamsearch

Streaming Boyer-Moore-Horspool searching for node.js
JavaScript
69
star
19

node-rtp

An RTP module in pure JavaScript for node.js
JavaScript
59
star
20

node-oscar

An OSCAR protocol client module for node.js
JavaScript
54
star
21

cpu-features

A simple node.js binding to Google's cpu_features library for obtaining information about installed CPU(s)
C++
40
star
22

node-pcre

A pcre binding for node.js
C++
39
star
23

esqlite

An SQLite binding for node.js with built-in encryption, focused on simplicity and (async) performance
C++
36
star
24

base91.js

basE91 encoding/decoding for node.js and browsers
JavaScript
31
star
25

bellhop

A node.js module that exposes streams for doing Pubsub and RPC.
JavaScript
28
star
26

ssh-repl

SSH into your node.js process and access a REPL
JavaScript
26
star
27

groan

A PHP session file parser written in JavaScript
JavaScript
24
star
28

paclient

PulseAudio client written in pure JavaScript for node.js
JavaScript
23
star
29

pg2

A PostgreSQL driver for node.js that focuses on performance
JavaScript
21
star
30

pmq

A node.js addon for using POSIX message queues
C++
19
star
31

grappler

A minimalistic server for "comet" connections in Node.js.
JavaScript
19
star
32

reformed

A high-level form field handling and validation module for busboy
JavaScript
18
star
33

zup

A simple, fast template engine for node.js
JavaScript
15
star
34

express-optimized

A minimal, optimized version of Express
JavaScript
13
star
35

xfer

Simple binary TLV reader/writer for node.js
JavaScript
12
star
36

youknow

A realtime, multiplayer card game for node.js that supports multiple frontends
JavaScript
11
star
37

odroid-c2-minimal-debian-ubuntu

Fork of various scripts to setup a minimal debian/ubuntu installation for the odroid c2
Shell
8
star
38

print

A node.js module for communicating with printers
JavaScript
7
star
39

filebounce

A server for bouncing files from point A to point B
JavaScript
7
star
40

node-poormansmysql

MySQL driver module for node.js that executes queries using the mysql command-line client.
JavaScript
7
star
41

buffy

Access and manipulate multiple node.js Buffers as if they were one continuous Buffer
JavaScript
6
star
42

nodebench

Node.js Benchmark Results
HTML
6
star
43

xsys

A node.js binding to useful system-level functions
C++
5
star
44

speaky

A binding to the SVOX Pico engine (libttspico) for performing text-to-speech
C++
4
star
45

lrused

An LRU cache for node.js
JavaScript
4
star
46

conveyor

Feed multiple node.js streams sequentially into one stream
JavaScript
3
star
47

benchd

Benchmark JavaScript code across different node.js/io.js versions from the browser
JavaScript
3
star
48

beepjs

A BEEP protocol implementation for node.js
JavaScript
3
star
49

vermal

A VRML 1.0 push parser for node.js
JavaScript
2
star
50

datatables.sortpriorities

Display column sort orders in your Datatables table headers
JavaScript
1
star
51

build-addons

Build node.js addon binaries for releases using Github Actions
JavaScript
1
star
52

buildcheck

Build environment checking (a la autoconf) for node.js
JavaScript
1
star