librex 0.0.63 → 0.0.65

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/README.markdown +1 -1
  2. data/lib/rex/assembly/nasm.rb +4 -4
  3. data/lib/rex/post/meterpreter/extensions/stdapi/net/config.rb +4 -4
  4. data/lib/rex/post/meterpreter/extensions/stdapi/net/interface.rb +2 -2
  5. data/lib/rex/post/meterpreter/extensions/stdapi/net/socket.rb +1 -1
  6. data/lib/rex/post/meterpreter/extensions/stdapi/net/socket_subsystem/tcp_server_channel.rb +27 -27
  7. data/lib/rex/post/meterpreter/extensions/stdapi/railgun/api_constants.rb +2 -2
  8. data/lib/rex/post/meterpreter/extensions/stdapi/railgun/buffer_item.rb +1 -1
  9. data/lib/rex/post/meterpreter/extensions/stdapi/railgun/buffer_item.rb.ut.rb +3 -3
  10. data/lib/rex/post/meterpreter/extensions/stdapi/railgun/def/def_advapi32.rb +19 -15
  11. data/lib/rex/post/meterpreter/extensions/stdapi/railgun/def/def_crypt32.rb +1 -1
  12. data/lib/rex/post/meterpreter/extensions/stdapi/railgun/def/def_iphlpapi.rb +1 -1
  13. data/lib/rex/post/meterpreter/extensions/stdapi/railgun/def/def_kernel32.rb +680 -680
  14. data/lib/rex/post/meterpreter/extensions/stdapi/railgun/def/def_netapi32.rb +1 -1
  15. data/lib/rex/post/meterpreter/extensions/stdapi/railgun/def/def_ntdll.rb +1 -1
  16. data/lib/rex/post/meterpreter/extensions/stdapi/railgun/def/def_shell32.rb +1 -1
  17. data/lib/rex/post/meterpreter/extensions/stdapi/railgun/def/def_user32.rb +2 -2
  18. data/lib/rex/post/meterpreter/extensions/stdapi/railgun/def/def_wlanapi.rb +12 -12
  19. data/lib/rex/post/meterpreter/extensions/stdapi/railgun/def/def_ws2_32.rb +1 -1
  20. data/lib/rex/post/meterpreter/extensions/stdapi/railgun/dll.rb +3 -3
  21. data/lib/rex/post/meterpreter/extensions/stdapi/railgun/dll.rb.ut.rb +1 -1
  22. data/lib/rex/post/meterpreter/extensions/stdapi/railgun/dll_function.rb +6 -6
  23. data/lib/rex/post/meterpreter/extensions/stdapi/railgun/dll_function.rb.ut.rb +2 -2
  24. data/lib/rex/post/meterpreter/extensions/stdapi/railgun/dll_helper.rb +4 -4
  25. data/lib/rex/post/meterpreter/extensions/stdapi/railgun/dll_helper.rb.ut.rb +7 -7
  26. data/lib/rex/post/meterpreter/extensions/stdapi/railgun/dll_wrapper.rb +2 -2
  27. data/lib/rex/post/meterpreter/extensions/stdapi/railgun/dll_wrapper.rb.ut.rb +1 -1
  28. data/lib/rex/post/meterpreter/extensions/stdapi/railgun/mock_magic.rb +5 -5
  29. data/lib/rex/post/meterpreter/extensions/stdapi/railgun/multicall.rb +6 -6
  30. data/lib/rex/post/meterpreter/extensions/stdapi/railgun/railgun.rb +20 -20
  31. data/lib/rex/post/meterpreter/extensions/stdapi/railgun/railgun.rb.ut.rb +5 -5
  32. data/lib/rex/post/meterpreter/extensions/stdapi/railgun/util.rb +15 -15
  33. data/lib/rex/post/meterpreter/extensions/stdapi/railgun/win_const_manager.rb +2 -2
  34. data/lib/rex/post/meterpreter/extensions/stdapi/railgun/win_const_manager.rb.ut.rb +5 -5
  35. data/lib/rex/post/meterpreter/extensions/stdapi/stdapi.rb +3 -3
  36. data/lib/rex/post/meterpreter/extensions/stdapi/sys/event_log.rb +3 -3
  37. data/lib/rex/post/meterpreter/extensions/stdapi/sys/event_log_subsystem/event_record.rb +6 -6
  38. data/lib/rex/post/meterpreter/extensions/stdapi/sys/process_subsystem/memory.rb +10 -10
  39. data/lib/rex/post/meterpreter/extensions/stdapi/sys/process_subsystem/thread.rb +2 -2
  40. data/lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/registry_key.rb +3 -3
  41. data/lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/registry_value.rb +2 -2
  42. data/lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/remote_registry_key.rb +3 -3
  43. data/lib/rex/post/meterpreter/extensions/stdapi/sys/thread.rb +6 -6
  44. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/sys.rb +10 -5
  45. data/lib/rex/proto/smb/constants.rb +1 -1
  46. data/lib/rex/socket.rb +24 -7
  47. data/lib/rex/text.rb +15 -1
  48. data/lib/rex/text.rb.ut.rb +2 -0
  49. data/lib/rex/ui/text/output/stdio.rb +5 -1
  50. metadata +5 -5
@@ -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__), '..', '..', '..','..','..','..','..', 'lib'))
4
4
 
5
5
  require 'rex/post/meterpreter/extensions/stdapi/railgun/railgun'
6
6
  require 'rex/post/meterpreter/extensions/stdapi/railgun/mock_magic'
@@ -15,7 +15,7 @@ module Stdapi
15
15
  module Railgun
16
16
  class Railgun::UnitTest < Test::Unit::TestCase
17
17
 
18
- # DLLs we know should be available at the time of this writing,
18
+ # DLLs we know should be available at the time of this writing,
19
19
  # and DLLs that because of changes since then should be available
20
20
  STOCK_DLLS = [
21
21
  'kernel32',
@@ -38,7 +38,7 @@ class Railgun::UnitTest < Test::Unit::TestCase
38
38
 
39
39
  assert_equal(dll_names.length, dll_names.uniq.length,
40
40
  "known_dll_names should not have duplicates")
41
-
41
+
42
42
  STOCK_DLLS.each do |name|
43
43
  assert(dll_names.include?(name),
44
44
  "known_dll_names should include #{name}")
@@ -89,7 +89,7 @@ class Railgun::UnitTest < Test::Unit::TestCase
89
89
 
90
90
  def test_method_missing
91
91
  railgun = Railgun.new(make_mock_client())
92
-
92
+
93
93
  STOCK_DLLS.each do |dll_name|
94
94
  assert_nothing_raised do
95
95
  railgun.send(dll_name.to_sym)
@@ -129,7 +129,7 @@ class Railgun::UnitTest < Test::Unit::TestCase
129
129
 
130
130
  dll_name = func[:dll_name]
131
131
  function_name = func[:name]
132
-
132
+
133
133
  railgun.add_dll(dll_name)
134
134
  railgun.add_function(dll_name, function_name, func[:return_type], func[:params])
135
135
 
@@ -29,7 +29,7 @@ class Util
29
29
  :long_long => 8,
30
30
  :float => 4,
31
31
  :double => 8,
32
- :long_double => 8,
32
+ :long_double => 8,
33
33
  :wchar_t => 2,
34
34
  }
35
35
 
@@ -323,7 +323,7 @@ class Util
323
323
  #
324
324
  def unpack_pointer(packed_pointer)
325
325
  if is_64bit
326
- # XXX: Only works if attacker and victim are like-endianed
326
+ # XXX: Only works if attacker and victim are like-endianed
327
327
  packed_pointer.unpack('Q')[0]
328
328
  else
329
329
  packed_pointer.unpack('V')[0]
@@ -343,7 +343,7 @@ class Util
343
343
  if pointer.class == String
344
344
  pointer = unpack_pointer(pointer)
345
345
  end
346
-
346
+
347
347
  return pointer.nil? || pointer == 0
348
348
  end
349
349
 
@@ -360,13 +360,13 @@ class Util
360
360
  return ''
361
361
  end
362
362
 
363
- # If length not provided, use lstrlenW
363
+ # If length not provided, use lstrlenW
364
364
  if length.nil?
365
365
  length = railgun.kernel32.lstrlenW(pointer)['return']
366
366
  end
367
367
 
368
368
  # Retrieve the array of characters
369
- chars = read_array(:WCHAR, length, pointer)
369
+ chars = read_array(:WCHAR, length, pointer)
370
370
 
371
371
  # Concatenate the characters and convert to a ruby string
372
372
  str = uniz_to_str(chars.join(''))
@@ -457,7 +457,7 @@ class Util
457
457
  offset = 0
458
458
 
459
459
  1.upto(length).map do |n|
460
- data = read_data(type, offset, buffer)
460
+ data = read_data(type, offset, buffer)
461
461
 
462
462
  offset = offset + size
463
463
 
@@ -524,11 +524,11 @@ class Util
524
524
 
525
525
  if TYPE_DEFINITIONS.has_key?(type)
526
526
  primitive = TYPE_DEFINITIONS[type]
527
-
527
+
528
528
  if primitive == :pointer
529
529
  return pointer_size
530
- end
531
-
530
+ end
531
+
532
532
  if PRIMITIVE_TYPE_SIZES.has_key?(primitive)
533
533
  return PRIMITIVE_TYPE_SIZES[primitive]
534
534
  else
@@ -551,7 +551,7 @@ class Util
551
551
  end
552
552
 
553
553
  #
554
- # Given a description of a data structure, returns an Array containing
554
+ # Given a description of a data structure, returns an Array containing
555
555
  # the offset from the beginning for each subsequent element, taking into
556
556
  # consideration alignment and padding.
557
557
  #
@@ -565,7 +565,7 @@ class Util
565
565
  if sizeof_type(data_type) > padding
566
566
  offset = offset + padding
567
567
  end
568
-
568
+
569
569
  offsets.push(offset)
570
570
 
571
571
  offset = offset + sizeof_type(data_type)
@@ -575,7 +575,7 @@ class Util
575
575
 
576
576
  offsets
577
577
  end
578
-
578
+
579
579
  # http://en.wikipedia.org/wiki/Data_structure_alignment
580
580
  def required_alignment
581
581
  is_64bit ? 8 : 4
@@ -605,13 +605,13 @@ class Util
605
605
  if type =~ /^(\w+)\[(\w+)\]$/
606
606
  element_type = $1
607
607
  length = $2
608
-
608
+
609
609
  unless length =~ /^\d+$/
610
610
  length = railgun.const(length)
611
611
  end
612
-
612
+
613
613
  return element_type, length
614
- else
614
+ else
615
615
  raise "Can not split non-array type #{type}"
616
616
  end
617
617
  end
@@ -38,10 +38,10 @@ class WinConstManager
38
38
  @consts = {}
39
39
 
40
40
  initial_consts.each_pair do |name, value|
41
- add_const(name, value)
41
+ add_const(name, value)
42
42
  end
43
43
 
44
- # Load utility
44
+ # Load utility
45
45
  end
46
46
 
47
47
  def add_const(name, value)
@@ -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__), '..', '..', '..','..','..','..','..', 'lib'))
4
4
 
5
5
  require 'rex/post/meterpreter/extensions/stdapi/railgun/win_const_manager'
6
6
  require 'test/unit'
@@ -40,14 +40,14 @@ class WinConstManager::UnitTest < Test::Unit::TestCase
40
40
  def test_add_const
41
41
  target_key = 'VALID_KEY'
42
42
  target_value = 23
43
-
43
+
44
44
  const_manager = WinConstManager.new
45
45
 
46
46
  const_manager.add_const(target_key, target_value)
47
47
 
48
48
  assert_equal(target_value, const_manager.parse(target_key),
49
49
  "add_const should add a constant/value pair that can be trieved with parse")
50
-
50
+
51
51
  end
52
52
 
53
53
  def test_initialization
@@ -73,7 +73,7 @@ class WinConstManager::UnitTest < Test::Unit::TestCase
73
73
  "parse should retrieve the corresponding value when a key is provided")
74
74
 
75
75
  # From API: "should not throw an exception given an invalid key"
76
- assert_nothing_thrown do
76
+ assert_nothing_thrown do
77
77
  const_manager.parse(invalid_key)
78
78
  end
79
79
 
@@ -83,7 +83,7 @@ class WinConstManager::UnitTest < Test::Unit::TestCase
83
83
  x_key = 'X'
84
84
  x_value = 228
85
85
  y_key = 'Y'
86
- y_value = 15
86
+ y_value = 15
87
87
 
88
88
  boolean_logic = x_key + ' | ' + y_key
89
89
  target_boolean_logic_result = x_value | y_value
@@ -43,7 +43,7 @@ class Stdapi < Extension
43
43
  # can be directly referenced
44
44
  client.register_extension_aliases(
45
45
  [
46
- {
46
+ {
47
47
  'name' => 'fs',
48
48
  'ext' => ObjectAliases.new(
49
49
  {
@@ -70,7 +70,7 @@ class Stdapi < Extension
70
70
  'config' => Rex::Post::Meterpreter::Extensions::Stdapi::Net::Config.new(client),
71
71
  'socket' => Rex::Post::Meterpreter::Extensions::Stdapi::Net::Socket.new(client)
72
72
  })
73
- },
73
+ },
74
74
  {
75
75
  'name' => 'railgun',
76
76
  'ext' => Rex::Post::Meterpreter::Extensions::Stdapi::Railgun::Railgun.new(client)
@@ -146,4 +146,4 @@ class Stdapi < Extension
146
146
  end
147
147
  end
148
148
 
149
- end; end; end; end; end
149
+ end; end; end; end; end
@@ -16,7 +16,7 @@ module Sys
16
16
 
17
17
  ###
18
18
  #
19
- # This class provides access to the Windows event log on the remote
19
+ # This class provides access to the Windows event log on the remote
20
20
  # machine.
21
21
  #
22
22
  ###
@@ -52,7 +52,7 @@ class EventLog
52
52
  attr_accessor :handle # :nodoc:
53
53
  attr_accessor :client # :nodoc:
54
54
 
55
- public
55
+ public
56
56
 
57
57
  #
58
58
  # Initializes an instance of the eventlog manipulator.
@@ -182,7 +182,7 @@ class EventLog
182
182
  response = client.send_request(request, nil)
183
183
  return nil
184
184
  end
185
-
185
+
186
186
  # Instance method
187
187
  def close
188
188
  self.class.close(self.client, self.handle)
@@ -15,15 +15,15 @@ module EventLogSubsystem
15
15
  ###
16
16
  class EventRecord
17
17
 
18
- attr_reader :num, :generated, :written, :eventid,
19
- :type, :category, :strings, :data
18
+ attr_reader :num, :generated, :written, :eventid
19
+ attr_reader :type, :category, :strings, :data
20
20
 
21
21
  protected
22
22
 
23
- attr_writer :num, :generated, :written, :eventid,
24
- :type, :category, :strings, :data
23
+ attr_writer :num, :generated, :written, :eventid
24
+ attr_writer :type, :category, :strings, :data
25
25
 
26
- public
26
+ public
27
27
 
28
28
  def initialize(recnum, timegen, timewri, id, type, cat, strs, data)
29
29
  self.num = recnum
@@ -38,4 +38,4 @@ class EventRecord
38
38
 
39
39
  end
40
40
 
41
- end end end end end end end
41
+ end end end end end end end
@@ -22,17 +22,17 @@ class Memory
22
22
 
23
23
  # Page protection translation hash
24
24
  @@page_protection_map =
25
- {
25
+ {
26
26
  PROT_NONE => PAGE_NOACCESS,
27
27
  PROT_EXEC => PAGE_EXECUTE,
28
28
  PROT_EXEC | PROT_READ => PAGE_EXECUTE_READ,
29
- PROT_EXEC | PROT_READ |
29
+ PROT_EXEC | PROT_READ |
30
30
  PROT_WRITE => PAGE_EXECUTE_READWRITE,
31
- PROT_EXEC | PROT_READ |
31
+ PROT_EXEC | PROT_READ |
32
32
  PROT_WRITE | PROT_COW => PAGE_EXECUTE_WRITECOPY,
33
33
  PROT_READ => PAGE_READONLY,
34
34
  PROT_READ | PROT_WRITE => PAGE_READWRITE,
35
- PROT_READ | PROT_WRITE |
35
+ PROT_READ | PROT_WRITE |
36
36
  PROT_COW => PAGE_WRITECOPY,
37
37
  PROT_WRITE => PAGE_READWRITE
38
38
  }
@@ -52,10 +52,10 @@ class Memory
52
52
  end
53
53
 
54
54
  #
55
- # Allocate storage of the supplied length and returns the
55
+ # Allocate storage of the supplied length and returns the
56
56
  # address at which the memory was allocated.
57
57
  #
58
- def allocate(length, protection = nil, base = nil)
58
+ def allocate(length, protection = nil, base = nil)
59
59
  allocation_type = MEM_COMMIT
60
60
 
61
61
  # If no protection was supplied, default to the most flexible
@@ -225,7 +225,7 @@ class Memory
225
225
  end
226
226
 
227
227
  #
228
- # Lock a region of memory into physical memory so that it can't be
228
+ # Lock a region of memory into physical memory so that it can't be
229
229
  # swapped to disk. This can only be done in the context of the
230
230
  # process that is running the meterpreter server. The instance's
231
231
  # handle is ignored.
@@ -242,7 +242,7 @@ class Memory
242
242
  end
243
243
 
244
244
  #
245
- # Unloock a region of memory into physical memory so that it can be
245
+ # Unloock a region of memory into physical memory so that it can be
246
246
  # swapped to disk. This can only be done in the context of the
247
247
  # process that is running the meterpreter server. The instance's
248
248
  # handle is ignored.
@@ -322,7 +322,7 @@ protected
322
322
  # Translates specific protection flags to general protection flags.
323
323
  #
324
324
  def specific_prot_to_gen(prot)
325
-
325
+
326
326
  if (prot == nil)
327
327
  return PAGE_READONLY
328
328
  end
@@ -333,4 +333,4 @@ protected
333
333
  attr_accessor :process # :nodoc:
334
334
  end
335
335
 
336
- end; end; end; end; end; end; end
336
+ end; end; end; end; end; end; end
@@ -97,7 +97,7 @@ class Thread
97
97
  request.add_tlv(TLV_TYPE_CREATION_FLAGS, creation_flags)
98
98
 
99
99
  # Transmit the request
100
- response = process.client.send_request(request)
100
+ response = process.client.send_request(request)
101
101
 
102
102
 
103
103
  thread_id = response.get_tlv_value(TLV_TYPE_THREAD_ID)
@@ -138,4 +138,4 @@ protected
138
138
 
139
139
  end
140
140
 
141
- end; end; end; end; end; end; end
141
+ end; end; end; end; end; end; end
@@ -29,7 +29,7 @@ class RegistryKey
29
29
  self.base_key = base_key
30
30
  self.perm = perm
31
31
  self.hkey = hkey
32
-
32
+
33
33
  ObjectSpace.define_finalizer( self, self.class.finalize(self.client, self.hkey) )
34
34
  end
35
35
 
@@ -110,9 +110,9 @@ class RegistryKey
110
110
  return client.sys.registry.close_key(hkey)
111
111
  end
112
112
 
113
- return false
113
+ return false
114
114
  end
115
-
115
+
116
116
  # Instance method for the same
117
117
  def close()
118
118
  self.class.close(self.client, self.hkey)
@@ -28,7 +28,7 @@ class RegistryValue
28
28
  self.name = name
29
29
  self.type = type
30
30
  self.data = data
31
- end
31
+ end
32
32
 
33
33
  #
34
34
  # Sets the value's data.
@@ -99,4 +99,4 @@ protected
99
99
  attr_writer :hkey, :name, :type, :data # :nodoc:
100
100
  end
101
101
 
102
- end; end; end; end; end; end; end
102
+ end; end; end; end; end; end; end
@@ -28,7 +28,7 @@ class RemoteRegistryKey
28
28
  self.root_key = root_key
29
29
  self.target_host = target_host
30
30
  self.hkey = hkey
31
-
31
+
32
32
  ObjectSpace.define_finalizer( self, self.class.finalize(self.client, self.hkey) )
33
33
  end
34
34
 
@@ -109,9 +109,9 @@ class RemoteRegistryKey
109
109
  return client.sys.registry.close_key(hkey)
110
110
  end
111
111
 
112
- return false
112
+ return false
113
113
  end
114
-
114
+
115
115
  # Instance method for the same
116
116
  def close()
117
117
  self.class.close(self.client, self.hkey)
@@ -13,7 +13,7 @@ module Sys
13
13
 
14
14
  ##
15
15
  #
16
- # This class implements the Rex::Post::Thread interface which
16
+ # This class implements the Rex::Post::Thread interface which
17
17
  # wrappers a logical thread for a given process.
18
18
  #
19
19
  ##
@@ -123,7 +123,7 @@ class Thread < Rex::Post::Thread
123
123
  # Add all of the register that we're setting
124
124
  regs_hash.each_key { |name|
125
125
  t = request.add_tlv(TLV_TYPE_REGISTER)
126
-
126
+
127
127
  t.add_tlv(TLV_TYPE_REGISTER_NAME, name)
128
128
  t.add_tlv(TLV_TYPE_REGISTER_VALUE_32, regs_hash[name])
129
129
  }
@@ -139,13 +139,13 @@ class Thread < Rex::Post::Thread
139
139
  def pretty_regs
140
140
  regs = query_regs
141
141
 
142
- buf = sprintf("eax=%.8x ebx=%.8x ecx=%.8x edx=%.8x esi=%.8x edi=%.8x\n",
142
+ buf = sprintf("eax=%.8x ebx=%.8x ecx=%.8x edx=%.8x esi=%.8x edi=%.8x\n",
143
143
  regs['eax'], regs['ebx'], regs['ecx'], regs['edx'], regs['esi'], regs['edi'])
144
144
  buf += sprintf("eip=%.8x esp=%.8x ebp=%.8x\n",
145
145
  regs['eip'], regs['esp'], regs['ebp'])
146
146
  buf += sprintf("cs=%.4x ss=%.4x ds=%.4x es=%.4x fs=%.4x gs=%.4x\n",
147
147
  regs['cs'], regs['ss'], regs['ds'], regs['es'], regs['fs'], regs['gs'])
148
-
148
+
149
149
  return buf
150
150
  end
151
151
 
@@ -165,14 +165,14 @@ class Thread < Rex::Post::Thread
165
165
  handle = nil
166
166
  return true
167
167
  end
168
-
168
+
169
169
  # Instance method
170
170
  def close
171
171
  self.class.close(self.process.client, self.handle)
172
172
  end
173
173
 
174
174
  attr_reader :process, :handle, :tid # :nodoc:
175
- protected
175
+ protected
176
176
  attr_writer :process, :handle, :tid # :nodoc:
177
177
 
178
178
  end