rex-socket 0.1.57 → 0.1.59

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3813cfab9315c8efee87b3104d1270a7f9c542cbd012b97b5155650d78f2f98b
4
- data.tar.gz: 15962d9201caa7cfb3c90a80457b0988913f35007126b15669114632842fa465
3
+ metadata.gz: e949497936b6f26c1c6da1830a2673f8708706e89598765b26ddf05179dceee0
4
+ data.tar.gz: 49e42e30d773df6f4b52539d360748fe77e51dd49bb1f1e2782a35217839eef3
5
5
  SHA512:
6
- metadata.gz: 0b0a6fb36088a4a299583325ff7ebe74363efd2587a0ed32ac8769b99ba8937a31b09042277d0349142e19b12bcbb7a16738d53b26b14a4d490261da3eeddad5
7
- data.tar.gz: 32e6b77da1e059619c9aca489c6eb7cba8116e2069f79af276646db40b0fd949b4cc82d73eee4d7198e19d5fa5e06b100d3ded0aae644dbe8d6573bf318ba836
6
+ metadata.gz: c8ea54f52f4f10c8050e181980de4caf16bc5443657c55cf0ce5ef1d20b1a5bca84448515ab502ab79c4bc3eef66b1a199ada9e095304a42c25150ee9d3062fe
7
+ data.tar.gz: aec32cadf5c60108aba67155731cf5eba9da3dba310f37fa6f6941f04a9e167762bae8953c05b5dfa7c6b096c8fdc44616b42a3f80e910a4cbc2b2e8c438308f
checksums.yaml.gz.sig CHANGED
Binary file
@@ -37,10 +37,11 @@ jobs:
37
37
  - '3.0'
38
38
  - '3.1'
39
39
  - '3.2'
40
+ - '3.3'
40
41
  os:
41
42
  - ubuntu-20.04
42
43
  - windows-2019
43
- - macos-11
44
+ - macos-13
44
45
  - ubuntu-latest
45
46
  exclude:
46
47
  - { os: ubuntu-latest, ruby: '2.7' }
@@ -9,6 +9,7 @@ require 'rex/socket/udp'
9
9
  require 'rex/socket/sctp'
10
10
  require 'rex/socket/sctp_server'
11
11
  require 'rex/socket/ip'
12
+ require 'rex/socket/proxies'
12
13
  require 'timeout'
13
14
 
14
15
  ###
@@ -353,7 +354,7 @@ class Rex::Socket::Comm::Local
353
354
 
354
355
  def self.proxy(sock, type, host, port)
355
356
  case type.downcase
356
- when 'sapni'
357
+ when Rex::Socket::Proxies::ProxyType::SAPNI
357
358
  packet_type = 'NI_ROUTE'
358
359
  route_info_version = 2
359
360
  ni_version = 39
@@ -422,7 +423,7 @@ class Rex::Socket::Comm::Local
422
423
  raise Rex::ConnectionProxyError.new(host, port, type, "Connection to #{host}:#{port} failed (Unknown fail)")
423
424
  end
424
425
 
425
- when 'http'
426
+ when Rex::Socket::Proxies::ProxyType::HTTP
426
427
  setup = "CONNECT #{host}:#{port} HTTP/1.0\r\n\r\n"
427
428
  size = sock.put(setup)
428
429
  if size != setup.length
@@ -445,7 +446,7 @@ class Rex::Socket::Comm::Local
445
446
  if resp.code != 200
446
447
  raise Rex::ConnectionProxyError.new(host, port, type, "The proxy returned a non-OK response"), caller
447
448
  end
448
- when 'socks4'
449
+ when Rex::Socket::Proxies::ProxyType::SOCKS4
449
450
  supports_ipv6 = false
450
451
  setup = [4,1,port.to_i].pack('CCn') + Rex::Socket.resolv_nbo(host, supports_ipv6) + Rex::Text.rand_text_alpha(rand(8)+1) + "\x00"
451
452
  size = sock.put(setup)
@@ -465,7 +466,7 @@ class Rex::Socket::Comm::Local
465
466
  if ret[1,1] != "\x5a"
466
467
  raise Rex::ConnectionProxyError.new(host, port, type, "Proxy responded with error code #{ret[0,1].unpack("C")[0]}"), caller
467
468
  end
468
- when 'socks5'
469
+ when Rex::Socket::Proxies::ProxyType::SOCKS5
469
470
  auth_methods = [5,1,0].pack('CCC')
470
471
  size = sock.put(auth_methods)
471
472
  if size != auth_methods.length
@@ -1,5 +1,6 @@
1
1
  # -*- coding: binary -*-
2
2
  require 'rex/socket'
3
+ require 'rex/socket/proxies'
3
4
 
4
5
  ###
5
6
  #
@@ -163,7 +164,7 @@ class Rex::Socket::Parameters
163
164
  end
164
165
 
165
166
  if hash['Proxies']
166
- self.proxies = hash['Proxies'].split(',').map{|a| a.strip}.map{|a| a.split(':').map{|b| b.strip}}
167
+ self.proxies = Rex::Socket::Proxies.parse(hash['Proxies'])
167
168
  end
168
169
 
169
170
  # The protocol this socket will be using
@@ -0,0 +1,24 @@
1
+ # -*- coding: binary -*-
2
+
3
+ module Rex
4
+ module Socket
5
+ module Proxies
6
+ module ProxyType
7
+ SAPNI = 'sapni'
8
+ HTTP = 'http'
9
+ SOCKS4 = 'socks4'
10
+ SOCKS5 = 'socks5'
11
+ end
12
+
13
+ # @param [String,nil] value A proxy chain of format {type:host:port[,type:host:port][...]}
14
+ # @return [Array] The array of proxies, i.e. {[['type', 'host', 'port']]}
15
+ def self.parse(value)
16
+ value.to_s.strip.split(',').map { |a| a.strip }.map { |a| a.split(':').map { |b| b.strip } }
17
+ end
18
+
19
+ def self.supported_types
20
+ ProxyType.constants.map { |c| ProxyType.const_get(c) }
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,5 +1,5 @@
1
1
  module Rex
2
2
  module Socket
3
- VERSION = "0.1.57"
3
+ VERSION = "0.1.59"
4
4
  end
5
5
  end
data/lib/rex/socket.rb CHANGED
@@ -4,6 +4,7 @@ require 'socket'
4
4
  require 'thread'
5
5
  require 'resolv'
6
6
  require 'rex/exceptions'
7
+ require 'dnsruby'
7
8
 
8
9
  module Rex
9
10
 
@@ -939,26 +940,30 @@ protected
939
940
  # @param resolver [Rex::Proto::DNS::CachedResolver] Resolver to query for the name
940
941
  # @return [Array] Array mimicking the native getaddrinfo return type
941
942
  def self.rex_getaddrinfo(name, resolver: @@resolver)
942
- v4, v6 = self.rex_resolve_hostname(name, resolver: resolver)
943
- # Build response array
944
- getaddrinfo = []
945
- v4.each do |a4|
946
- getaddrinfo << Addrinfo.new(
947
- self.to_sockaddr(a4.address.to_s, 0),
948
- ::Socket::AF_INET,
949
- ::Socket::SOCK_STREAM,
950
- ::Socket::IPPROTO_TCP,
951
- ) unless v4.empty?
943
+ v4_sockaddrs = []
944
+ v6_sockaddrs = []
945
+
946
+ if name =~ /\A\d+\Z/ && name.to_i.between?(0, 0xffffffff)
947
+ v4_sockaddrs << self.to_sockaddr(name.to_i, 0)
948
+ elsif name =~ /\A0x[0-9a-fA-F]+\Z/ && name.to_i(16).between?(0, 0xffffffff)
949
+ v4_sockaddrs << self.to_sockaddr(name.to_i(16), 0)
950
+ elsif self.is_ipv4?(name)
951
+ v4_sockaddrs << self.to_sockaddr(name, 0)
952
+ elsif self.is_ipv6?(name)
953
+ v6_sockaddrs << self.to_sockaddr(name, 0)
954
+ else
955
+ v4, v6 = self.rex_resolve_hostname(name, resolver: resolver)
956
+ v4.each do |a4|
957
+ v4_sockaddrs << self.to_sockaddr(a4.address.to_s, 0)
958
+ end
959
+ v6.each do |a6|
960
+ v6_sockaddrs << self.to_sockaddr(a6.address.to_s, 0)
961
+ end
952
962
  end
953
- v6.each do |a6|
954
- getaddrinfo << Addrinfo.new(
955
- self.to_sockaddr(a6.address.to_s, 0),
956
- ::Socket::AF_INET6,
957
- ::Socket::SOCK_STREAM,
958
- ::Socket::IPPROTO_TCP,
959
- ) unless v6.empty?
963
+
964
+ (v4_sockaddrs.map { |sa| [sa, ::Socket::AF_INET] } + v6_sockaddrs.map { |sa| [sa, ::Socket::AF_INET6] }).map do |sa, family|
965
+ Addrinfo.new(sa, family, ::Socket::SOCK_STREAM, ::Socket::IPPROTO_TCP)
960
966
  end
961
- return getaddrinfo
962
967
  end
963
968
 
964
969
 
@@ -974,21 +979,21 @@ protected
974
979
  ) unless name.is_a?(String)
975
980
  # Pull both record types
976
981
  v4 = begin
977
- resolver.send(name, ::Net::DNS::A).answer.select do |a|
982
+ resolver.send(name, ::Dnsruby::Types::A).answer.select do |a|
978
983
  a.type == Dnsruby::Types::A
979
984
  end.sort_by do |a|
980
985
  self.addr_ntoi(a.address.address)
981
986
  end
982
- rescue
987
+ rescue StandardError
983
988
  []
984
989
  end
985
990
  v6 = begin
986
- resolver.send(name, ::Net::DNS::AAAA).answer.select do |a|
991
+ resolver.send(name, Dnsruby::Types::AAAA).answer.select do |a|
987
992
  a.type == Dnsruby::Types::AAAA
988
993
  end.sort_by do |a|
989
994
  self.addr_ntoi(a.address.address)
990
995
  end
991
- rescue
996
+ rescue StandardError
992
997
  []
993
998
  end
994
999
  # Emulate ::Socket's error if no responses found
@@ -1012,7 +1017,7 @@ protected
1012
1017
  if attribute.nil?
1013
1018
  raise ArgumentError, "Invalid typeclass: #{typeclass}"
1014
1019
  end
1015
- const = ::Net::DNS.const_get(typeclass)
1020
+ const = Dnsruby::Types.const_get(typeclass)
1016
1021
 
1017
1022
  resources = begin
1018
1023
  resolver.send(name, const).answer.select do |a|
data/rex-socket.gemspec CHANGED
@@ -28,4 +28,5 @@ Gem::Specification.new do |spec|
28
28
  spec.add_development_dependency "rspec"
29
29
 
30
30
  spec.add_runtime_dependency "rex-core"
31
+ spec.add_runtime_dependency "dnsruby"
31
32
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rex-socket
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.57
4
+ version: 0.1.59
5
5
  platform: ruby
6
6
  authors:
7
7
  - Metasploit Hackers
@@ -34,7 +34,7 @@ cert_chain:
34
34
  DgscAao7wB3xW2BWEp1KnaDWkf1x9ttgoBEYyuYwU7uatB67kBQG1PKvLt79wHvz
35
35
  Dxs+KOjGbBRfMnPgVGYkORKVrZIwlaboHbDKxcVW5xv+oZc7KYXWGg==
36
36
  -----END CERTIFICATE-----
37
- date: 2024-03-25 00:00:00.000000000 Z
37
+ date: 2024-12-05 00:00:00.000000000 Z
38
38
  dependencies:
39
39
  - !ruby/object:Gem::Dependency
40
40
  name: rake
@@ -78,6 +78,20 @@ dependencies:
78
78
  - - ">="
79
79
  - !ruby/object:Gem::Version
80
80
  version: '0'
81
+ - !ruby/object:Gem::Dependency
82
+ name: dnsruby
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :runtime
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
81
95
  description: "The Ruby Exploitation (Rex) Socket Abstraction Library. This library\n
82
96
  \ includes all of the code needed to turn sockets into Rex::Sockets
83
97
  with the functionality\n for things like L3 pivoting used
@@ -104,6 +118,7 @@ files:
104
118
  - lib/rex/socket/comm/local.rb
105
119
  - lib/rex/socket/ip.rb
106
120
  - lib/rex/socket/parameters.rb
121
+ - lib/rex/socket/proxies.rb
107
122
  - lib/rex/socket/range_walker.rb
108
123
  - lib/rex/socket/sctp.rb
109
124
  - lib/rex/socket/sctp_server.rb
@@ -137,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
152
  - !ruby/object:Gem::Version
138
153
  version: '0'
139
154
  requirements: []
140
- rubygems_version: 3.4.10
155
+ rubygems_version: 3.5.22
141
156
  signing_key:
142
157
  specification_version: 4
143
158
  summary: The Ruby Exploitation (Rex) Socket Abstraction Library.
metadata.gz.sig CHANGED
Binary file