-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Difficulty of probing Tor hidden services #264
Comments
The blackbox exporter is intended to handle a small number of standard of probes. The Tor use case is quite a bit away from that on several axes, so as with anything like that I'd suggest writing a custom exporter rather than trying to overload the blackbox exporter. |
Use case aside, that's a bug. I would never expect an HTTP proxy client to perform DNS resolution (of anything but the proxy's hostname itself). That's not how HTTP proxies are supposed to work. |
Our support for control of v4/v6 requires us to do the resolution ourselves. It's expected that the vast majority of users are hitting services directly, not via a proxy. That's merely something that comes in with the http library we use. |
Thinking on this a bit, our current http module isn't great for testing of HTTP proxies which is something we should really support. Similar to how the DNS module works, what would you think of a module/option where the target was the proxy to use and the actual HTTP request line coming from the config? Have you looked at doing what you want via the TCP module? |
@brian-brazil That sounds good to me. As long as I can pass an .onion DNS name along to the proxy without getting resolution errors from blackbox, then I can have the proxy handle SOCKS/Tor and everything else. I've not looked at using the TCP module and not sure what that would look like... I'm seeking HTTP 200 responses, the goal is to make sure these hidden services are up. Think of an ecosystem like SecureDrop where you have 40+ of these targets. You might even want to check for a version string showing up in the page. |
@ageis there is another way to achieve the goal of testing Unfortunately, there is no clean way to resolve Also, I looked at current blackbox_exporter codebase, and I consider it impractical to add Socks5 proxy support to every prober speaking over TCP. But it may also be useful for cases when the host-to-be-probbed is reachable via OpenSSH I see following extention points to solve the issue:
Seems, The method I describe has following flaws:
IMHO, pain with BPF rules should be reduced with some code implementing
|
@ageis SOCKS should be supported by blackbox_exporter as it just uses Go http Transport. So it all comes down to make one single option available: bypass local DNS resolution. |
As indicated above, that'd break our v4/v6 features so would not be accepted. |
Using the use_proxy_dns feature would make the ip version selection ignored. That would be logic, in the same way that you don’t use tls options when using unsecured http. |
That'd be confusing though, as it's not that endpoint you're testing then
but actually the proxy server.
…On Fri 22 Nov 2019, 17:20 Pascal Fautré, ***@***.***> wrote:
Using the use_proxy_dns feature would make the ip version selection
ignored. That would be logic, in the same way that you don’t use tls
options when using unsecured http.
It would be an expected behavior, nothing being broken.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#264?email_source=notifications&email_token=ABWJG5QU7NJW5E4QSBHREZLQVABGTA5CNFSM4EEMTX4KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEE6EDFQ#issuecomment-557597078>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABWJG5XUQW3TQOET3IEQWBLQVABGTANCNFSM4EEMTX4A>
.
|
@darkk I intend to review your stuff you've posted soon; eventually after my original post I did get a reliable and not-too-convoluted THS-monitoring setup that simply relies upon shoving all requests through Privoxy, and as I recall a few of the roadblocks I had encountered in the beginning have since dissipated; which I think might've been related to the Prometheus team deciding to use miekg/dns.
Thanks for the BPF rule! That is really cool. |
@brian-brazil it is end to end testing, the purpose of blackbox monitoring. |
Hey @darkk I'm curious, is it possible to make your netfilter+BPF rule work for version 3 hidden services as well as v2? |
Onionprobe fits the use case of Onion Services sites monitoring and was created the after evaluating (and being inspired by) the blackbox exporter. It comes with built-in Prometheus exporter with many metrics and has a relatively easy setup process. (Disclosure: I'm the Onionprobe maintainer) |
Debian stretch/9.x
all versions of blackbox_exporter
This is sort of partly a bug and partly a feature request. I wanted to monitor some Tor hidden services using Prometheus and I eventually got it to work, but it required a lot of effort. I discovered that these tools are pretty ill-suited to that use case. Unfortunately I can't tell you exactly what the magic combination was since there's so many factors involved, but I'd like to document my experience and touch upon the difficulties encountered. I'll provide configuration files at the bottom of this post.
My setup is thus: I run Tor with the DNSPort (5353), SOCKSPort (9050) and TransPort (9040) enabled. I configure it to listen on and accept requests from localhost, as well as resolve all .onion addresses to a virtual/fake IPv4 address (AutomapHostsOnResolve+VirtualAddrNetworkIPv4). For some help with caching, I run dnsmasq and put it on top of that, and I then direct all name resolution on my machine through Tor via resolv.conf and/or iptables.
We also need to have a transparent HTTP proxy in the picture, since Tor doesn't provide one. Alas, it only provides support for SOCKS, transparent TCP proxying, and DNS. SOCKS is not supported by blackbox_exporter, so I guess that would be one of the first problems I'd highlight. But anyway, to solve that I run Privoxy, which listens on port 8118 and sends HTTP requests through Tor's SOCKS port. I set
proxy_url
in the params of my scrape configs in prometheus.yml and include that in blackbox.yml as well, as well as setting the HTTP_PROXY environment variable.Right off the bat, I had issues with Go's built-in DNS resolver. We need to use CGO in order for this to work! Apparently you can force CGO by setting the RES_OPTIONS environment variable, but I'm not sure on that. So I rebuilt Go from source with the netcgo build tag, plus built the blackbox_exporter binary with
GODEBUG="netdns=cgo+1" GOFLAGS="-tags=netcgo" CGO_ENABLED=1
.One other thing which I tried and should mention, yet I'm not sure to what extent it helped, is modifying the ExecStart command in prometheus-blackbox-exporter's systemd service unit and prepending /usr/bin/torsocks to it. That's a shell wrapper which is supposed to make everything go through the Tor network by using the torsocks library to re-write system calls—in theory that should mean I wouldn't need the proxy or DNS setup here. I experimented with different versions, e.g. the binary 0.9.1 package in stretch-backports vs. the current master branch and got different results. Sometimes torify/torsocks did seem to help name resolution complete successfully, other times it looked like it had no effect. Another way of doing it is like this:
Throughout this whole process, I witnessed a variety of errors. "resolution with preferred IP protocol failed, attempting fallback protocol"..."temporary failure in name resolution"..."context deadline exceeded"..."connection reset by peer" (from Privoxy)..."Error resolving address...no suitable address found" and so on.
To summarize, the primary issue with probing Tor hidden services is that blackbox_exporter wants to do DNS resolution of the target address before passing the request along to the HTTP proxy, instead of letting the proxy handle it. The more problematic failure that I've seen is where resolution succeeds except blackbox_exporter reports an error (EOF) in the HTTP request: "Error for HTTP request" err="Get http://[10.197.95.211]: EOF" which is weird and kind of smells like it never passed the request along to the proxy and tried to do the probing itself. The other issue is that for some reason we can't use a binary which prefers Go's built-in resolver and need to use CGO in order to access Tor hidden services.
I doubt so many users want this, but I would suggest a new config option to help make all of this easier. Such an option would essentially disable the successful DNS resolution requirement and still pass the request along to the specified proxy regardless of any error there.
I hope this has been informative. Now, without further ado, here's my configs for anyone else who wants to experiment.
/etc/prometheus/blackbox.yml:
Extra environment variables for
/etc/default/prometheus-blackbox-exporter
in addition to ARGS:/etc/prometheus/prometheus.yml:
/etc/tor/torrc:
/etc/dnsmasq.conf:
/etc/privoxy/config:
The text was updated successfully, but these errors were encountered: