znetstar / tor-router Goto Github PK
View Code? Open in Web Editor NEWA SOCKS, HTTP and DNS proxy for distributing traffic across multiple instances of Tor
License: Apache License 2.0
A SOCKS, HTTP and DNS proxy for distributing traffic across multiple instances of Tor
License: Apache License 2.0
Hi, I'm running the Docker image and sending a request via nodejs
this is my code
import * as request from 'request';
request.get('http://example.com/', {
proxy:'http://localhost:1637',
},(e,r,b)=>{
console.log(e)
console.log(b)
console.log(r)
})
this is my output of the code:
{ Error: socket hang up
at createHangUpError (_http_client.js:323:15)
at Socket.socketOnEnd (_http_client.js:426:23)
at Socket.emit (events.js:203:15)
at endReadableNT (_stream_readable.js:1145:12)
at process._tickCallback (internal/process/next_tick.js:63:19) code: 'ECONNRESET' }
and these are my logs from Docker run:
>> docker run --rm -it -p 1637:9050 znetstar/tor-router -j 3 -h 127.0.0.1:9050
info: [control]: control server listening on tcp://:9077
info: [tor]: starting 3 tor instance(s)...
info: [tor-mXwaXKrDTKhS]: DNS PORT = 33353
info: [tor-mXwaXKrDTKhS]: SOCKS PORT = 46205
info: [tor-mXwaXKrDTKhS]: CONTROL PORT = 35985
info: [tor-ThoNeFBBQbV4]: DNS PORT = 42767
info: [tor-ThoNeFBBQbV4]: SOCKS PORT = 35143
info: [tor-ThoNeFBBQbV4]: CONTROL PORT = 40665
info: [tor-PL7fQWJDejLo]: DNS PORT = 34869
info: [tor-PL7fQWJDejLo]: SOCKS PORT = 37579
info: [tor-PL7fQWJDejLo]: CONTROL PORT = 44301
info: [http]: listening on http://127.0.0.1:9050
info: [tor-mXwaXKrDTKhS]: tor is ready
warn: [tor-PL7fQWJDejLo]: Unparseable microdescriptor
warn: [tor-PL7fQWJDejLo]: Illegal nickname "$B771AA877687F88E6F1CA5354756DF6C8A7B6B2" in family line
info: [tor-PL7fQWJDejLo]: tor is ready
info: [tor-ThoNeFBBQbV4]: tor is ready
info: [tor]: tor started
When populating TorPool with a larger number of TorProcesses, a race condition appears when getting the ports. This is a known problem of the get-port package (Compare sindresorhus/get-port#23), but as there is no better solution so far I suggest that we shift getting the default ports outside of the TorProcess into the creation function of the TorPool and protect the execution of the getPort function, such that no race conditions should appear.
A suggested fix can be found in pull request #14
I want a separate instance or ip for several "users" and I want to avoid the ips overlapping for each set of requests as much as possible... however I read requests using this router are sent in a "round robin" fashion?
Is this possible using this library?
cat@cate-ssd:~/Projects/tor-router$ npm run start
> [email protected] start /home/cat/Projects/tor-router
> bin/tor-router -s -d -j 1
info: [control]: control server listening on tcp://:9077
/home/cat/Projects/tor-router/node_modules/multi-rpc-tcp-transport/lib/TCPTransport.js:145
this.server.off('error', listenError);
^
TypeError: this.server.off is not a function
at Server.listenSuccess (/home/cat/Projects/tor-router/node_modules/multi-rpc-tcp-transport/lib/TCPTransport.js:145:29)
at Object.onceWrapper (events.js:272:13)
at Server.emit (events.js:180:13)
at emitListeningNT (net.js:1373:10)
at process._tickCallback (internal/process/next_tick.js:178:19)
at Function.Module.runMain (internal/modules/cjs/loader.js:697:11)
at startup (internal/bootstrap/node.js:201:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:516:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `bin/tor-router -s -d -j 1`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/cat/.npm/_logs/2019-01-15T14_21_05_715Z-debug.log
when I am trying to run tor-router -j 3 -s 127.0.0.1:16379
with node v10.17.0
and npm 6.13.0
`info: [control]: control server listening on tcp://:9077
info: [tor]: starting 3 tor instance(s)...
info: [socks]: listening on socks5://127.0.0.1:16379
events.js:174
throw er; // Unhandled 'error' event
^
Error: spawn /home/shibu/Downloads/node_modules/granax/bin/tor-browser_en-US/Browser/TorBrowser/Tor/tor ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:240:19)
at onErrorNT (internal/child_process.js:415:16)
at process._tickCallback (internal/process/next_tick.js:63:19)
Emitted 'error' event at:
at Process.ChildProcess._handle.onexit (internal/child_process.js:246:12)
at onErrorNT (internal/child_process.js:415:16)
at process._tickCallback (internal/process/next_tick.js:63:19)
`
Also, granax dependencies are changes to @deadcanaries/granax
. Can you please help me fixing the issue.
Please provide a samplke of how I could use this lib.
Eg sample request from postman via tor proxy to http://google.com
tor-router links to a module, @deadcanaries/granax, which downloads and installs tor locally within the application, among other things. This module carries the AGPL 3.0 license, and my understanding of this license is that any works using it would also need to be licensed as AGPL 3.0.
I see tor-router is licensed as Apache 2.0. Is this license valid, considering it is using an AGPL 3.0 component?
Thank you,
Hi,
I've run into the following issue and did not yet find a workaround.
Setup information: I run tor-router within a Docker container and on docker start, only the Control Server is initialized.
Afterward, a Tor pool, a socket server and ten Tor instances are created in code (see below), which seems to work as expected, since the logs show
[control]: Control Server listening on 9077
[socks]: listening on 9050
[tor-19]: tor is ready
[tor-22]: tor is ready
... [more output omitted]
Creation of Tor pool/socket server & Tor instances:
async createTorPool() {
let rpcId = this.currentRPCId;
this.currentRPCId += 1;
let createTorRequest = {
"method": "createTorPool",
"params": [],
"jsonrpc": "2.0",
"id": rpcId,
};
this.client.write(JSON.stringify(createTorRequest));
return new Promise( (resolve, reject) => {
this.client.on("data", (chunk) => {
let rawResponse = chunk.toString("utf8");
let rpcResponse = JSON.parse( rawResponse );
if (rpcResponse.id === rpcId) {
resolve(rpcResponse);
}
});
setTimeout(() => {
reject("createTorPool request timed out.");
}, this.timeout);
});
}
async createSocksServer(socksPort) {
// Set torPort to 9050 (Tor standard), if undefined
if (socksPort) {
this.socksPort = socksPort;
}
if (!this.socksPort) {
this.socksPort = 9050;
}
let rpcId = this.currentRPCId;
this.currentRPCId += 1;
let createSocksRequest = {
"method": "createSOCKSServer",
"params": [socksPort],
"jsonrpc": "2.0",
"id": rpcId,
};
this.client.write(JSON.stringify(createSocksRequest));
return new Promise( (resolve, reject) => {
this.client.on("data", (chunk) => {
let rawResponse = chunk.toString("utf8");
let rpcResponse = JSON.parse( rawResponse );
if (rpcResponse.id === rpcId) {
resolve(rpcResponse);
}
});
setTimeout(() => {
reject("createSocksServer request timed out.");
}, this.timeout);
});
}
async createTorInstances(numOfInstances) {
let rpcId = this.currentRPCId;
this.currentRPCId += 1;
let createTorInstancesRequest = {
"method": "createInstances",
"params": [numOfInstances],
"jsonrpc": "2.0",
"id": rpcId,
};
this.client.write(JSON.stringify(createTorInstancesRequest));
return new Promise( (resolve, reject) => {
this.client.on( "data", (chunk) => {
let rawResponse = chunk.toString("utf8");
let rpcResponse = JSON.parse( rawResponse );
if (rpcResponse.id == rpcId) {
resolve(rpcResponse);
}
});
setTimeout(() => {
reject("createTorInstances timed out.");
}, this.timeout);
});
}
However, if I send a request to the socks proxy (See code section below), the logs say
(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use
emitter.setMaxListeners() to increase limit.
Trace
at TorPool.logPossibleMemoryLeak (/app/node_modules/eventemitter2/lib/eventemitter2.js:53:15)
at TorPool.EventEmitter.on (/app/node_modules/eventemitter2/lib/eventemitter2.js:517:31)
at TorPool.EventEmitter.many (/app/node_modules/eventemitter2/lib/eventemitter2.js:269:10)
at TorPool.EventEmitter.once (/app/node_modules/eventemitter2/lib/eventemitter2.js:249:10)
at SOCKSServer.handleConnection (/app/src/SOCKSServer.js:75:14)
at emitThree (events.js:136:13)
at SOCKSServer.emit (events.js:217:7)
at Parser.<anonymous> (/app/node_modules/socksv5/lib/server.js:130:12)
at emitOne (events.js:116:13)
at Parser.emit (events.js:211:7)
Code for sending the request over the SOCKS proxy:
let headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; rv:52.0) Gecko/20100101 Firefox/52.0",
"Accept-Language": "en-US,en;q=0.5",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Accept-Encoding": "identity",
"Connection": "keep-alive",
};
let request = {
method: "GET",
hostname: url,
path: path,
agent: new ProxyAgent("socks://127.0.0.1:9050"),
headers: headers,
};
let startTime = (new Date).getTime();
let request = http.get(request);
The same appears if I set the SOCKS proxy as the proxy of my browser and try to connect to a website.
So my question is: Is this an issue in my code and if yes: how should a request over this proxy be structured?
Thank you for your response!
I am looking to use tor in my website for certain api request. I was wondering if this library can be used in browser via webpack like libraries. If not do you know of any other tor library that comes bundled with tor that can be used as such.
Hi, I'm trying to run tor-router as PM2 process, but no matter what, the instances count remains 1, I've passed different values as -j 3 or -j 5 , Weird part is every argument parses fine till the point
234 > nconf.argv(argv_config); (launch.js)
but after that if you do nconf.get('instances');
it gives output of 1, always when running via PM2.
I'm not sure if it's a bug with pm2 or nconf coupled with pm2 , but It's kind of use case i'm trying to accomplish,
I couldn't see a way to do this, is it possible and I am missing it?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.