| | 236 | when 'socks5' |
|---|
| | 237 | # TODO: add dns lookups through socks5 |
|---|
| | 238 | auth_methods = [5,1,0].pack('CCC') |
|---|
| | 239 | size = sock.put(auth_methods) |
|---|
| | 240 | if (size != auth_methods.length) |
|---|
| | 241 | raise ArgumentError, "Wrote less data than expected to the socks proxy" |
|---|
| | 242 | end |
|---|
| | 243 | response = sock.get_once(2,30) |
|---|
| | 244 | if (0xff == response[1,1]) |
|---|
| | 245 | raise ArgumentError, "Proxy requires authentication" |
|---|
| | 246 | end |
|---|
| | 247 | |
|---|
| | 248 | setup = [5,1,0,1].pack('CCCC') + Socket.gethostbyname(host)[3] + [port.to_i].pack('n') |
|---|
| | 249 | size = sock.put(setup) |
|---|
| | 250 | if (size != setup.length) |
|---|
| | 251 | raise ArgumentError, "Wrote less data than expected to the socks proxy" |
|---|
| | 252 | end |
|---|
| | 253 | |
|---|
| | 254 | begin |
|---|
| | 255 | response = sock.get_once(10, 30) |
|---|
| | 256 | rescue IOError |
|---|
| | 257 | raise Rex::ConnectionRefused.new(host, port), caller |
|---|
| | 258 | end |
|---|
| | 259 | |
|---|
| | 260 | if (response.nil? or response.length < 8) |
|---|
| | 261 | raise ArgumentError, 'SOCKS5 server did not respond with a proper response' |
|---|
| | 262 | end |
|---|
| | 263 | if response[1] != 0 |
|---|
| | 264 | raise "SOCKS5 server responded with error code #{response[1]}" |
|---|
| | 265 | end |
|---|