How to connect to hidden services through the Tor proxy

My end goal is to write a Rust application that connects to an onion address and sends some information. For that, I want to open tor as a child process and use the proxy to connect to the hidden service.
However, I cannot send requests to onion addresses through the proxy. Curl simply says:

~> curl http://xmh57jrknzkhv6y3ls3ubitzfqnkrwxhopf5aygthi7d6rplyvk3noyd.onion/ -x socks://127.0.0.1:9050 -v
* Uses proxy env variable no_proxy == 'localhost,127.0.0.0/8,::1'
*   Trying 127.0.0.1:9050...
* SOCKS4 communication to xmh57jrknzkhv6y3ls3ubitzfqnkrwxhopf5aygthi7d6rplyvk3noyd.onion:80
* SOCKS4 non-blocking resolve of xmh57jrknzkhv6y3ls3ubitzfqnkrwxhopf5aygthi7d6rplyvk3noyd.onion
* Could not resolve host: xmh57jrknzkhv6y3ls3ubitzfqnkrwxhopf5aygthi7d6rplyvk3noyd.onion
* Closing connection 0
curl: (97) Could not resolve host: xmh57jrknzkhv6y3ls3ubitzfqnkrwxhopf5aygthi7d6rplyvk3noyd.onion

Is there a way to do this through proxies or is there a completely different way that Iā€™m missing?

1 Like

Connecting a Rust application to an onion-service would involve different questions but for your curl example have you tried socks5h as the proxy protocol? socks5 attempts to use the DNS of the host system to perform DNS resolution that unless specifically configured knows nothing about Tor (and would be a potential clearnet leak as well.)

3 Likes

First, you should make sure your tor browser can explore this address.

Then, config ~/.curlrc, if not exist,create a new file. input :
proxy = socks5h://127.0.0.1:9050

Third, curl -v

2 Likes

Die you try socks5h ?

3 Likes

socks5h:// instead of just socks:// might be the key for curl

2 Likes