rex-socket 0.1.52 → 0.1.53

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 69a97cac39e77ee44665aa30e9b9d5d30fa490c1cbb0909cfeda49bce7ca1414
4
- data.tar.gz: 3e76c09d2320265208f8a91c8bd93730d4d4698d1940b8a654d7ec553c008b6d
3
+ metadata.gz: f4e2765900a58243437c2588d16bc2c3fcd65b58f042707a1ebca28d2240786d
4
+ data.tar.gz: b7e46d8ab59b275872e48c418de39f07c615a2fdc480ad7ce0a8cf033eb5297f
5
5
  SHA512:
6
- metadata.gz: 475846de509a2f145142566a729b7fa4bf1d67d0d993c2cff20edb2bf7418c64930136d5e34f8a05a717da610c3dc734d4b631cb66611d3725a173f53a6d3001
7
- data.tar.gz: 355abe15808629534099238aad2fee65e4588573108aa4307aa6bc45b1addca4bc6422d48bb77b288945d8b33956be4503a842f74f8e14c0ecc283fcaa45ca9b
6
+ metadata.gz: 87cdca34534ff3ba9c085659200b40f71802ea51bc023e82bd918df19c3e5b70b2f9132dd954d121655d21a90e2a32bbea0fbed48543877f22ca404cac4d3ee9
7
+ data.tar.gz: 3bb326d55b4b6c3f6741df0bcf6073b329bba6934e5a5ac45cae1a6716b53301f1d8b3bebc80d40de0ed1c55a67e5c6fc37846fe5eb9524f294d373b6fc984c8
checksums.yaml.gz.sig CHANGED
Binary file
@@ -1,5 +1,5 @@
1
1
  module Rex
2
2
  module Socket
3
- VERSION = "0.1.52"
3
+ VERSION = "0.1.53"
4
4
  end
5
5
  end
data/lib/rex/socket.rb CHANGED
@@ -122,6 +122,9 @@ module Socket
122
122
  end
123
123
 
124
124
  #
125
+ # Cache our resolver
126
+ @@resolver = nil
127
+
125
128
  # Determine whether this is an IPv4 address
126
129
  #
127
130
  def self.is_ipv4?(addr)
@@ -216,7 +219,11 @@ module Socket
216
219
  return [hostname]
217
220
  end
218
221
 
219
- res = ::Addrinfo.getaddrinfo(hostname, 0, ::Socket::AF_UNSPEC, ::Socket::SOCK_STREAM)
222
+ if @@resolver
223
+ res = self.rex_getaddrinfo(hostname)
224
+ else
225
+ res = ::Addrinfo.getaddrinfo(hostname, 0, ::Socket::AF_UNSPEC, ::Socket::SOCK_STREAM)
226
+ end
220
227
 
221
228
  res.map! do |address_info|
222
229
  address_info.ip_address
@@ -248,7 +255,7 @@ module Socket
248
255
  host, _ = host.split('%', 2)
249
256
  end
250
257
 
251
- ::Socket.gethostbyname(host)
258
+ @@resolver ? self.rex_gethostbyname(host) : ::Socket.gethostbyname(host)
252
259
  end
253
260
 
254
261
  #
@@ -719,6 +726,15 @@ module Socket
719
726
  return [lsock, rsock]
720
727
  end
721
728
 
729
+ #
730
+ # Install Rex::Proto::DNS::CachedResolver, or similar, to pivot DNS
731
+ #
732
+ # @param res [Rex::Proto::DNS::CachedResolver] Resolver object to handle DNS requests
733
+ # @return [Rex::Proto::DNS::CachedResolver] The installed resolver
734
+ def self._install_global_resolver(res)
735
+ @@resolver = res
736
+ end
737
+
722
738
 
723
739
  ##
724
740
  #
@@ -844,6 +860,89 @@ protected
844
860
  attr_writer :context # :nodoc:
845
861
  attr_writer :ipv # :nodoc:
846
862
 
863
+ #
864
+ # @param name [String] The hostname to lookup via the resolver
865
+ # @param resolver [Rex::Proto::DNS::CachedResolver] Resolver to query for the name
866
+ # @return [Array] Array mimicking the native gethostbyname return type
867
+ def self.rex_gethostbyname(name, resolver: @@resolver)
868
+ v4, v6 = self.rex_resolve_hostname(name, resolver: resolver)
869
+ # Build response array
870
+ hostbyname = [name, []]
871
+ unless v4.empty?
872
+ hostbyname << ::Socket::AF_INET
873
+ hostbyname += v4.map(&:address).map(&:address)
874
+ hostbyname << v6[0].address.address unless v6.empty?
875
+ else
876
+ hostbyname << ::Socket::AF_INET6
877
+ hostbyname += v6.map(&:address).map(&:address)
878
+ end
879
+ return hostbyname
880
+ end
881
+
882
+ #
883
+ # @param name [String] The hostname to lookup via the resolver
884
+ # @param resolver [Rex::Proto::DNS::CachedResolver] Resolver to query for the name
885
+ # @return [Array] Array mimicking the native getaddrinfo return type
886
+ def self.rex_getaddrinfo(name, resolver: @@resolver)
887
+ v4, v6 = self.rex_resolve_hostname(name, resolver: resolver)
888
+ # Build response array
889
+ getaddrinfo = []
890
+ v4.each do |a4|
891
+ getaddrinfo << Addrinfo.new(
892
+ self.to_sockaddr(a4.address.to_s, 0),
893
+ ::Socket::AF_INET,
894
+ ::Socket::SOCK_STREAM,
895
+ ::Socket::IPPROTO_TCP,
896
+ ) unless v4.empty?
897
+ end
898
+ v6.each do |a6|
899
+ getaddrinfo << Addrinfo.new(
900
+ self.to_sockaddr(a6.address.to_s, 0),
901
+ ::Socket::AF_INET6,
902
+ ::Socket::SOCK_STREAM,
903
+ ::Socket::IPPROTO_TCP,
904
+ ) unless v6.empty?
905
+ end
906
+ return getaddrinfo
907
+ end
908
+
909
+
910
+ # @param name [String] The hostname to lookup via the resolver
911
+ # @param resolver [Rex::Proto::DNS::CachedResolver] Resolver to query for the name
912
+ # @return [Array] Array of Dnsruby::Message responses for consumers to reformat
913
+ def self.rex_resolve_hostname(name, resolver: @@resolver)
914
+ raise ::SocketError.new(
915
+ "Rex::Socket internal DNS resolution requires passing/setting a resolver"
916
+ ) unless resolver
917
+ raise ::SocketError.new(
918
+ "Rex::Socket internal DNS resolution requires passing a String name to resolve"
919
+ ) unless name.is_a?(String)
920
+ # Pull both record types
921
+ v4 = begin
922
+ resolver.send(name, ::Net::DNS::A).answer.select do |a|
923
+ a.type == Dnsruby::Types::A
924
+ end.sort_by do |a|
925
+ self.addr_ntoi(a.address.address)
926
+ end
927
+ rescue
928
+ []
929
+ end
930
+ v6 = begin
931
+ resolver.send(name, ::Net::DNS::AAAA).answer.select do |a|
932
+ a.type == Dnsruby::Types::AAAA
933
+ end.sort_by do |a|
934
+ self.addr_ntoi(a.address.address)
935
+ end
936
+ rescue
937
+ []
938
+ end
939
+ # Emulate ::Socket's error if no responses found
940
+ if v4.empty? and v6.empty?
941
+ raise ::SocketError.new('getaddrinfo: Name or service not known')
942
+ end
943
+ # Ensure response types (depending on underlying library used) provide required methods
944
+ return v4, v6
945
+ end
847
946
  end
848
947
 
849
948
  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.52
4
+ version: 0.1.53
5
5
  platform: ruby
6
6
  authors:
7
7
  - Metasploit Hackers
@@ -93,7 +93,7 @@ cert_chain:
93
93
  EknWpNgVhohbot1lfVAMmIhdtOVaRVcQQixWPwprDj/ydB8ryDMDosIMcw+fkoXU
94
94
  9GJsSaSRRYQ9UUkVL27b64okU8D48m8=
95
95
  -----END CERTIFICATE-----
96
- date: 2023-06-09 00:00:00.000000000 Z
96
+ date: 2023-09-05 00:00:00.000000000 Z
97
97
  dependencies:
98
98
  - !ruby/object:Gem::Dependency
99
99
  name: rake
metadata.gz.sig CHANGED
Binary file