I have tried using curl through tor like so
curl --socks5 127.0.0.1:9050 XXXXXXXXXXXXXXX.onion
This works for public addresses like stackoverflow.com but not for tor .onion addresses
Moreover, you should use
torsocks - built-in utility for working with Tor Network.
It is designed to prevent any leakage! Please, read the man page.
root@localhost:/# torsocks curl XXXXXXXXXXXXXXX.onion
Otherwise, if you are trying to resolve .onion name to IPv6, you are able to use
tor-resolve utility, it is built-in too:
root@localhost:/# tor-resolve kpvz7ki2v5agwt35.onion fe80:7cd1:5f4e:a9d5:dfe:1976:5edf:4386
Of-course, this IP address it temporary one and can be used only from your
localhost for the limited time.
Moreover, your traffic shall be redirected through Tor's transparent proxy connections port -
TransPort, which is always, by default
9040. See the documentation about transparent & isolated proxies on the torproject.org's wiki site.
Thereafter, you can use this IP directly with
anonymous@localhost:/$ curl fe80:7cd1:5f4e:a9d5:dfe:1976:5edf:4386
Or just use .onion domain:
anonymous@localhost:/$ curl XXXXXXXXXXXXXXX.onion