ruby - 如何使用 Ruby 构建 HTTP 请求并将其发送到 Tor 隐藏服务

标签 ruby tor

过去几天我一直在寻找这个问题的解决方案,虽然有很多半相关的问题,但没有一个答案显示通过 Tor 发送成功的 HTTP 请求的成功用例使用 Ruby 的隐藏服务。

所有答案中似乎不清楚的一件事是 Tor 浏览器包如何充当请求代理。

我尝试了多种攻击途径,最近的一次是尝试改编 the PHP code here使用 Ruby CURL 库向隐藏服务发送 curl 请求。

这是我使用 Curb gem 的代码,它为 Ruby 实现了一些 libcurl 绑定(bind):

require 'curb'

url = 'http://am4wuhz3zifexz5u.onion' #a known, functioning hidden service

c = Curl::Easy.new(url) do |curl| 
  curl.headers["User-Agent"] = "Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Firefox/24.0" #the user agent string from the most recent version of the tor browser
  curl.verbose = true
end

c.perform
c.inspect

然后我尝试通过 socksify 运行它,使用 Tor 浏览器包的代理设置指定的 IP 地址和端口:

$ socksify_ruby 127.0.0.1 9150 tor-test/tor-test.rb

这产生了以下输出:

* Adding handle: conn: 0x7fb1fe195e00
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x7fb1fe195e00) send_pipe: 1, recv_pipe: 0
* Could not resolve host: jhiwjjlqpyawmpjx.onion
* Closing connection 0

我尝试过的每种方法都产生了类似的结果:无法解析隐藏服务的 URI

任何人都可以帮我解决这个问题或指出正确的方向吗?我觉得既然 Tor 浏览器可以通过编程方式连接到隐藏的服务,我们也应该能够:)

最佳答案

如果您在“curl” block 中设置代理,则 Curl 仅使用代理。

例如:

c = Curl::Easy.new() do |curl| 
    curl.proxy_tunnel = true
    curl.proxy_type = Curl::CURLPROXY_SOCKS5 # also available and default Curl::CURLPROXY_HTTP
    curl.proxy_url = '127.0.0.1:9050' # local tor client/proxy
    curl.headers["User-Agent"] = "Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Firefox/24.0" #the user agent string from the most recent version of the tor browser
    curl.verbose = true
    curl.url = url # your example url
    curl.perform
    curl.inspect
end

不幸的是,curl 不使用代理来解析主机名。换句话说,我没有找到强制 curl 使用代理进行主机名解析的方法。

不过你可以试试

#enable socksify debug
Socksify::debug = true

#own try via direct use of socksify and Net::HTTP
uri = URI.parse('http://am4wuhz3zifexz5u.onion/') #a known, functioning hidden service

# some debug stuff - just ignore ;-)
puts uri
puts uri.host
puts uri.port
puts uri.path

res1 = Net::HTTP.SOCKSProxy('127.0.0.1', 9050).start(uri.host, uri.port) do |http| 
    http.get(uri.path)
end

关于ruby - 如何使用 Ruby 构建 HTTP 请求并将其发送到 Tor 隐藏服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22003474/

相关文章:

java - htmlunit 上的 Tor

ubuntu - 当我启动容器时启动 tor 和 polipo

java - IntelliJ IDEA : What qualifies as an SDK?

ruby - 在 Nagiosgraph 中绘制多个磁盘卷

java - 如何使用 java 为 tor onion 服务生成有效的私钥(RSA 1024)?

python - 通过tor发出请求,requests.exceptions.ConnectionError Errno 61 : Connection Refused

.net - 如何通过 Tor 发出 httpwebrequest

ruby - 在 Ruby 中,如何从外部进程读取内存值?

ruby-on-rails - 如何同时在 localhost 和 web 上运行 Ruby 项目?

ruby-on-rails - Rails ActiveRecord 序列化数据 Rspec 测试