0

I have a fully functional tor hidden service with his v3 url, created with stem and the controller class. The server is redirecting the traffic into a local tcp server running on port 5000 created with socket. But now I want to connect to this hidden service using python. So I tried socks with SOCKS5 proxies, no way of making it work. I also tried the torpy library with the example provided on the offical doc but, again, no way to make it works:

from torpy import TorClient

url = 'myv3torurl.onion'

tor = TorClient()
with tor.create_circuit() as circuit:
    print('circuit done')
    with circuit.create_stream(('http://' + url, 5000)) as client:
        print('sending')
        client.send(b'yeah yeah im there')
        print(client.recv(1024))

Also tried changing the url adding http:// or https://, or tried to change the port with 80, 9050 or 9051. The torpy logs are always the same and you can find them here.

At this point I do not really know what to try. I just want a tcp connection hosted by the onion website. And by the way, I'm sure it's not a problem of the server because if I try to copy and paste the url on the tor browser it is fully reachable. Thank you for any help.

  • Does your hidden service run a web service? Are you able to connect using the Tor Browser? Can you connect to your hidden service outside of Python, for example with torsocks telnet foo.onion? – Steve Oct 9 at 4:18
  • my hidden service is supposed to redirect the traffic to my local-running tcp server. Exactly as a proxy. I'm able to connect with tor browser. Yes i can connect to it. – Gianla Oct 19 at 18:34
0

welcome.

By the message in line 20 of the log:

20. Exception: Can't extend to hidden service

I think your tor daemon is not accepting connections coming to it. Did you created Hidden services in your torrc server machine?

Since I'm a new user and I need 50 messages to be able to post a comment, I will use this Answer field.

For every port you want your tor to accept, you need to create a hidden service. Add these lines to you torrc tor configuration file on the server that is hosting the tor daemon:

HiddenServiceDir C:\Tor\Data\Tor\os-ssh
HiddenServicePort 22 127.0.0.1:22

Change the path to adequate to your system, the ports to the ports you are currently using, and the name "os-ssh" to whatever you want. You can opt to maintain the prefix "os-" since I think it is the most default one.

Nevertheless to say, you can add several hidden services, just copy and past those two lines and edit as you wish.

If you are using the tor service as a proxy server, for others connect through it or even your application, you need to add:

SocksPort 192.168.0.5:9100
SocksPolicy accept 192.168.0.0/24

Here change the ip to the ip of your computer that is running tor and change the default port from 9050 to 9100, to avoid conflicts, mainly if you also use Tor Browser (as I use). The SocksPolicy you can configure to accept all incoming connections from your local network trying to user this tor as a proxy server, instead of have to install the tor application on every computer. You can also change the ip to * (SocksPolicy accept *), meaning you will accept all incoming connections to serve as a proxy. You can also read more about the reject options, instead of accept.

Sorry by the awful text formatting, this is ones of my first posts here.

P.S. You can also create your application normally as you as working with ipv4 address, and using some proxy software like torsocks (linux) or Proxifier (windows). They you resolve the onions addresses, since they will use the proxy to resolve DNS(in Proxifier, if you check a box containing such option). Anyway, if you use linux, preffer seriously torsocks.

| improve this answer | |
  • you absolutely hit the point. I want a proxy to my local-running tcp server. I'm on linux so do you still recommend torsocks? Also, how do i use it? – Gianla Oct 14 at 14:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.