Class: Rex::Post::Meterpreter::Extensions::Stdapi::Sys::RegistrySubsystem::RemoteRegistryKey

Inherits:
Object
  • Object
show all
Defined in:
lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/remote_registry_key.rb

Overview

Class wrapper around a remote registry key on the remote side

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, target_host, root_key, hkey) ⇒ RemoteRegistryKey

Initializes an instance of a registry key using the supplied properties and HKEY handle from the server.


26
27
28
29
30
31
32
33
34
# File 'lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/remote_registry_key.rb', line 26

def initialize(client, target_host, root_key, hkey)
  self.client   = client
  self.root_key = root_key
  self.target_host = target_host
  self.hkey     = hkey

  # Ensure the remote object is closed when all references are removed
  ObjectSpace.define_finalizer(self, self.class.finalize(client, hkey))
end

Instance Attribute Details

#clientObject (protected)

:nodoc:


188
189
190
# File 'lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/remote_registry_key.rb', line 188

def client
  @client
end

#hkeyObject

The open handle to the key on the server.


176
177
178
# File 'lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/remote_registry_key.rb', line 176

def hkey
  @hkey
end

#root_keyObject

The root key name, such as HKEY_LOCAL_MACHINE.


180
181
182
# File 'lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/remote_registry_key.rb', line 180

def root_key
  @root_key
end

#target_hostObject

The remote machine name, such as PDC01


184
185
186
# File 'lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/remote_registry_key.rb', line 184

def target_host
  @target_host
end

Class Method Details

.close(client, hkey) ⇒ Object

Closes the open key. This must be called if the registry key was opened.


108
109
110
111
112
113
114
# File 'lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/remote_registry_key.rb', line 108

def self.close(client, hkey)
  if hkey != nil
    return client.sys.registry.close_key(hkey)
  end

  return false
end

.finalize(client, hkey) ⇒ Object


36
37
38
# File 'lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/remote_registry_key.rb', line 36

def self.finalize(client, hkey)
  proc { self.close(client, hkey) }
end

Instance Method Details

#closeObject

Instance method for the same


117
118
119
120
121
122
123
# File 'lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/remote_registry_key.rb', line 117

def close
  unless self.hkey.nil?
    ObjectSpace.undefine_finalizer(self)
    self.class.close(self.client, self.hkey)
    self.hkey = nil
  end
end

#create_key(base_key, perm = KEY_READ) ⇒ Object

Creates a registry key that is relative to this registry key.


93
94
95
# File 'lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/remote_registry_key.rb', line 93

def create_key(base_key, perm = KEY_READ)
  return self.client.sys.registry.create_key(self.hkey, base_key, perm)
end

#delete_key(base_key, recursive = true) ⇒ Object

Deletes a registry key that is relative to this registry key.


100
101
102
# File 'lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/remote_registry_key.rb', line 100

def delete_key(base_key, recursive = true)
  return self.client.sys.registry.delete_key(self.hkey, base_key, recursive)
end

#delete_value(name) ⇒ Object

Delete the supplied registry value.


156
157
158
# File 'lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/remote_registry_key.rb', line 156

def delete_value(name)
  return self.client.sys.registry.delete_value(self.hkey, name)
end

#each_key(&block) ⇒ Object

Enumerates all of the child keys within this registry key.


49
50
51
# File 'lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/remote_registry_key.rb', line 49

def each_key(&block)
  return enum_key.each(&block)
end

#each_value(&block) ⇒ Object

Enumerates all of the child values within this registry key.


56
57
58
# File 'lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/remote_registry_key.rb', line 56

def each_value(&block)
  return enum_value.each(&block)
end

#enum_keyObject

Retrieves all of the registry keys that are direct descendents of the class' registry key.


64
65
66
# File 'lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/remote_registry_key.rb', line 64

def enum_key()
  return self.client.sys.registry.enum_key(self.hkey)
end

#enum_valueObject

Retrieves all of the registry values that exist within the opened registry key.


72
73
74
# File 'lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/remote_registry_key.rb', line 72

def enum_value()
  return self.client.sys.registry.enum_value(self.hkey)
end

#open_key(base_key, perm = KEY_READ) ⇒ Object

Opens a registry key that is relative to this registry key.


86
87
88
# File 'lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/remote_registry_key.rb', line 86

def open_key(base_key, perm = KEY_READ)
  return self.client.sys.registry.open_key(self.hkey, base_key, perm)
end

#query_classObject

Queries the class of the specified key


149
150
151
# File 'lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/remote_registry_key.rb', line 149

def query_class
  return self.client.sys.registry.query_class(self.hkey)
end

#query_value(name) ⇒ Object

Queries the attributes of the supplied registry value relative to the opened registry key.


142
143
144
# File 'lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/remote_registry_key.rb', line 142

def query_value(name)
  return self.client.sys.registry.query_value(self.hkey, name)
end

#set_value(name, type, data) ⇒ Object

Sets a value relative to the opened registry key.


134
135
136
# File 'lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/remote_registry_key.rb', line 134

def set_value(name, type, data)
  return self.client.sys.registry.set_value(self.hkey, name, type, data)
end

#to_sObject

Returns the path to the key.


169
170
171
# File 'lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/remote_registry_key.rb', line 169

def to_s
  return "\\\\" + self.target_host + "\\" + self.root_key.to_s + "\\"
end