rex-socket 0.1.52 → 0.1.54

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: 0d6178ec17a488e30e67e5f38c47a37ef101779a01819acc9fe5f0e77e21137a
4
+ data.tar.gz: 850e34b302ac851ef01ed341fdb361e60c6256a3be7ebec6f52398046884b041
5
5
  SHA512:
6
- metadata.gz: 475846de509a2f145142566a729b7fa4bf1d67d0d993c2cff20edb2bf7418c64930136d5e34f8a05a717da610c3dc734d4b631cb66611d3725a173f53a6d3001
7
- data.tar.gz: 355abe15808629534099238aad2fee65e4588573108aa4307aa6bc45b1addca4bc6422d48bb77b288945d8b33956be4503a842f74f8e14c0ecc283fcaa45ca9b
6
+ metadata.gz: 0e6be5fbc26e756be673e373c521ddac5b1b98a999ee5c78d9d9d009a68d9de1d5a40f2915ebb226a0349c4dd097d76779c2181396be31756f2a95c77f0fabff
7
+ data.tar.gz: 9bcd47ba675dd95f6eb4d5164e94ed5c82d1ac0f36513a20b2c77a37089f6a3cbe0705027ad363e153a700e45e9493b449e6659dc73e6256d20e83188e15c089
checksums.yaml.gz.sig CHANGED
Binary file
@@ -30,7 +30,7 @@ jobs:
30
30
  timeout-minutes: 40
31
31
 
32
32
  strategy:
33
- fail-fast: true
33
+ fail-fast: false
34
34
  matrix:
35
35
  ruby:
36
36
  - '2.7'
@@ -39,20 +39,20 @@ jobs:
39
39
  - '3.2'
40
40
  os:
41
41
  - ubuntu-20.04
42
+ - windows-2019
43
+ - macos-11
42
44
  - ubuntu-latest
43
45
  exclude:
44
46
  - { os: ubuntu-latest, ruby: '2.7' }
45
47
  - { os: ubuntu-latest, ruby: '3.0' }
46
- test_cmd:
47
- - bundle exec rspec
48
48
 
49
49
  env:
50
50
  RAILS_ENV: test
51
51
 
52
- name: ${{ matrix.os }} - Ruby ${{ matrix.ruby }} - ${{ matrix.test_cmd }}
52
+ name: ${{ matrix.os }} - Ruby ${{ matrix.ruby }}
53
53
  steps:
54
54
  - name: Checkout code
55
- uses: actions/checkout@v2
55
+ uses: actions/checkout@v4
56
56
 
57
57
  - name: Setup Ruby
58
58
  uses: ruby/setup-ruby@v1
@@ -60,9 +60,6 @@ jobs:
60
60
  ruby-version: ${{ matrix.ruby }}
61
61
  bundler-cache: true
62
62
 
63
- - name: ${{ matrix.test_cmd }}
63
+ - name: rspec
64
64
  run: |
65
- echo "${CMD}"
66
- bash -c "${CMD}"
67
- env:
68
- CMD: ${{ matrix.test_cmd }}
65
+ bundle exec rspec
@@ -1,5 +1,5 @@
1
1
  module Rex
2
2
  module Socket
3
- VERSION = "0.1.52"
3
+ VERSION = "0.1.54"
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
  #
@@ -665,37 +672,57 @@ module Socket
665
672
  # is no concurrent use of the same locals and this is safe.
666
673
  def self.tcp_socket_pair
667
674
  lsock = nil
675
+ last_child_error = nil
676
+ accept_timeout = 10
668
677
  rsock = nil
669
678
  laddr = '127.0.0.1'
670
679
  lport = 0
671
680
  threads = []
672
681
  mutex = ::Mutex.new
673
682
 
674
- threads << Rex::ThreadFactory.spawn('TcpSocketPair', false) {
683
+ threads << Rex::ThreadFactory.spawn('TcpSocketPair', false) do
675
684
  server = nil
676
- mutex.synchronize {
677
- threads << Rex::ThreadFactory.spawn('TcpSocketPairClient', false) {
678
- mutex.synchronize {
679
- rsock = ::TCPSocket.new( laddr, lport )
680
- }
681
- }
682
- server = ::TCPServer.new(laddr, 0)
683
- if (server.getsockname =~ /127\.0\.0\.1:/)
684
- # JRuby ridiculousness
685
- caddr, lport = server.getsockname.split(":")
686
- caddr = caddr[1,caddr.length]
687
- lport = lport.to_i
685
+ begin
686
+ mutex.synchronize do
687
+ threads << Rex::ThreadFactory.spawn('TcpSocketPairClient', false) do
688
+ mutex.synchronize do
689
+ begin
690
+ rsock = ::TCPSocket.new( laddr, lport )
691
+ rescue => e
692
+ last_child_error = "#{e.class} - #{e.message}"
693
+ raise
694
+ end
695
+ end
696
+ end
697
+ server = ::TCPServer.new(laddr, 0)
698
+ if (server.getsockname =~ /127\.0\.0\.1:/)
699
+ # JRuby ridiculousness
700
+ caddr, lport = server.getsockname.split(":")
701
+ caddr = caddr[1,caddr.length]
702
+ lport = lport.to_i
703
+ else
704
+ # Sane implementations where Socket#getsockname returns a
705
+ # sockaddr
706
+ lport, caddr = ::Socket.unpack_sockaddr_in( server.getsockname )
707
+ end
708
+ end
709
+
710
+ readable, _writable, _errors = ::IO.select([server], nil, nil, accept_timeout)
711
+ if readable && readable.any?
712
+ lsock, _ = server.accept_nonblock
688
713
  else
689
- # Sane implementations where Socket#getsockname returns a
690
- # sockaddr
691
- lport, caddr = ::Socket.unpack_sockaddr_in( server.getsockname )
714
+ raise RuntimeError, "rsock didn't connect in #{accept_timeout} seconds"
692
715
  end
693
- }
694
- lsock, _ = server.accept
695
- server.close
696
- }
716
+ ensure
717
+ server.close if server
718
+ end
719
+ end
697
720
 
698
- threads.each { |t| t.join }
721
+ threads.each.with_index do |thread, i|
722
+ thread.join
723
+ rescue => e
724
+ raise "Thread #{i} - error #{e} - last child error: #{last_child_error}"
725
+ end
699
726
 
700
727
  return [lsock, rsock]
701
728
  end
@@ -719,6 +746,15 @@ module Socket
719
746
  return [lsock, rsock]
720
747
  end
721
748
 
749
+ #
750
+ # Install Rex::Proto::DNS::CachedResolver, or similar, to pivot DNS
751
+ #
752
+ # @param res [Rex::Proto::DNS::CachedResolver] Resolver object to handle DNS requests
753
+ # @return [Rex::Proto::DNS::CachedResolver] The installed resolver
754
+ def self._install_global_resolver(res)
755
+ @@resolver = res
756
+ end
757
+
722
758
 
723
759
  ##
724
760
  #
@@ -844,6 +880,89 @@ protected
844
880
  attr_writer :context # :nodoc:
845
881
  attr_writer :ipv # :nodoc:
846
882
 
883
+ #
884
+ # @param name [String] The hostname to lookup via the resolver
885
+ # @param resolver [Rex::Proto::DNS::CachedResolver] Resolver to query for the name
886
+ # @return [Array] Array mimicking the native gethostbyname return type
887
+ def self.rex_gethostbyname(name, resolver: @@resolver)
888
+ v4, v6 = self.rex_resolve_hostname(name, resolver: resolver)
889
+ # Build response array
890
+ hostbyname = [name, []]
891
+ unless v4.empty?
892
+ hostbyname << ::Socket::AF_INET
893
+ hostbyname += v4.map(&:address).map(&:address)
894
+ hostbyname << v6[0].address.address unless v6.empty?
895
+ else
896
+ hostbyname << ::Socket::AF_INET6
897
+ hostbyname += v6.map(&:address).map(&:address)
898
+ end
899
+ return hostbyname
900
+ end
901
+
902
+ #
903
+ # @param name [String] The hostname to lookup via the resolver
904
+ # @param resolver [Rex::Proto::DNS::CachedResolver] Resolver to query for the name
905
+ # @return [Array] Array mimicking the native getaddrinfo return type
906
+ def self.rex_getaddrinfo(name, resolver: @@resolver)
907
+ v4, v6 = self.rex_resolve_hostname(name, resolver: resolver)
908
+ # Build response array
909
+ getaddrinfo = []
910
+ v4.each do |a4|
911
+ getaddrinfo << Addrinfo.new(
912
+ self.to_sockaddr(a4.address.to_s, 0),
913
+ ::Socket::AF_INET,
914
+ ::Socket::SOCK_STREAM,
915
+ ::Socket::IPPROTO_TCP,
916
+ ) unless v4.empty?
917
+ end
918
+ v6.each do |a6|
919
+ getaddrinfo << Addrinfo.new(
920
+ self.to_sockaddr(a6.address.to_s, 0),
921
+ ::Socket::AF_INET6,
922
+ ::Socket::SOCK_STREAM,
923
+ ::Socket::IPPROTO_TCP,
924
+ ) unless v6.empty?
925
+ end
926
+ return getaddrinfo
927
+ end
928
+
929
+
930
+ # @param name [String] The hostname to lookup via the resolver
931
+ # @param resolver [Rex::Proto::DNS::CachedResolver] Resolver to query for the name
932
+ # @return [Array] Array of Dnsruby::Message responses for consumers to reformat
933
+ def self.rex_resolve_hostname(name, resolver: @@resolver)
934
+ raise ::SocketError.new(
935
+ "Rex::Socket internal DNS resolution requires passing/setting a resolver"
936
+ ) unless resolver
937
+ raise ::SocketError.new(
938
+ "Rex::Socket internal DNS resolution requires passing a String name to resolve"
939
+ ) unless name.is_a?(String)
940
+ # Pull both record types
941
+ v4 = begin
942
+ resolver.send(name, ::Net::DNS::A).answer.select do |a|
943
+ a.type == Dnsruby::Types::A
944
+ end.sort_by do |a|
945
+ self.addr_ntoi(a.address.address)
946
+ end
947
+ rescue
948
+ []
949
+ end
950
+ v6 = begin
951
+ resolver.send(name, ::Net::DNS::AAAA).answer.select do |a|
952
+ a.type == Dnsruby::Types::AAAA
953
+ end.sort_by do |a|
954
+ self.addr_ntoi(a.address.address)
955
+ end
956
+ rescue
957
+ []
958
+ end
959
+ # Emulate ::Socket's error if no responses found
960
+ if v4.empty? and v6.empty?
961
+ raise ::SocketError.new('getaddrinfo: Name or service not known')
962
+ end
963
+ # Ensure response types (depending on underlying library used) provide required methods
964
+ return v4, v6
965
+ end
847
966
  end
848
967
 
849
968
  end
data.tar.gz.sig CHANGED
@@ -1 +1,3 @@
1
- +�Sl��N���ϱ`. e�� ,Smt�mB��bvh����WQ�%�׆�����(y\�ԯ.��OW=�q���� �O刣�9�#�;���a%;(�����E!���dҨmZ��$�jI;0�� �G��|Z�$ID4��4|��s�|0�U�\5C�2  �����u�.���z���8��Q���Eڵ�_c1pjq�,%Z��vLI���ý�N�&�����DI�������ӓ(!-���W�E��'�-�
1
+ |
2
+ �$�I(��p�x�Z��}����=;;�7���6pdN؊���m��sJ���3���!Aʊ!�Lo
3
+ ��U#&ܮ��} �a<M�5)1]#��G����M��>�ʹA��2v(�j��^��κ�����C��H)ު������l�`Vy�� �u�������"fӉwFQ�Yߒ�F�z��̆�T�|�9���`�H̒��(��Jע
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.54
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-13 00:00:00.000000000 Z
97
97
  dependencies:
98
98
  - !ruby/object:Gem::Dependency
99
99
  name: rake
metadata.gz.sig CHANGED
Binary file