socks
Advanced tools
Comparing version 2.7.1 to 2.7.2
@@ -15,3 +15,2 @@ "use strict"; | ||
const net = require("net"); | ||
const ip = require("ip"); | ||
const smart_buffer_1 = require("smart-buffer"); | ||
@@ -23,2 +22,3 @@ const constants_1 = require("../common/constants"); | ||
Object.defineProperty(exports, "SocksClientError", { enumerable: true, get: function () { return util_1.SocksClientError; } }); | ||
const ip_address_1 = require("ip-address"); | ||
class SocksClient extends events_1.EventEmitter { | ||
@@ -166,7 +166,7 @@ constructor(options) { | ||
buff.writeUInt8(constants_1.Socks5HostType.IPv4); | ||
buff.writeUInt32BE(ip.toLong(options.remoteHost.host)); | ||
buff.writeUInt32BE((0, helpers_1.ipv4ToInt32)(options.remoteHost.host)); | ||
} | ||
else if (net.isIPv6(options.remoteHost.host)) { | ||
buff.writeUInt8(constants_1.Socks5HostType.IPv6); | ||
buff.writeBuffer(ip.toBuffer(options.remoteHost.host)); | ||
buff.writeBuffer((0, helpers_1.ipToBuffer)(options.remoteHost.host)); | ||
} | ||
@@ -195,6 +195,6 @@ else { | ||
if (hostType === constants_1.Socks5HostType.IPv4) { | ||
remoteHost = ip.fromLong(buff.readUInt32BE()); | ||
remoteHost = (0, helpers_1.int32ToIpv4)(buff.readUInt32BE()); | ||
} | ||
else if (hostType === constants_1.Socks5HostType.IPv6) { | ||
remoteHost = ip.toString(buff.readBuffer(16)); | ||
remoteHost = ip_address_1.Address6.fromByteArray(Array.from(buff.readBuffer(16))).canonicalForm(); | ||
} | ||
@@ -408,3 +408,3 @@ else { | ||
if (net.isIPv4(this.options.destination.host)) { | ||
buff.writeBuffer(ip.toBuffer(this.options.destination.host)); | ||
buff.writeBuffer((0, helpers_1.ipToBuffer)(this.options.destination.host)); | ||
buff.writeStringNT(userId); | ||
@@ -441,3 +441,3 @@ // Socks 4a (hostname) | ||
port: buff.readUInt16BE(), | ||
host: ip.fromLong(buff.readUInt32BE()), | ||
host: (0, helpers_1.int32ToIpv4)(buff.readUInt32BE()), | ||
}; | ||
@@ -473,3 +473,3 @@ // If host is 0.0.0.0, set to proxy host. | ||
port: buff.readUInt16BE(), | ||
host: ip.fromLong(buff.readUInt32BE()), | ||
host: (0, helpers_1.int32ToIpv4)(buff.readUInt32BE()), | ||
}; | ||
@@ -620,7 +620,7 @@ this.setState(constants_1.SocksClientState.Established); | ||
buff.writeUInt8(constants_1.Socks5HostType.IPv4); | ||
buff.writeBuffer(ip.toBuffer(this.options.destination.host)); | ||
buff.writeBuffer((0, helpers_1.ipToBuffer)(this.options.destination.host)); | ||
} | ||
else if (net.isIPv6(this.options.destination.host)) { | ||
buff.writeUInt8(constants_1.Socks5HostType.IPv6); | ||
buff.writeBuffer(ip.toBuffer(this.options.destination.host)); | ||
buff.writeBuffer((0, helpers_1.ipToBuffer)(this.options.destination.host)); | ||
} | ||
@@ -663,3 +663,3 @@ else { | ||
remoteHost = { | ||
host: ip.fromLong(buff.readUInt32BE()), | ||
host: (0, helpers_1.int32ToIpv4)(buff.readUInt32BE()), | ||
port: buff.readUInt16BE(), | ||
@@ -697,3 +697,3 @@ }; | ||
remoteHost = { | ||
host: ip.toString(buff.readBuffer(16)), | ||
host: ip_address_1.Address6.fromByteArray(Array.from(buff.readBuffer(16))).canonicalForm(), | ||
port: buff.readUInt16BE(), | ||
@@ -756,3 +756,3 @@ }; | ||
remoteHost = { | ||
host: ip.fromLong(buff.readUInt32BE()), | ||
host: (0, helpers_1.int32ToIpv4)(buff.readUInt32BE()), | ||
port: buff.readUInt16BE(), | ||
@@ -790,3 +790,3 @@ }; | ||
remoteHost = { | ||
host: ip.toString(buff.readBuffer(16)), | ||
host: ip_address_1.Address6.fromByteArray(Array.from(buff.readBuffer(16))).canonicalForm(), | ||
port: buff.readUInt16BE(), | ||
@@ -793,0 +793,0 @@ }; |
@@ -41,6 +41,6 @@ "use strict"; | ||
// Command response + incoming connection (bind) | ||
Socks5ResponseHeader: 5, | ||
Socks5ResponseIPv4: 10, | ||
Socks5ResponseIPv6: 22, | ||
Socks5ResponseHostname: (hostNameLength) => hostNameLength + 7, | ||
Socks5ResponseHeader: 5, // We need at least 5 to read the hostname length, then we wait for the address+port information. | ||
Socks5ResponseIPv4: 10, // 4 header + 4 ip + 2 port | ||
Socks5ResponseIPv6: 22, // 4 header + 16 ip + 2 port | ||
Socks5ResponseHostname: (hostNameLength) => hostNameLength + 7, // 4 header + 1 host length + host + 2 port | ||
// Command response + incoming connection (bind) | ||
@@ -55,4 +55,3 @@ Socks4Response: 8, // 2 header + 2 port + 4 ip | ||
SocksCommand[SocksCommand["associate"] = 3] = "associate"; | ||
})(SocksCommand || (SocksCommand = {})); | ||
exports.SocksCommand = SocksCommand; | ||
})(SocksCommand || (exports.SocksCommand = SocksCommand = {})); | ||
var Socks4Response; | ||
@@ -64,4 +63,3 @@ (function (Socks4Response) { | ||
Socks4Response[Socks4Response["RejectedIdent"] = 93] = "RejectedIdent"; | ||
})(Socks4Response || (Socks4Response = {})); | ||
exports.Socks4Response = Socks4Response; | ||
})(Socks4Response || (exports.Socks4Response = Socks4Response = {})); | ||
var Socks5Auth; | ||
@@ -72,4 +70,3 @@ (function (Socks5Auth) { | ||
Socks5Auth[Socks5Auth["UserPass"] = 2] = "UserPass"; | ||
})(Socks5Auth || (Socks5Auth = {})); | ||
exports.Socks5Auth = Socks5Auth; | ||
})(Socks5Auth || (exports.Socks5Auth = Socks5Auth = {})); | ||
const SOCKS5_CUSTOM_AUTH_START = 0x80; | ||
@@ -92,4 +89,3 @@ exports.SOCKS5_CUSTOM_AUTH_START = SOCKS5_CUSTOM_AUTH_START; | ||
Socks5Response[Socks5Response["AddressNotSupported"] = 8] = "AddressNotSupported"; | ||
})(Socks5Response || (Socks5Response = {})); | ||
exports.Socks5Response = Socks5Response; | ||
})(Socks5Response || (exports.Socks5Response = Socks5Response = {})); | ||
var Socks5HostType; | ||
@@ -100,4 +96,3 @@ (function (Socks5HostType) { | ||
Socks5HostType[Socks5HostType["IPv6"] = 4] = "IPv6"; | ||
})(Socks5HostType || (Socks5HostType = {})); | ||
exports.Socks5HostType = Socks5HostType; | ||
})(Socks5HostType || (exports.Socks5HostType = Socks5HostType = {})); | ||
var SocksClientState; | ||
@@ -118,4 +113,3 @@ (function (SocksClientState) { | ||
SocksClientState[SocksClientState["Error"] = 99] = "Error"; | ||
})(SocksClientState || (SocksClientState = {})); | ||
exports.SocksClientState = SocksClientState; | ||
})(SocksClientState || (exports.SocksClientState = SocksClientState = {})); | ||
//# sourceMappingURL=constants.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.validateSocksClientChainOptions = exports.validateSocksClientOptions = void 0; | ||
exports.ipToBuffer = exports.int32ToIpv4 = exports.ipv4ToInt32 = exports.validateSocksClientChainOptions = exports.validateSocksClientOptions = void 0; | ||
const util_1 = require("./util"); | ||
const constants_1 = require("./constants"); | ||
const stream = require("stream"); | ||
const ip_address_1 = require("ip-address"); | ||
const net = require("net"); | ||
/** | ||
@@ -128,2 +130,34 @@ * Validates the provided SocksClientOptions | ||
} | ||
function ipv4ToInt32(ip) { | ||
const address = new ip_address_1.Address4(ip); | ||
// Convert the IPv4 address parts to an integer | ||
return address.toArray().reduce((acc, part) => (acc << 8) + part, 0); | ||
} | ||
exports.ipv4ToInt32 = ipv4ToInt32; | ||
function int32ToIpv4(int32) { | ||
// Extract each byte (octet) from the 32-bit integer | ||
const octet1 = (int32 >>> 24) & 0xff; | ||
const octet2 = (int32 >>> 16) & 0xff; | ||
const octet3 = (int32 >>> 8) & 0xff; | ||
const octet4 = int32 & 0xff; | ||
// Combine the octets into a string in IPv4 format | ||
return [octet1, octet2, octet3, octet4].join('.'); | ||
} | ||
exports.int32ToIpv4 = int32ToIpv4; | ||
function ipToBuffer(ip) { | ||
if (net.isIPv4(ip)) { | ||
// Handle IPv4 addresses | ||
const address = new ip_address_1.Address4(ip); | ||
return Buffer.from(address.toArray()); | ||
} | ||
else if (net.isIPv6(ip)) { | ||
// Handle IPv6 addresses | ||
const address = new ip_address_1.Address6(ip); | ||
return Buffer.from(address.toByteArray()); | ||
} | ||
else { | ||
throw new Error('Invalid IP address format'); | ||
} | ||
} | ||
exports.ipToBuffer = ipToBuffer; | ||
//# sourceMappingURL=helpers.js.map |
{ | ||
"name": "socks", | ||
"private": false, | ||
"version": "2.7.1", | ||
"version": "2.7.2", | ||
"description": "Fully featured SOCKS proxy client supporting SOCKSv4, SOCKSv4a, and SOCKSv5. Includes Bind and Associate functionality.", | ||
@@ -26,3 +26,3 @@ "main": "build/index.js", | ||
"engines": { | ||
"node": ">= 10.13.0", | ||
"node": ">= 10.0.0", | ||
"npm": ">= 3.0.0" | ||
@@ -37,15 +37,14 @@ }, | ||
"devDependencies": { | ||
"@types/ip": "1.1.0", | ||
"@types/mocha": "^9.1.1", | ||
"@types/node": "^18.0.6", | ||
"@typescript-eslint/eslint-plugin": "^5.30.6", | ||
"@typescript-eslint/parser": "^5.30.6", | ||
"@types/mocha": "^10.0.6", | ||
"@types/node": "^20.11.17", | ||
"@typescript-eslint/eslint-plugin": "^6.21.0", | ||
"@typescript-eslint/parser": "^6.21.0", | ||
"eslint": "^8.20.0", | ||
"mocha": "^10.0.0", | ||
"prettier": "^2.7.1", | ||
"prettier": "^3.2.5", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^4.7.4" | ||
"typescript": "^5.3.3" | ||
}, | ||
"dependencies": { | ||
"ip": "^2.0.0", | ||
"ip-address": "^9.0.5", | ||
"smart-buffer": "^4.2.0" | ||
@@ -58,4 +57,5 @@ }, | ||
"lint": "eslint 'src/**/*.ts'", | ||
"build": "rm -rf build typings && prettier --write ./src/**/*.ts --config .prettierrc.yaml && tsc -p ." | ||
"build": "rm -rf build typings && prettier --write ./src/**/*.ts --config .prettierrc.yaml && tsc -p .", | ||
"build-raw": "rm -rf build typings && tsc -p ." | ||
} | ||
} |
@@ -6,5 +6,4 @@ /// <reference types="node" /> | ||
import { Socket, SocketConnectOpts } from 'net'; | ||
import { RequireOnlyOne } from './util'; | ||
declare const DEFAULT_TIMEOUT = 30000; | ||
declare type SocksProxyType = 4 | 5; | ||
type SocksProxyType = 4 | 5; | ||
declare const ERRORS: { | ||
@@ -48,3 +47,3 @@ InvalidSocksCommand: string; | ||
}; | ||
declare type SocksCommandOption = 'connect' | 'bind' | 'associate'; | ||
type SocksCommandOption = 'connect' | 'bind' | 'associate'; | ||
declare enum SocksCommand { | ||
@@ -103,3 +102,3 @@ connect = 1, | ||
*/ | ||
declare type SocksProxy = RequireOnlyOne<{ | ||
interface SocksProxy { | ||
ipaddress?: string; | ||
@@ -115,3 +114,3 @@ host?: string; | ||
custom_auth_response_handler?: (data: Buffer) => Promise<boolean>; | ||
}, 'host' | 'ipaddress'>; | ||
} | ||
/** | ||
@@ -150,3 +149,3 @@ * Represents a remote host | ||
} | ||
declare type SocksClientBoundEvent = SocksClientEstablishedEvent; | ||
type SocksClientBoundEvent = SocksClientEstablishedEvent; | ||
interface SocksUDPFrameDetails { | ||
@@ -153,0 +152,0 @@ frameNumber?: number; |
@@ -0,1 +1,2 @@ | ||
/// <reference types="node" /> | ||
import { SocksClientOptions, SocksClientChainOptions } from '../client/socksclient'; | ||
@@ -14,1 +15,4 @@ /** | ||
export { validateSocksClientOptions, validateSocksClientChainOptions }; | ||
export declare function ipv4ToInt32(ip: string): number; | ||
export declare function int32ToIpv4(int32: number): string; | ||
export declare function ipToBuffer(ip: string): Buffer; |
@@ -14,5 +14,2 @@ import { SocksClientOptions, SocksClientChainOptions } from './constants'; | ||
declare function shuffleArray(array: unknown[]): void; | ||
declare type RequireOnlyOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, Keys>> & { | ||
[K in Keys]?: Required<Pick<T, K>> & Partial<Record<Exclude<Keys, K>, undefined>>; | ||
}[Keys]; | ||
export { RequireOnlyOne, SocksClientError, shuffleArray }; | ||
export { SocksClientError, shuffleArray }; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
156030
9
1512
1
2
+ Addedip-address@^9.0.5
+ Addedip-address@9.0.5(transitive)
+ Addedjsbn@1.1.0(transitive)
+ Addedsprintf-js@1.1.3(transitive)
- Removedip@^2.0.0
- Removedip@2.0.1(transitive)