Created
June 10, 2026 10:16
-
-
Save Kattoor/57e20e97e3e093e0f04f4c6504d9f7e9 to your computer and use it in GitHub Desktop.
repro.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const net = require('net'); | |
| const { URL } = require('url'); | |
| const proxy = new URL('socks5://USERNAME:PASSWORD@rp.scrapegw.com:6060'); | |
| const targetHost = '18.117.245.0'; | |
| const targetPort = 43594; | |
| const iterations = 10; | |
| const probe = Buffer.from('0000000100', 'hex'); | |
| if (proxy.hostname === 'PROXY_HOST') { | |
| console.error('Set SOCKS5_PROXY first. Example: socks5://user:pass@host:port'); | |
| process.exit(1); | |
| } | |
| (async () => { | |
| for (let i = 0; i < iterations; i++) { | |
| const sock = net.connect(Number(proxy.port), proxy.hostname); | |
| try { | |
| await connected(sock); | |
| const user = Buffer.from(decodeURIComponent(proxy.username)); | |
| const pass = Buffer.from(decodeURIComponent(proxy.password)); | |
| sock.write(Buffer.from([5, 2, 0, 2])); | |
| let r = await read(sock); | |
| if (r[0] !== 5) return print(i, 'not-socks-greeting', r); | |
| if (r[1] === 2) { | |
| sock.write(Buffer.concat([Buffer.from([1, user.length]), user, Buffer.from([pass.length]), pass])); | |
| r = await read(sock); | |
| if (r[1] !== 0) return print(i, 'auth-failed', r); | |
| } | |
| sock.write(Buffer.concat([ | |
| Buffer.from([5, 1, 0]), | |
| socksHost(targetHost), | |
| Buffer.from([targetPort >> 8, targetPort & 255]) | |
| ])); | |
| r = await read(sock); | |
| if (r[0] !== 5 || r[1] !== 0) return print(i, 'connect-failed', r); | |
| sock.write(probe); | |
| r = await read(sock, true); | |
| print(i, startsWithHttp(r) ? 'http-response' : 'tcp-or-empty', r); | |
| } catch (e) { | |
| console.log(JSON.stringify({ attempt: i, result: 'error', error: e.message })); | |
| } finally { | |
| sock.destroy(); | |
| await sleep(250); | |
| } | |
| } | |
| })(); | |
| function socksHost(host) { | |
| if (net.isIP(host) === 4) return Buffer.from([1, ...host.split('.').map(Number)]); | |
| const b = Buffer.from(host); | |
| return Buffer.concat([Buffer.from([3, b.length]), b]); | |
| } | |
| function connected(sock) { | |
| return new Promise((resolve, reject) => { | |
| const t = setTimeout(() => reject(new Error('connect timeout')), 8000); | |
| sock.once('connect', () => { clearTimeout(t); resolve(); }); | |
| sock.once('error', reject); | |
| }); | |
| } | |
| function read(sock, allowTimeout = false) { | |
| return new Promise((resolve, reject) => { | |
| const t = setTimeout(() => allowTimeout ? resolve(Buffer.alloc(0)) : reject(new Error('read timeout')), 8000); | |
| sock.once('data', (b) => { clearTimeout(t); resolve(b); }); | |
| sock.once('error', reject); | |
| }); | |
| } | |
| function print(attempt, result, buf) { | |
| const ascii = buf.toString('latin1').replace(/[^\x09\x0a\x0d\x20-\x7e]/g, '.').slice(0, 120); | |
| console.log(JSON.stringify({ | |
| attempt, | |
| result, | |
| bytes: buf.length, | |
| http: (ascii.match(/^HTTP\/\d(?:\.\d)?\s+\d{3}[^\r\n]*/) || [null])[0], | |
| ascii, | |
| hex: buf.slice(0, 80).toString('hex') | |
| })); | |
| } | |
| function startsWithHttp(buf) { | |
| return /^HTTP\/\d(?:\.\d)?\s+\d{3}/.test(buf.toString('latin1')); | |
| } | |
| function sleep(ms) { | |
| return new Promise((resolve) => setTimeout(resolve, ms)); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment