astro / socksify-ruby

Redirect any TCP connection initiated by a Ruby script through a SOCKS5 proxy
http://socksify.rubyforge.org/
Other
165 stars 80 forks source link

HTTPS not supported? #55

Closed fokx closed 4 months ago

fokx commented 8 months ago
require 'socksify/http'

Socksify::debug = true
uri = URI.parse('https://google.com')
Net::HTTP.socks_proxy('127.0.0.1', 3999).start(uri.host, uri.port) do |http|
  req = Net::HTTP::Get.new uri
  resp = http.request(req)
  puts resp.inspect
  puts resp.body
end

gives this error:

18:22:06 Connecting to SOCKS server 127.0.0.1:3999
18:22:06 Sending no authentication
18:22:06 Waiting for authentication reply
18:22:06 Sending destination address
18:22:06 ["05"]
18:22:06 google.com
18:22:06 Waiting for SOCKS reply
18:22:06 ["05000001"]
18:22:06 Waiting for bind_addr
18:22:06 Connected to google.com:443 over SOCKS
18:22:07 Connecting to SOCKS server 127.0.0.1:3999
18:22:07 Sending no authentication
18:22:07 Waiting for authentication reply
18:22:07 Sending destination address
18:22:07 ["05"]
18:22:07 google.com
18:22:07 Waiting for SOCKS reply
18:22:07 ["05000001"]
18:22:07 Waiting for bind_addr
18:22:07 Connected to google.com:443 over SOCKS
Uncaught exception: end of file reached
    /home/liu/.rvm/rubies/ruby-3.3.0/lib/ruby/3.3.0/net/protocol.rb:237:in `rbuf_fill'
    /home/liu/.rvm/rubies/ruby-3.3.0/lib/ruby/3.3.0/net/protocol.rb:199:in `readuntil'
    /home/liu/.rvm/rubies/ruby-3.3.0/lib/ruby/3.3.0/net/protocol.rb:209:in `readline'
    /home/liu/.rvm/rubies/ruby-3.3.0/lib/ruby/3.3.0/net/http/response.rb:158:in `read_status_line'
    /home/liu/.rvm/rubies/ruby-3.3.0/lib/ruby/3.3.0/net/http/response.rb:147:in `read_new'
    /home/liu/.rvm/rubies/ruby-3.3.0/lib/ruby/3.3.0/net/http.rb:2342:in `block in transport_request'
    /home/liu/.rvm/rubies/ruby-3.3.0/lib/ruby/3.3.0/net/http.rb:2333:in `catch'
    /home/liu/.rvm/rubies/ruby-3.3.0/lib/ruby/3.3.0/net/http.rb:2333:in `transport_request'
    /home/liu/.rvm/rubies/ruby-3.3.0/lib/ruby/3.3.0/net/http.rb:2306:in `request'
    /f/ru/scan_xyz.rb:35:in `block in <top (required)>'
    /home/liu/.rvm/rubies/ruby-3.3.0/lib/ruby/3.3.0/net/http.rb:1570:in `start'
    /home/liu/.rvm/rubies/ruby-3.3.0/lib/ruby/3.3.0/net/http.rb:1029:in `start'
    /f/ru/scan_xyz.rb:33:in `<top (required)>'
    /home/liu/.rvm/gems/ruby-3.3.0/gems/debase-3.0.0.beta.10/lib/debase.rb:224:in `load_protect'
    /home/liu/.rvm/gems/ruby-3.3.0/gems/debase-3.0.0.beta.10/lib/debase.rb:224:in `debug_load'
/home/liu/.rvm/rubies/ruby-3.3.0/lib/ruby/3.3.0/net/protocol.rb:237:in `rbuf_fill': end of file reached (EOFError)
    from /home/liu/.rvm/rubies/ruby-3.3.0/lib/ruby/3.3.0/net/protocol.rb:199:in `readuntil'
    from /home/liu/.rvm/rubies/ruby-3.3.0/lib/ruby/3.3.0/net/protocol.rb:209:in `readline'
    from /home/liu/.rvm/rubies/ruby-3.3.0/lib/ruby/3.3.0/net/http/response.rb:158:in `read_status_line'
    from /home/liu/.rvm/rubies/ruby-3.3.0/lib/ruby/3.3.0/net/http/response.rb:147:in `read_new'
    from /home/liu/.rvm/rubies/ruby-3.3.0/lib/ruby/3.3.0/net/http.rb:2342:in `block in transport_request'
    from /home/liu/.rvm/rubies/ruby-3.3.0/lib/ruby/3.3.0/net/http.rb:2333:in `catch'
    from /home/liu/.rvm/rubies/ruby-3.3.0/lib/ruby/3.3.0/net/http.rb:2333:in `transport_request'
    from /home/liu/.rvm/rubies/ruby-3.3.0/lib/ruby/3.3.0/net/http.rb:2306:in `request'
    from /f/ru/scan_xyz.rb:35:in `block in <top (required)>'
    from /home/liu/.rvm/rubies/ruby-3.3.0/lib/ruby/3.3.0/net/http.rb:1570:in `start'
    from /home/liu/.rvm/rubies/ruby-3.3.0/lib/ruby/3.3.0/net/http.rb:1029:in `start'
    from /f/ru/scan_xyz.rb:33:in `<top (required)>'
    from /home/liu/.rvm/gems/ruby-3.3.0/gems/debase-3.0.0.beta.10/lib/debase.rb:224:in `load_protect'
    from /home/liu/.rvm/gems/ruby-3.3.0/gems/debase-3.0.0.beta.10/lib/debase.rb:224:in `debug_load'
    from /home/liu/.rvm/gems/ruby-3.3.0/gems/ruby-debug-ide-3.0.0.beta.15/lib/ruby-debug-ide.rb:129:in `debug_program'
    from /home/liu/.rvm/gems/ruby-3.3.0/gems/ruby-debug-ide-3.0.0.beta.15/bin/rdebug-ide:202:in `<main>'

if URL is changed to http://google.com

18:22:52 Connected to google.com:80 over SOCKS
#<Net::HTTPMovedPermanently 301 Moved Permanently readbody=true>
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved

So HTTPS is not supported?

Also I cannot find any working full-featured SOCKS5 proxy for ruby like PySocks for Python.

atomical commented 4 months ago

It is supported. Example:

  def current_ip_address_https
    uri = URI.parse('https://api.ipify.org/')
    Net::HTTP.SOCKSProxy('127.0.0.1', 9050).start(uri.host, uri.port, use_ssl: true) do |http|
      return http.get(uri.path).body
    end
  end

Your code is missing the use_ssl argument.

fokx commented 4 months ago

Thanks!