Class: Rex::Post::Meterpreter::Extensions::Stdapi::Sys::RegistrySubsystem::RegistryKey
- Inherits:
-
Object
- Object
- Rex::Post::Meterpreter::Extensions::Stdapi::Sys::RegistrySubsystem::RegistryKey
- Defined in:
- lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/registry_key.rb
Overview
Class wrapper around a logical registry key on the remote side
Instance Attribute Summary collapse
-
#base_key ⇒ Object
readonly
The base key name, such as SoftwareFoo.
-
#hkey ⇒ Object
readonly
The open handle to the key on the server.
-
#perm ⇒ Object
readonly
The permissions that the key was opened with.
-
#root_key ⇒ Object
readonly
The root key name, such as HKEY_LOCAL_MACHINE.
Class Method Summary collapse
-
.close(client, hkey) ⇒ Object
Closes the open key.
- .finalize(client, hkey) ⇒ Object
Instance Method Summary collapse
-
#close ⇒ Object
Instance method for the same.
-
#create_key(base_key, perm = KEY_READ) ⇒ Object
Creates a registry key that is relative to this registry key.
-
#delete_key(base_key, recursive = true) ⇒ Object
Deletes a registry key that is relative to this registry key.
-
#delete_value(name) ⇒ Object
Delete the supplied registry value.
-
#each_key(&block) ⇒ Object
Enumerates all of the child keys within this registry key.
-
#each_value(&block) ⇒ Object
Enumerates all of the child values within this registry key.
-
#enum_key ⇒ Object
Retrieves all of the registry keys that are direct descendents of the class’ registry key.
-
#enum_value ⇒ Object
Retrieves all of the registry values that exist within the opened registry key.
-
#initialize(client, root_key, base_key, perm, hkey) ⇒ RegistryKey
constructor
Initializes an instance of a registry key using the supplied properties and HKEY handle from the server.
-
#open_key(base_key, perm = KEY_READ) ⇒ Object
Opens a registry key that is relative to this registry key.
-
#query_class ⇒ Object
Queries the class of the specified key.
-
#query_value(name) ⇒ Object
Queries the attributes of the supplied registry value relative to the opened registry key.
-
#set_value(name, type, data) ⇒ Object
Sets a value relative to the opened registry key.
-
#to_s ⇒ Object
Returns the path to the key.
Constructor Details
#initialize(client, root_key, base_key, perm, hkey) ⇒ RegistryKey
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 35 |
# File 'lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/registry_key.rb', line 26 def initialize(client, root_key, base_key, perm, hkey) self.client = client self.root_key = root_key self.base_key = base_key self.perm = perm 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
#base_key ⇒ Object
The base key name, such as SoftwareFoo.
189 190 191 |
# File 'lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/registry_key.rb', line 189 def base_key @base_key end |
#hkey ⇒ Object
The open handle to the key on the server.
181 182 183 |
# File 'lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/registry_key.rb', line 181 def hkey @hkey end |
#perm ⇒ Object
The permissions that the key was opened with.
193 194 195 |
# File 'lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/registry_key.rb', line 193 def perm @perm end |
#root_key ⇒ Object
The root key name, such as HKEY_LOCAL_MACHINE.
185 186 187 |
# File 'lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/registry_key.rb', line 185 def root_key @root_key end |
Class Method Details
.close(client, hkey) ⇒ Object
Closes the open key. This must be called if the registry key was opened.
109 110 111 112 113 114 115 |
# File 'lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/registry_key.rb', line 109 def self.close(client, hkey) if hkey != nil return client.sys.registry.close_key(hkey) end return false end |
.finalize(client, hkey) ⇒ Object
37 38 39 |
# File 'lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/registry_key.rb', line 37 def self.finalize(client,hkey) proc { self.close(client,hkey) } end |
Instance Method Details
#close ⇒ Object
Instance method for the same
118 119 120 121 122 123 124 |
# File 'lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/registry_key.rb', line 118 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.
94 95 96 |
# File 'lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/registry_key.rb', line 94 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.
101 102 103 |
# File 'lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/registry_key.rb', line 101 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.
157 158 159 |
# File 'lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/registry_key.rb', line 157 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.
50 51 52 |
# File 'lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/registry_key.rb', line 50 def each_key(&block) return enum_key.each(&block) end |
#each_value(&block) ⇒ Object
Enumerates all of the child values within this registry key.
57 58 59 |
# File 'lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/registry_key.rb', line 57 def each_value(&block) return enum_value.each(&block) end |
#enum_key ⇒ Object
Retrieves all of the registry keys that are direct descendents of the class’ registry key.
65 66 67 |
# File 'lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/registry_key.rb', line 65 def enum_key() return self.client.sys.registry.enum_key(self.hkey) end |
#enum_value ⇒ Object
Retrieves all of the registry values that exist within the opened registry key.
73 74 75 |
# File 'lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/registry_key.rb', line 73 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.
87 88 89 |
# File 'lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/registry_key.rb', line 87 def open_key(base_key, perm = KEY_READ) return self.client.sys.registry.open_key(self.hkey, base_key, perm) end |
#query_class ⇒ Object
Queries the class of the specified key
150 151 152 |
# File 'lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/registry_key.rb', line 150 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.
143 144 145 |
# File 'lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/registry_key.rb', line 143 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.
135 136 137 |
# File 'lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/registry_key.rb', line 135 def set_value(name, type, data) return self.client.sys.registry.set_value(self.hkey, name, type, data) end |
#to_s ⇒ Object
Returns the path to the key.
170 171 172 173 174 175 176 |
# File 'lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/registry_key.rb', line 170 def to_s if self.base_key.nil? self.root_key.to_s + "\\" else self.root_key.to_s + "\\" + self.base_key end end |