librex 0.0.30 → 0.0.31

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/README.markdown +1 -1
  2. data/lib/rex.rb +40 -33
  3. data/lib/rex/arch.rb +2 -3
  4. data/lib/rex/encoder.rb +17 -0
  5. data/lib/rex/encoder/alpha2.rb +11 -9
  6. data/lib/rex/encoder/xor.rb +5 -2
  7. data/lib/rex/encoders.rb +11 -0
  8. data/lib/rex/encoding.rb +10 -0
  9. data/lib/rex/encoding/xor.rb +14 -15
  10. data/lib/rex/exploitation/egghunter.rb +1 -0
  11. data/lib/rex/exploitation/egghunter.rb.ut.rb +7 -5
  12. data/lib/rex/exploitation/javascriptosdetect.rb +0 -1
  13. data/lib/rex/exploitation/omelet.rb +2 -2
  14. data/lib/rex/exploitation/omelet.rb.ut.rb +26 -13
  15. data/lib/rex/io.rb +16 -0
  16. data/lib/rex/io/stream.rb +4 -12
  17. data/lib/rex/io/stream_abstraction.rb +7 -5
  18. data/lib/rex/logging.rb +15 -2
  19. data/lib/rex/logging/log_dispatcher.rb +0 -1
  20. data/lib/rex/logging/log_sink.rb +0 -3
  21. data/lib/rex/logging/sinks.rb +16 -0
  22. data/lib/rex/logging/sinks/flatfile.rb +2 -0
  23. data/lib/rex/parser.rb +23 -0
  24. data/lib/rex/payloads.rb +3 -1
  25. data/lib/rex/payloads/win32.rb +4 -2
  26. data/lib/rex/payloads/win32/kernel.rb +5 -6
  27. data/lib/rex/peparsey.rb +5 -6
  28. data/lib/rex/pescan.rb +6 -7
  29. data/lib/rex/platforms.rb +11 -1
  30. data/lib/rex/post/meterpreter/extensions/stdapi/railgun/api_constants.rb.ut.rb +1 -1
  31. data/lib/rex/proto.rb +17 -6
  32. data/lib/rex/proto/dcerpc.rb +15 -6
  33. data/lib/rex/proto/drda.rb +9 -4
  34. data/lib/rex/proto/http.rb +15 -2
  35. data/lib/rex/proto/http/packet.rb +1 -0
  36. data/lib/rex/proto/ntlm.rb +12 -6
  37. data/lib/rex/proto/ntlm.rb.ut.rb +3 -0
  38. data/lib/rex/proto/ntlm/message.rb +2 -0
  39. data/lib/rex/proto/rfb.rb.ut.rb +2 -0
  40. data/lib/rex/proto/smb.rb +15 -7
  41. data/lib/rex/service_manager.rb +0 -1
  42. data/lib/rex/socket.rb +17 -13
  43. data/lib/rex/socket/comm.rb +2 -0
  44. data/lib/rex/socket/comm/local.rb +2 -6
  45. data/lib/rex/socket/ssl_tcp.rb +38 -14
  46. data/lib/rex/socket/switch_board.rb +5 -1
  47. data/lib/rex/socket/tcp_server.rb.ut.rb +3 -3
  48. data/lib/rex/sync.rb +6 -6
  49. data/lib/rex/ui.rb +13 -13
  50. data/lib/rex/ui/text.rb +17 -0
  51. data/lib/rex/ui/text/input.rb +4 -4
  52. data/lib/rex/ui/text/input/buffer.rb +6 -3
  53. data/lib/rex/ui/text/output.rb +4 -5
  54. metadata +10 -3
@@ -3,7 +3,7 @@
3
3
  A non-official re-packaging of the Rex library as a gem for easy of usage of the Metasploit REX framework in a non Metasploit application. I received permission from HDM to create this package.
4
4
 
5
5
  Currently based on:
6
- SVN Revision: 12516
6
+ SVN Revision: 12559
7
7
 
8
8
  # Credits
9
9
  The Metasploit development team <http://www.metasploit.com>
data/lib/rex.rb CHANGED
@@ -40,53 +40,60 @@ end
40
40
  # Generic classes
41
41
  require 'rex/constants'
42
42
  require 'rex/exceptions'
43
- require 'rex/transformer'
44
- require 'rex/text'
45
- require 'rex/time'
46
- require 'rex/job_container'
47
- require 'rex/file'
48
43
 
49
- # Thread safety and synchronization
50
- require 'rex/sync'
44
+ module Rex
45
+ # Generic modules
46
+ autoload :File, 'rex/file'
47
+ autoload :Text, 'rex/text'
48
+ autoload :Job, 'rex/job_container'
49
+ autoload :JobContainer, 'rex/job_container'
50
+ autoload :Transformer, 'rex/transformer'
51
+ autoload :ExtTime, 'rex/time'
51
52
 
52
- # Thread factory
53
- require 'rex/thread_factory'
53
+ # Thread safety and synchronization
54
+ autoload :ReadWriteLock, 'rex/sync/read_write_lock'
55
+ autoload :ThreadSafe, 'rex/sync/thread_safe'
56
+ autoload :Ref, 'rex/sync/ref'
57
+ autoload :Sync, 'rex/sync/event'
54
58
 
55
- # Encoding
56
- require 'rex/encoder/xor'
57
- require 'rex/encoding/xor'
59
+ # Thread factory
60
+ autoload :ThreadFactory, 'rex/thread_factory'
58
61
 
59
- # Architecture subsystem
60
- require 'rex/arch'
62
+ # Encoding
63
+ autoload :Encoder, 'rex/encoder'
64
+ autoload :Encoders, 'rex/encoders'
65
+ autoload :Encoding, 'rex/encoding'
61
66
 
62
- # Assembly
63
- require 'rex/assembly/nasm'
67
+ # Architecture subsystem
68
+ autoload :Arch, 'rex/arch'
64
69
 
65
- # Logging
66
- require 'rex/logging/log_dispatcher'
70
+ # Assembly
71
+ autoload :Assembly, 'rex/assembly/nasm'
67
72
 
68
- # IO
69
- require 'rex/io/stream'
70
- require 'rex/io/stream_abstraction'
71
- require 'rex/io/stream_server'
73
+ # Logging
74
+ autoload :Logging, 'rex/logging'
72
75
 
73
- # Sockets
74
- require 'rex/socket'
76
+ # IO
77
+ autoload :IO, 'rex/io'
75
78
 
76
- # Protocols
79
+ # Sockets
80
+ autoload :Socket, 'rex/socket'
77
81
 
78
- require 'rex/proto'
82
+ # Platforms
83
+ autoload :Platforms, 'rex/platforms'
79
84
 
80
- # Parsers
81
- require 'rex/parser/arguments'
82
- require 'rex/parser/ini'
85
+ # Protocols
86
+ autoload :Proto, 'rex/proto'
83
87
 
88
+ # Service handling
89
+ autoload :Service, 'rex/service'
84
90
 
85
- # Compatibility
86
- require 'rex/compat'
91
+ # Parsers
92
+ autoload :Parser, 'rex/parser'
87
93
 
88
- # Platforms
89
- require 'rex/platforms'
94
+ # Compatibility
95
+ autoload :Compat, 'rex/compat'
96
+ end
90
97
 
91
98
 
92
99
  # Overload the Kernel.sleep() function to be thread-safe
@@ -2,7 +2,6 @@ require 'rex/constants'
2
2
 
3
3
  module Rex
4
4
 
5
-
6
5
  ###
7
6
  #
8
7
  # This module provides generalized methods for performing operations that are
@@ -15,8 +14,8 @@ module Arch
15
14
  #
16
15
  # Architecture classes
17
16
  #
18
- require 'rex/arch/x86'
19
- require 'rex/arch/sparc'
17
+ autoload :X86, 'rex/arch/x86'
18
+ autoload :Sparc, 'rex/arch/sparc'
20
19
 
21
20
  #
22
21
  # This routine adjusts the stack pointer for a given architecture.
@@ -0,0 +1,17 @@
1
+ ##
2
+ # $Id: encoder.rb 12554 2011-05-06 18:47:10Z jduck $
3
+ #
4
+ # This file maps encoders for autoload
5
+ ##
6
+
7
+ module Rex::Encoder
8
+ # Encoder support code
9
+ autoload :Xor, 'rex/encoder/xor'
10
+ autoload :Alpha2, 'rex/encoder/alpha2'
11
+ autoload :NonAlpha, 'rex/encoder/nonalpha'
12
+ autoload :NonUpper, 'rex/encoder/nonupper'
13
+
14
+ # Hrm? Is these in the wrong module?
15
+ autoload :XDR, 'rex/encoder/xdr'
16
+ autoload :NDR, 'rex/encoder/ndr'
17
+ end
@@ -18,14 +18,16 @@
18
18
  module Rex
19
19
  module Encoder
20
20
  module Alpha2
21
- end end end
22
21
 
23
- #
24
- # include the Alpha2 encodings
25
- #
22
+ #
23
+ # autoload the Alpha2 encoders
24
+ #
25
+ autoload :Generic, 'rex/encoder/alpha2/generic'
26
+ autoload :AlphaMixed, 'rex/encoder/alpha2/alpha_mixed'
27
+ autoload :AlphaUpper, 'rex/encoder/alpha2/alpha_upper'
28
+ autoload :UnicodeMixed, 'rex/encoder/alpha2/unicode_mixed'
29
+ autoload :UnicodeUpper, 'rex/encoder/alpha2/unicode_upper'
26
30
 
27
- require 'rex/encoder/alpha2/generic'
28
- require 'rex/encoder/alpha2/alpha_mixed'
29
- require 'rex/encoder/alpha2/alpha_upper'
30
- require 'rex/encoder/alpha2/unicode_mixed'
31
- require 'rex/encoder/alpha2/unicode_upper'
31
+ end
32
+ end
33
+ end
@@ -10,6 +10,9 @@ module Encoder
10
10
  ###
11
11
  class Xor
12
12
 
13
+ autoload :Dword, 'rex/encoder/xor/dword'
14
+ autoload :DwordAdditive, 'rex/encoder/xor/dword_additive'
15
+
13
16
  attr_accessor :raw, :encoded, :badchars, :opts, :key, :fkey # :nodoc:
14
17
 
15
18
  #
@@ -65,5 +68,5 @@ class Xor
65
68
 
66
69
  end
67
70
 
68
- end end
69
-
71
+ end
72
+ end
@@ -0,0 +1,11 @@
1
+ ##
2
+ # $Id: encoders.rb 12554 2011-05-06 18:47:10Z jduck $
3
+ #
4
+ # This file maps encoders for autoload
5
+ ##
6
+ require 'rex'
7
+
8
+ module Rex::Encoders
9
+ autoload :XorDword, 'rex/encoders/xor_dword'
10
+ autoload :XorDwordAdditive, 'rex/encoders/xor_dword_additive'
11
+ end
@@ -0,0 +1,10 @@
1
+ ##
2
+ # $Id: encoding.rb 12554 2011-05-06 18:47:10Z jduck $
3
+ #
4
+ # This file maps encodings for autoload
5
+ ##
6
+
7
+ module Rex::Encoding
8
+ # Encoding support code
9
+ autoload :Xor, 'rex/encoding/xor'
10
+ end
@@ -1,20 +1,19 @@
1
- #!/usr/bin/env ruby
2
-
3
- #
4
- # make sure the namespace is created
5
- #
6
-
7
1
  module Rex
8
2
  module Encoding
9
3
  module Xor
10
- end end end
11
4
 
12
- #
13
- # include the Xor encodings
14
- #
5
+ #
6
+ # autoload the Xor encodings
7
+ #
8
+ autoload :Generic, 'rex/encoding/xor/generic'
9
+ autoload :Byte, 'rex/encoding/xor/byte'
10
+ autoload :Word, 'rex/encoding/xor/word'
11
+ autoload :Dword, 'rex/encoding/xor/dword'
12
+ autoload :DwordAdditive, 'rex/encoding/xor/dword_additive'
13
+ autoload :Qword, 'rex/encoding/xor/qword'
14
+
15
+ autoload :Exception, 'rex/encoding/xor/exceptions'
15
16
 
16
- require 'rex/encoding/xor/generic'
17
- require 'rex/encoding/xor/byte'
18
- require 'rex/encoding/xor/word'
19
- require 'rex/encoding/xor/dword'
20
- require 'rex/encoding/xor/qword'
17
+ end
18
+ end
19
+ end
@@ -1,5 +1,6 @@
1
1
  require 'rex/text'
2
2
  require 'rex/arch'
3
+ require 'metasm'
3
4
 
4
5
  module Rex
5
6
  module Exploitation
@@ -10,16 +10,18 @@ class Rex::Exploitation::Egghunter::UnitTest < Test::Unit::TestCase
10
10
  Klass = Rex::Exploitation::Egghunter
11
11
 
12
12
  def test_egghunter
13
+ payload = "\xcc" * 1023
14
+
13
15
  r = Klass.new('bogus')
14
- assert_nil(r.generate)
16
+ assert_nil(r.generate(payload))
15
17
 
16
18
  r = Klass.new('win')
17
- assert_nil(r.generate)
19
+ assert_nil(r.generate(payload))
18
20
 
19
21
  r = Klass.new('win', ARCH_X86)
20
- assert_not_nil(r.generate)
21
- assert_not_nil(r.generate[0])
22
- assert_not_nil(r.generate[1])
22
+ assert_not_nil(r.generate(payload))
23
+ assert_not_nil(r.generate(payload)[0])
24
+ assert_not_nil(r.generate(payload)[1])
23
25
  end
24
26
 
25
27
  end
@@ -1,7 +1,6 @@
1
1
 
2
2
  require 'rex/text'
3
3
  require 'rex/exploitation/obfuscatejs'
4
- require 'msf/core/auxiliary'
5
4
 
6
5
  module Rex
7
6
  module Exploitation
@@ -104,8 +104,8 @@ class Omelet
104
104
  eggsize_hex = "%02x" % eggsize
105
105
 
106
106
  hextag = ''
107
- eggtag.split('').each do | thischar |
108
- decchar = "%02x" % thischar[0]
107
+ eggtag.each_byte do |thischar|
108
+ decchar = "%02x" % thischar
109
109
  hextag = decchar + hextag
110
110
  end
111
111
  hextag = hextag + "01"
@@ -1,13 +1,26 @@
1
- # $Id$
2
-
3
- require 'omelet.rb'
4
-
5
- x = Rex::Exploitation::Omelet.new('win', ARCH_X86)
6
- x.generate("\xcc" * 1024, '', {
7
- #:eggsize => 31336, # default: 123
8
- #:eggtag => "b00", # default: 00w
9
- #:searchforward => false, # default: true
10
- #:reset => true, # default: false
11
- #:startreg => "EBP", # default: none
12
- :checksum => true # default: false
13
- })
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File.join(File.dirname(__FILE__), '..', '..'))
4
+
5
+ require 'test/unit'
6
+ require 'rex/exploitation/omelet'
7
+
8
+ class Rex::Exploitation::Omelet::UnitTest < Test::Unit::TestCase
9
+
10
+ Klass = Rex::Exploitation::Omelet
11
+
12
+ def test_generate
13
+ x = Klass.new('win', ARCH_X86)
14
+
15
+ om = x.generate("\xcc" * 1024, '', {
16
+ #:eggsize => 31336, # default: 123
17
+ #:eggtag => "b00", # default: 00w
18
+ #:searchforward => false, # default: true
19
+ #:reset => true, # default: false
20
+ #:startreg => "EBP", # default: none
21
+ :checksum => true # default: false
22
+ })
23
+ # XXX: TODO: assertions!
24
+ end
25
+
26
+ end
@@ -0,0 +1,16 @@
1
+ ##
2
+ # $Id: io.rb 12554 2011-05-06 18:47:10Z jduck $
3
+ #
4
+ # This file simply provides an autoload interface for the children
5
+ # of Rex::IO
6
+ #
7
+ ##
8
+ module Rex::IO
9
+ autoload :Stream, 'rex/io/stream'
10
+ autoload :StreamAbstraction, 'rex/io/stream_abstraction'
11
+ autoload :StreamServer, 'rex/io/stream_server'
12
+
13
+ autoload :BidirectionalPipe, 'rex/io/bidirectional_pipe'
14
+ autoload :DatagramAbstraction, 'rex/io/datagram_abstraction'
15
+ autoload :RingBuffer, 'rex/io/ring_buffer'
16
+ end
@@ -56,7 +56,7 @@ module Stream
56
56
  # Try to write the data again
57
57
  retry
58
58
  rescue ::IOError, ::Errno::EPIPE
59
- return nil if (fd.abortive_close == true)
59
+ return nil
60
60
  end
61
61
 
62
62
  total_sent
@@ -75,7 +75,7 @@ module Stream
75
75
  # Decrement the block size to handle full sendQs better
76
76
  retry
77
77
  rescue ::IOError, ::Errno::EPIPE
78
- return nil if (fd.abortive_close == true)
78
+ return nil
79
79
  end
80
80
  end
81
81
 
@@ -101,11 +101,8 @@ module Stream
101
101
  rescue ::Errno::EBADF, ::Errno::ENOTSOCK
102
102
  raise ::EOFError
103
103
  rescue StreamClosedError, ::IOError, ::EOFError, ::Errno::EPIPE
104
- # If the thing that lead to the closure was an abortive close, then
105
- # don't raise the stream closed error.
106
- return false if (fd.abortive_close == true)
107
-
108
- raise $!
104
+ # Return false if the socket is dead
105
+ return false
109
106
  end
110
107
  end
111
108
 
@@ -310,11 +307,6 @@ module Stream
310
307
  16384
311
308
  end
312
309
 
313
- #
314
- # This flag indicates whether or not an abortive close has been issued.
315
- #
316
- attr_accessor :abortive_close
317
-
318
310
  protected
319
311
 
320
312
  end
@@ -148,10 +148,9 @@ protected
148
148
  closed = true
149
149
  wlog("monitor_rsock: closed remote socket due to nil read")
150
150
  end
151
-
152
151
  rescue ::Exception
153
152
  closed = true
154
- wlog("monitor_rsock: exception during read: #{e.class} #{e}")
153
+ wlog("monitor_rsock: exception during read: #{e.class} #{e}")
155
154
  end
156
155
  end
157
156
 
@@ -165,15 +164,18 @@ protected
165
164
  # Note that this must be write() NOT syswrite() or put() or anything like it.
166
165
  # Using syswrite() breaks SSL streams.
167
166
  sent = self.write( data )
168
-
167
+
169
168
  # sf: Only remove the data off the queue is write was successfull.
170
169
  # This way we naturally perform a resend if a failure occured.
171
170
  # Catches an edge case with meterpreter TCP channels where remote send
172
171
  # failes gracefully and a resend is required.
173
- if( sent > 0 )
172
+ if (sent.nil? or sent <= 0)
173
+ wlog("monitor_rsock: failed writing, socket must be dead")
174
+ break
175
+ else
174
176
  total_sent += sent
175
177
  end
176
- rescue ::IOError => e
178
+ rescue ::IOError, ::EOFError => e
177
179
  closed = true
178
180
  wlog("monitor_rsock: exception during write: #{e.class} #{e}")
179
181
  break
@@ -1,4 +1,17 @@
1
- #!/usr/bin/env ruby
1
+ ##
2
+ # $Id: $
3
+ #
4
+ # maps autoload for logging classes
5
+ ##
2
6
 
3
7
  require 'rex/constants' # for LEV_'s
4
- require 'rex/logging/log_dispatcher'
8
+
9
+ module Rex
10
+ module Logging
11
+ autoload :LogSink, 'rex/logging/log_sink'
12
+ autoload :Sinks, 'rex/logging/sinks'
13
+ end
14
+ end
15
+
16
+ # This defines a global so it must be loaded always
17
+ require 'rex/logging/log_dispatcher'
@@ -1,5 +1,4 @@
1
1
  require 'rex/sync'
2
- require 'rex/logging/log_sink'
3
2
 
4
3
  module Rex
5
4
  module Logging
@@ -37,6 +37,3 @@ end
37
37
 
38
38
  end
39
39
  end
40
-
41
- require 'rex/logging/sinks/flatfile'
42
- require 'rex/logging/sinks/stderr'
@@ -0,0 +1,16 @@
1
+ ##
2
+ # $Id: sinks.rb 12554 2011-05-06 18:47:10Z jduck $
3
+ #
4
+ # Map log sinks for autload
5
+ ##
6
+
7
+ module Rex
8
+ module Logging
9
+ module Sinks
10
+
11
+ autoload :Flatfile, 'rex/logging/sinks/flatfile'
12
+ autoload :Stderr, 'rex/logging/sinks/stderr'
13
+
14
+ end
15
+ end
16
+ end
@@ -1,3 +1,5 @@
1
+ require 'rex/logging'
2
+
1
3
  module Rex
2
4
  module Logging
3
5
  module Sinks
@@ -0,0 +1,23 @@
1
+ ##
2
+ # $Id: parser.rb 12554 2011-05-06 18:47:10Z jduck $
3
+ #
4
+ # This file maps parsers for autoload
5
+ ##
6
+
7
+ module Rex
8
+ module Parser
9
+ # General parsers
10
+ autoload :Arguments, 'rex/parser/arguments'
11
+ autoload :Ini, 'rex/parser/ini'
12
+
13
+ # Data import parsers
14
+ autoload :NmapXMLStreamParser, 'rex/parser/nmap_xml'
15
+ autoload :NexposeXMLStreamParser, 'rex/parser/nexpose_xml'
16
+ autoload :RetinaXMLStreamParser, 'rex/parser/retina_xml'
17
+ autoload :NetSparkerXMLStreamParser, 'rex/parser/netsparker_xml'
18
+ autoload :NessusXMLStreamParser, 'rex/parser/nessus_xml'
19
+ autoload :IP360XMLStreamParser, 'rex/parser/ip360_xml'
20
+ autoload :IP360ASPLXMLStreamParser, 'rex/parser/ip360_aspl_xml'
21
+ autoload :AppleBackupManifestDB, 'rex/parser/apple_backup_manifestdb'
22
+ end
23
+ end
@@ -1 +1,3 @@
1
- require 'rex/payloads/win32'
1
+ module Rex::Payloads
2
+ autoload :Win32, 'rex/payloads/win32'
3
+ end
@@ -1,2 +1,4 @@
1
- require 'rex/payloads/win32/common'
2
- require 'rex/payloads/win32/kernel'
1
+ module Rex::Payloads::Win32
2
+ autoload :Common, 'rex/payloads/win32/common'
3
+ autoload :Kernel, 'rex/payloads/win32/kernel'
4
+ end
@@ -1,14 +1,13 @@
1
1
  module Rex
2
2
  module Payloads
3
3
  module Win32
4
-
5
- require 'rex/payloads/win32/kernel/common'
6
- require 'rex/payloads/win32/kernel/recovery'
7
- require 'rex/payloads/win32/kernel/stager'
8
- require 'rex/payloads/win32/kernel/migration'
9
-
10
4
  module Kernel
11
5
 
6
+ autoload :Common, 'rex/payloads/win32/kernel/common'
7
+ autoload :Recovery, 'rex/payloads/win32/kernel/recovery'
8
+ autoload :Stager, 'rex/payloads/win32/kernel/stager'
9
+ autoload :Migration, 'rex/payloads/win32/kernel/migration'
10
+
12
11
  #
13
12
  # Constructs a kernel-mode payload using the supplied options. The options
14
13
  # can be:
@@ -1,12 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
-
3
- # $Id: peparsey.rb 12196 2011-04-01 00:51:33Z egypt $
2
+ #
3
+ # $Id: peparsey.rb 12554 2011-05-06 18:47:10Z jduck $
4
+ #
4
5
 
5
6
  module Rex
6
7
  module PeParsey
7
-
8
+ autoload :Pe, 'rex/peparsey/pe'
9
+ autoload :PeMemDump, 'rex/peparsey/pe_memdump'
8
10
  end
9
11
  end
10
-
11
- require 'rex/peparsey/pe'
12
- require 'rex/peparsey/pe_memdump'
@@ -1,13 +1,12 @@
1
1
  #!/usr/bin/env ruby
2
-
3
- # $Id: pescan.rb 12196 2011-04-01 00:51:33Z egypt $
2
+ #
3
+ # $Id: pescan.rb 12554 2011-05-06 18:47:10Z jduck $
4
+ #
4
5
 
5
6
  module Rex
6
7
  module PeScan
7
-
8
+ autoload :Analyze, 'rex/pescan/analyze'
9
+ autoload :Scanner, 'rex/pescan/scanner'
10
+ autoload :Search, 'rex/pescan/search'
8
11
  end
9
12
  end
10
-
11
- require 'rex/pescan/analyze'
12
- require 'rex/pescan/scanner'
13
- require 'rex/pescan/search'
@@ -1 +1,11 @@
1
- require 'rex/platforms/windows'
1
+ ##
2
+ # $Id: $
3
+ #
4
+ # This file maps Platforms for autoload
5
+ ##
6
+
7
+ module Rex
8
+ module Platforms
9
+ autoload :Windows, 'rex/platforms/windows'
10
+ end
11
+ end
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- $:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..','..','..','..','..', 'lib'))
3
+ $:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..','..','..','..'))
4
4
 
5
5
  require 'rex/post/meterpreter/extensions/stdapi/railgun/api_constants'
6
6
  require 'rex/post/meterpreter/extensions/stdapi/railgun/win_const_manager'
@@ -1,13 +1,24 @@
1
- require 'rex/proto/http'
2
- require 'rex/proto/smb'
3
- require 'rex/proto/ntlm'
4
- require 'rex/proto/dcerpc'
5
- require 'rex/proto/drda'
1
+ ##
2
+ # $Id: proto.rb 12554 2011-05-06 18:47:10Z jduck $
3
+ #
4
+ # This file maps Proto items for autoload
5
+ ##
6
6
 
7
7
  module Rex
8
8
  module Proto
9
9
 
10
- attr_accessor :alias
10
+ autoload :Http, 'rex/proto/http'
11
+ autoload :SMB, 'rex/proto/smb'
12
+ autoload :NTLM, 'rex/proto/ntlm'
13
+ autoload :DCERPC, 'rex/proto/dcerpc'
14
+ autoload :DRDA, 'rex/proto/drda'
15
+
16
+ autoload :SunRPC, 'rex/proto/sunrpc'
17
+ autoload :DHCP, 'rex/proto/dhcp'
18
+ autoload :TFTP, 'rex/proto/tftp'
19
+ autoload :RFB, 'rex/proto/rfb'
20
+
21
+ attr_accessor :alias
11
22
 
12
23
  end
13
24
  end
@@ -1,6 +1,15 @@
1
- require 'rex/proto/dcerpc/uuid'
2
- require 'rex/proto/dcerpc/response'
3
- require 'rex/proto/dcerpc/client'
4
- require 'rex/proto/dcerpc/packet'
5
- require 'rex/proto/dcerpc/handle'
6
- require 'rex/proto/dcerpc/ndr'
1
+ module Rex
2
+ module Proto
3
+ module DCERPC
4
+
5
+ autoload :Exceptions, 'rex/proto/dcerpc/exceptions'
6
+ autoload :UUID, 'rex/proto/dcerpc/uuid'
7
+ autoload :Response, 'rex/proto/dcerpc/response'
8
+ autoload :Client, 'rex/proto/dcerpc/client'
9
+ autoload :Packet, 'rex/proto/dcerpc/packet'
10
+ autoload :Handle, 'rex/proto/dcerpc/handle'
11
+ autoload :NDR, 'rex/proto/dcerpc/ndr'
12
+
13
+ end
14
+ end
15
+ end
@@ -1,5 +1,10 @@
1
- require 'rex/proto/drda/constants'
2
- require 'rex/proto/drda/packet'
3
- require 'rex/proto/drda/utils'
4
-
1
+ module Rex
2
+ module Proto
3
+ module DRDA
4
+ autoload :Constants, 'rex/proto/drda/constants'
5
+ autoload :Utils, 'rex/proto/drda/utils'
6
+ end
7
+ end
8
+ end
5
9
 
10
+ require 'rex/proto/drda/packet'
@@ -1,5 +1,18 @@
1
+ # These are required by all uses of Rex::Proto::Http
1
2
  require 'rex/proto/http/packet'
2
3
  require 'rex/proto/http/request'
3
4
  require 'rex/proto/http/response'
4
- require 'rex/proto/http/client'
5
- require 'rex/proto/http/server'
5
+
6
+ # These are specific to use case
7
+ module Rex
8
+ module Proto
9
+ module Http
10
+
11
+ autoload :Client, 'rex/proto/http/client'
12
+
13
+ autoload :Server, 'rex/proto/http/server'
14
+ autoload :Handler, 'rex/proto/http/handler'
15
+
16
+ end
17
+ end
18
+ end
@@ -1,4 +1,5 @@
1
1
  require 'rex/proto/http'
2
+ require 'rex/text'
2
3
 
3
4
  module Rex
4
5
  module Proto
@@ -1,7 +1,13 @@
1
- require 'rex/proto/ntlm/constants'
2
- require 'rex/proto/ntlm/exceptions'
3
- require 'rex/proto/ntlm/crypt'
4
- require 'rex/proto/ntlm/utils'
5
- require 'rex/proto/ntlm/base'
6
- require 'rex/proto/ntlm/message'
1
+ module Rex
2
+ module Proto
3
+ module NTLM
4
+ autoload :Constants, 'rex/proto/ntlm/constants'
5
+ autoload :Exceptions, 'rex/proto/ntlm/exceptions'
7
6
 
7
+ autoload :Base, 'rex/proto/ntlm/base'
8
+ autoload :Crypt, 'rex/proto/ntlm/crypt'
9
+ autoload :Message, 'rex/proto/ntlm/message'
10
+ autoload :Utils, 'rex/proto/ntlm/utils'
11
+ end
12
+ end
13
+ end
@@ -1,4 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File.join(File.dirname(__FILE__), '..', '..'))
4
+
2
5
  require 'test/unit'
3
6
  require 'rex/proto/ntlm'
4
7
  require 'rex/socket'
@@ -45,6 +45,8 @@
45
45
 
46
46
  #this module defines the message class , useful for easily handling type 1/2/3 ntlm messages
47
47
 
48
+ require 'rex/text'
49
+
48
50
  require 'rex/proto/ntlm/base'
49
51
  require 'rex/proto/ntlm/constants'
50
52
  require 'rex/proto/ntlm/crypt'
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ $:.unshift(File.join(File.dirname(__FILE__), '..', '..'))
4
+
3
5
  ##
4
6
  # $Id: $
5
7
  ##
@@ -1,7 +1,15 @@
1
- require 'rex/proto/smb/constants'
2
- require 'rex/proto/smb/exceptions'
3
- require 'rex/proto/smb/evasions'
4
- require 'rex/proto/smb/crypt'
5
- require 'rex/proto/smb/utils'
6
- require 'rex/proto/smb/client'
7
- require 'rex/proto/smb/simpleclient'
1
+ module Rex
2
+ module Proto
3
+ module SMB
4
+
5
+ autoload :Constants, 'rex/proto/smb/constants'
6
+ autoload :Exceptions, 'rex/proto/smb/exceptions'
7
+ autoload :Evasions, 'rex/proto/smb/evasions'
8
+ autoload :Crypt, 'rex/proto/smb/crypt'
9
+ autoload :Utils, 'rex/proto/smb/utils'
10
+ autoload :Client, 'rex/proto/smb/client'
11
+ autoload :SimpleClient, 'rex/proto/smb/simpleclient'
12
+
13
+ end
14
+ end
15
+ end
@@ -1,6 +1,5 @@
1
1
  require 'singleton'
2
2
  require 'rex'
3
- require 'rex/service'
4
3
 
5
4
  module Rex
6
5
 
@@ -12,19 +12,23 @@ module Rex
12
12
  ###
13
13
  module Socket
14
14
 
15
- module Comm
16
- end
17
-
18
- require 'rex/socket/parameters'
19
- require 'rex/socket/tcp'
20
- require 'rex/socket/tcp_server'
21
-
22
- require 'rex/socket/comm'
23
- require 'rex/socket/comm/local'
24
-
25
- require 'rex/socket/switch_board'
26
- require 'rex/socket/subnet_walker'
27
- require 'rex/socket/range_walker'
15
+ # Plumbing / Aux
16
+ autoload :Parameters, 'rex/socket/parameters'
17
+ autoload :Comm, 'rex/socket/comm'
18
+
19
+ # Underlying protocol-specific
20
+ autoload :Ip, 'rex/socket/ip'
21
+ autoload :Udp, 'rex/socket/udp'
22
+ autoload :Tcp, 'rex/socket/tcp'
23
+ autoload :TcpServer, 'rex/socket/tcp_server'
24
+ autoload :SslTcp, 'rex/socket/ssl_tcp'
25
+ autoload :SslTcpServer, 'rex/socket/ssl_tcp_server'
26
+
27
+ # Utilities
28
+ autoload :SwitchBoard, 'rex/socket/switch_board'
29
+ autoload :SubnetWalker, 'rex/socket/subnet_walker'
30
+ autoload :Range, 'rex/socket/range_walker'
31
+ autoload :RangeWalker, 'rex/socket/range_walker'
28
32
 
29
33
  ##
30
34
  #
@@ -14,6 +14,8 @@ module Socket
14
14
  ###
15
15
  module Comm
16
16
 
17
+ autoload :Local, 'rex/socket/comm/local'
18
+
17
19
  ###
18
20
  #
19
21
  # This mixin provides stubs for event notification handlers that can be
@@ -1,10 +1,6 @@
1
- require 'singleton'
1
+ require 'rex/compat'
2
2
  require 'rex/socket'
3
- require 'rex/socket/tcp'
4
- require 'rex/socket/ssl_tcp'
5
- require 'rex/socket/ssl_tcp_server'
6
- require 'rex/socket/udp'
7
- require 'rex/socket/ip'
3
+ require 'singleton'
8
4
  require 'timeout'
9
5
 
10
6
  ###
@@ -144,7 +144,8 @@ begin
144
144
 
145
145
  total_sent = 0
146
146
  total_length = buf.length
147
- block_size = 32768
147
+ block_size = 16384
148
+ retry_time = 0.5
148
149
 
149
150
  begin
150
151
  while( total_sent < total_length )
@@ -160,29 +161,35 @@ begin
160
161
  end
161
162
 
162
163
  rescue ::IOError, ::Errno::EPIPE
163
- return nil if (fd.abortive_close == true)
164
+ return nil
164
165
 
165
166
  # Ruby 1.8.7 and 1.9.0/1.9.1 uses a standard Errno
166
167
  rescue ::Errno::EAGAIN, ::Errno::EWOULDBLOCK
167
168
  # Sleep for a half a second, or until we can write again
168
- Rex::ThreadSafe.select( nil, [ self.sslsock ], nil, 0.5 )
169
+ Rex::ThreadSafe.select( nil, [ self.sslsock ], nil, retry_time )
169
170
  # Decrement the block size to handle full sendQs better
170
171
  block_size = 1024
171
172
  # Try to write the data again
172
173
  retry
173
-
174
+
174
175
  # Ruby 1.9.2+ uses IO::WaitReadable/IO::WaitWritable
175
176
  rescue ::Exception => e
176
177
  if ::IO.const_defined?('WaitReadable') and e.kind_of?(::IO::WaitReadable)
177
- IO::select( [ self.sslsock ], nil, nil, 0.5 )
178
+ IO::select( [ self.sslsock ], nil, nil, retry_time )
178
179
  retry
179
180
  end
180
181
 
181
182
  if ::IO.const_defined?('WaitWritable') and e.kind_of?(::IO::WaitWritable)
182
- IO::select( nil, [ self.sslsock ], nil, 0.5 )
183
+ IO::select( nil, [ self.sslsock ], nil, retry_time )
183
184
  retry
184
185
  end
185
-
186
+
187
+ # Another form of SSL error, this is always fatal
188
+ if e.kind_of?(::OpenSSL::SSL::SSLError)
189
+ return nil
190
+ end
191
+
192
+ # Bubble the event up to the caller otherwise
186
193
  raise e
187
194
  end
188
195
 
@@ -197,8 +204,8 @@ begin
197
204
  length = 16384 unless length
198
205
  begin
199
206
  return sslsock.sysread(length)
200
- rescue EOFError, ::Errno::EPIPE
201
- raise EOFError
207
+ rescue ::IOError, ::Errno::EPIPE, ::OpenSSL::SSL::SSLError
208
+ return nil
202
209
  end
203
210
  return
204
211
  end
@@ -210,13 +217,11 @@ begin
210
217
  if( s == nil || s[0] == nil )
211
218
  next
212
219
  end
213
- buf = sslsock.read_nonblock( length )
214
- return buf if buf
215
- raise ::EOFError
220
+ return sslsock.read_nonblock( length )
216
221
  end
217
222
 
218
223
  rescue ::IOError, ::Errno::EPIPE
219
- return nil if (fd.abortive_close == true)
224
+ return nil
220
225
 
221
226
  # Ruby 1.8.7 and 1.9.0/1.9.1 uses a standard Errno
222
227
  rescue ::Errno::EAGAIN, ::Errno::EWOULDBLOCK
@@ -238,6 +243,11 @@ begin
238
243
  IO::select( nil, [ self.sslsock ], nil, 0.5 )
239
244
  retry
240
245
  end
246
+
247
+ # Another form of SSL error, this is always fatal
248
+ if e.kind_of?(::OpenSSL::SSL::SSLError)
249
+ return nil
250
+ end
241
251
 
242
252
  raise e
243
253
  end
@@ -249,7 +259,7 @@ begin
249
259
  # Closes the SSL socket.
250
260
  #
251
261
  def close
252
- sslsock.close
262
+ sslsock.close rescue nil
253
263
  super
254
264
  end
255
265
 
@@ -281,7 +291,21 @@ begin
281
291
  def cipher
282
292
  sslsock.cipher if sslsock
283
293
  end
294
+
295
+ #
296
+ # Prevent a sysread from the bare socket
297
+ #
298
+ def sysread(*args)
299
+ raise RuntimeError, "Invalid sysread() call on SSL socket"
300
+ end
284
301
 
302
+ #
303
+ # Prevent a sysread from the bare socket
304
+ #
305
+ def syswrite(*args)
306
+ raise RuntimeError, "Invalid syswrite() call on SSL socket"
307
+ end
308
+
285
309
  attr_reader :peer_verified # :nodoc:
286
310
  attr_accessor :sslsock, :sslctx # :nodoc:
287
311
 
@@ -78,6 +78,7 @@ class SwitchBoard
78
78
  if ret && comm.respond_to?(:routes) && comm.routes.kind_of?(Array)
79
79
  comm.routes << "#{subnet}/#{mask}"
80
80
  end
81
+ ret
81
82
  end
82
83
 
83
84
  #
@@ -89,6 +90,7 @@ class SwitchBoard
89
90
  if ret && comm.respond_to?(:routes) && comm.routes.kind_of?(Array)
90
91
  comm.routes.delete "#{subnet}/#{mask}"
91
92
  end
93
+ ret
92
94
  end
93
95
 
94
96
  #
@@ -193,7 +195,9 @@ class SwitchBoard
193
195
  # Remove each of the individual routes so the comms don't think they're
194
196
  # still routing after a flush.
195
197
  self.routes.each { |r|
196
- r.comm.routes.delete("#{r.subnet}/#{r.netmask}")
198
+ if r.comm.respond_to? :routes
199
+ r.comm.routes.delete("#{r.subnet}/#{r.netmask}")
200
+ end
197
201
  }
198
202
  # Re-initialize to an empty array
199
203
  self.routes = Array.new
@@ -31,9 +31,9 @@ class Rex::Socket::TcpServer::UnitTest < Test::Unit::TestCase
31
31
 
32
32
  assert_equal(2, scli.put("Yo"), "scli: put Yo")
33
33
  assert_equal("Yo", ccli.get(), "ccli: get Yo")
34
- assert(scli.methods.include?('<<'))
35
- assert(scli.methods.include?('>>'))
36
- assert(scli.methods.include?('has_read_data?'))
34
+ assert(scli.methods.include?('<<'), "no << operator")
35
+ assert(scli.methods.include?('>>'), "no >> operator")
36
+ assert(scli.methods.include?('has_read_data?'), "no has_read_data?")
37
37
 
38
38
  ensure
39
39
  ccli.close if (ccli)
@@ -1,6 +1,6 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'rex/sync/thread_safe'
4
- require 'rex/sync/ref'
5
- require 'rex/sync/read_write_lock'
6
- require 'rex/sync/event'
1
+ module Rex
2
+ autoload :ReadWriteLock, 'rex/sync/read_write_lock'
3
+ autoload :ThreadSafe, 'rex/sync/thread_safe'
4
+ autoload :Ref, 'rex/sync/ref'
5
+ autoload :Sync, 'rex/sync/event'
6
+ end
@@ -3,19 +3,19 @@
3
3
  # wrappers of the rex library.
4
4
  #
5
5
 
6
- # General classes
7
- require 'rex/ui/output'
8
- require 'rex/ui/progress_tracker'
6
+ require 'rex'
9
7
 
10
- # Text-based user interfaces
11
- require 'rex/ui/text/input'
12
- require 'rex/ui/text/shell'
13
- require 'rex/ui/text/dispatcher_shell'
14
- require 'rex/ui/text/irb_shell'
8
+ module Rex
9
+ module Ui
10
+ # General classes
11
+ autoload :Output, 'rex/ui/output'
12
+ autoload :ProgressTracker, 'rex/ui/progress_tracker'
15
13
 
16
- require 'rex/ui/text/color'
17
- require 'rex/ui/text/table'
14
+ # Text-based user interfaces
15
+ autoload :Text, 'rex/ui/text'
18
16
 
19
- # Ui subscriber
20
- require 'rex/ui/subscriber'
21
- require 'rex/ui/interactive'
17
+ # Ui subscriber
18
+ autoload :Subscriber, 'rex/ui/subscriber'
19
+ autoload :Interactive, 'rex/ui/interactive'
20
+ end
21
+ end
@@ -0,0 +1,17 @@
1
+ module Rex
2
+ module Ui
3
+ module Text
4
+ autoload :Input, 'rex/ui/text/input'
5
+ autoload :Output, 'rex/ui/text/output'
6
+ autoload :Color, 'rex/ui/text/color'
7
+ autoload :Table, 'rex/ui/text/table'
8
+
9
+ autoload :PseudoShell, 'rex/ui/text/shell'
10
+ autoload :Shell, 'rex/ui/text/shell'
11
+ autoload :DispatcherShell, 'rex/ui/text/dispatcher_shell'
12
+ autoload :IrbShell, 'rex/ui/text/irb_shell'
13
+
14
+ autoload :ProgressTracker, 'rex/ui/text/progress_tracker'
15
+ end
16
+ end
17
+ end
@@ -13,10 +13,10 @@ module Text
13
13
  ###
14
14
  class Input
15
15
 
16
- require 'rex/ui/text/input/stdio'
17
- require 'rex/ui/text/input/readline'
18
- require 'rex/ui/text/input/socket'
19
- require 'rex/ui/text/color'
16
+ autoload :Buffer, 'rex/ui/text/color'
17
+ autoload :Stdio, 'rex/ui/text/input/stdio'
18
+ autoload :Readline, 'rex/ui/text/input/readline'
19
+ autoload :Socket, 'rex/ui/text/input/socket'
20
20
 
21
21
  include Rex::Ui::Text::Color
22
22
 
@@ -14,7 +14,10 @@ require 'rex/io/stream_abstraction'
14
14
  class Input::Buffer < Rex::Ui::Text::Input
15
15
 
16
16
  class BufferSock
17
- include Rex::IO::StreamAbstraction
17
+ include Rex::IO::StreamAbstraction
18
+ def write(buf, opts={})
19
+ syswrite(buf)
20
+ end
18
21
  end
19
22
 
20
23
  def initialize
@@ -30,10 +33,10 @@ class Input::Buffer < Rex::Ui::Text::Input
30
33
  @sock.rsock.sysread(len)
31
34
  end
32
35
 
33
- def put(msg)
36
+ def put(msg, opts={})
34
37
  @sock.lsock.write(msg)
35
38
  end
36
-
39
+
37
40
  #
38
41
  # Wait for a line of input to be read from a socket.
39
42
  #
@@ -12,11 +12,10 @@ module Text
12
12
  ###
13
13
  class Output < Rex::Ui::Output
14
14
 
15
- require 'rex/ui/text/output/stdio'
16
- require 'rex/ui/text/output/socket'
17
- require 'rex/ui/text/output/buffer'
18
- require 'rex/ui/text/output/file'
19
- require 'rex/ui/text/color'
15
+ autoload :Stdio, 'rex/ui/text/output/stdio'
16
+ autoload :Socket, 'rex/ui/text/output/socket'
17
+ autoload :Buffer, 'rex/ui/text/output/buffer'
18
+ autoload :File, 'rex/ui/text/output/file'
20
19
 
21
20
  include Rex::Ui::Text::Color
22
21
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: librex
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.30
5
+ version: 0.0.31
6
6
  platform: ruby
7
7
  authors:
8
8
  - Metasploit Development Team
@@ -11,11 +11,11 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-05-02 00:00:00 -05:00
14
+ date: 2011-05-07 00:00:00 -05:00
15
15
  default_executable:
16
16
  dependencies: []
17
17
 
18
- description: Rex provides a variety of classes useful for security testing and exploit development. Based on SVN Revision 12516
18
+ description: Rex provides a variety of classes useful for security testing and exploit development. Based on SVN Revision 12559
19
19
  email:
20
20
  - hdm@metasploit.com
21
21
  - jacob.hammack@hammackj.com
@@ -60,9 +60,11 @@ files:
60
60
  - lib/rex/encoder/xor/dword.rb
61
61
  - lib/rex/encoder/xor/dword_additive.rb
62
62
  - lib/rex/encoder/xor.rb
63
+ - lib/rex/encoder.rb
63
64
  - lib/rex/encoders/xor_dword.rb
64
65
  - lib/rex/encoders/xor_dword_additive.rb
65
66
  - lib/rex/encoders/xor_dword_additive.rb.ut.rb
67
+ - lib/rex/encoders.rb
66
68
  - lib/rex/encoding/xor/byte.rb
67
69
  - lib/rex/encoding/xor/byte.rb.ut.rb
68
70
  - lib/rex/encoding/xor/dword.rb
@@ -77,6 +79,7 @@ files:
77
79
  - lib/rex/encoding/xor/word.rb.ut.rb
78
80
  - lib/rex/encoding/xor.rb
79
81
  - lib/rex/encoding/xor.rb.ts.rb
82
+ - lib/rex/encoding.rb
80
83
  - lib/rex/exceptions.rb
81
84
  - lib/rex/exceptions.rb.ut.rb
82
85
  - lib/rex/exploitation/cmdstager/base.rb
@@ -110,12 +113,14 @@ files:
110
113
  - lib/rex/io/stream.rb
111
114
  - lib/rex/io/stream_abstraction.rb
112
115
  - lib/rex/io/stream_server.rb
116
+ - lib/rex/io.rb
113
117
  - lib/rex/job_container.rb
114
118
  - lib/rex/LICENSE
115
119
  - lib/rex/logging/log_dispatcher.rb
116
120
  - lib/rex/logging/log_sink.rb
117
121
  - lib/rex/logging/sinks/flatfile.rb
118
122
  - lib/rex/logging/sinks/stderr.rb
123
+ - lib/rex/logging/sinks.rb
119
124
  - lib/rex/logging.rb
120
125
  - lib/rex/machparsey/exceptions.rb
121
126
  - lib/rex/machparsey/mach.rb
@@ -161,6 +166,7 @@ files:
161
166
  - lib/rex/parser/nexpose_xml.rb
162
167
  - lib/rex/parser/nmap_xml.rb
163
168
  - lib/rex/parser/retina_xml.rb
169
+ - lib/rex/parser.rb
164
170
  - lib/rex/payloads/win32/common.rb
165
171
  - lib/rex/payloads/win32/kernel/common.rb
166
172
  - lib/rex/payloads/win32/kernel/migration.rb
@@ -454,6 +460,7 @@ files:
454
460
  - lib/rex/ui/text/shell.rb
455
461
  - lib/rex/ui/text/table.rb
456
462
  - lib/rex/ui/text/table.rb.ut.rb
463
+ - lib/rex/ui/text.rb
457
464
  - lib/rex/ui.rb
458
465
  - lib/rex/zip/archive.rb
459
466
  - lib/rex/zip/blocks.rb