This file is indexed.

/usr/lib/ruby/vendor_ruby/net/ssh/proxy/socks4.rb is in ruby-net-ssh 1:3.2.0-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
require 'socket'
require 'resolv'
require 'ipaddr'
require 'net/ssh/proxy/errors'

module Net
  module SSH
    module Proxy

      # An implementation of a SOCKS4 proxy. To use it, instantiate it, then
      # pass the instantiated object via the :proxy key to Net::SSH.start:
      #
      #   require 'net/ssh/proxy/socks4'
      #
      #   proxy = Net::SSH::Proxy::SOCKS4.new('proxy.host', proxy_port, :user => 'user')
      #   Net::SSH.start('host', 'user', :proxy => proxy) do |ssh|
      #     ...
      #   end
      class SOCKS4

        # The SOCKS protocol version used by this class
        VERSION = 4

        # The packet type for connection requests
        CONNECT = 1

        # The status code for a successful connection
        GRANTED = 90

        # The proxy's host name or IP address, as given to the constructor.
        attr_reader :proxy_host

        # The proxy's port number.
        attr_reader :proxy_port

        # The additional options that were given to the proxy's constructor.
        attr_reader :options

        # Create a new proxy connection to the given proxy host and port.
        # Optionally, a :user key may be given to identify the username
        # with which to authenticate.
        def initialize(proxy_host, proxy_port=1080, options={})
          @proxy_host = proxy_host
          @proxy_port = proxy_port
          @options = options
        end

        # Return a new socket connected to the given host and port via the
        # proxy that was requested when the socket factory was instantiated.
        def open(host, port, connection_options)
          socket = Socket.tcp(proxy_host, proxy_port, nil, nil,
                              connect_timeout: connection_options[:timeout])
          ip_addr = IPAddr.new(Resolv.getaddress(host))
          
          packet = [VERSION, CONNECT, port.to_i, ip_addr.to_i, options[:user]].pack("CCnNZ*")
          socket.send packet, 0

          version, status, port, ip = socket.recv(8).unpack("CCnN")
          if status != GRANTED
            socket.close
            raise ConnectError, "error connecting to proxy (#{status})"
          end

          return socket
        end

      end

    end
  end
end