Skip to content

Commit 8a6fb7c

Browse files
committed
add module hyperv-host.py
1 parent 3a5c109 commit 8a6fb7c

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

nxc/modules/hyperv-host.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
from impacket.dcerpc.v5.rpcrt import DCERPCException
2+
from impacket.dcerpc.v5 import rrp
3+
from impacket.examples.secretsdump import RemoteOperations
4+
5+
6+
class NXCModule:
7+
name = "hyperv-host"
8+
description = "Performs a registry query on the VM to lookup its HyperV Host"
9+
supported_protocols = ["smb"]
10+
opsec_safe = True
11+
multiple_hosts = True
12+
13+
def __init__(self, context=None, module_options=None):
14+
self.context = context
15+
self.module_options = module_options
16+
17+
18+
def options(self, context, module_options):
19+
""""""
20+
21+
22+
def on_admin_login(self, context, connection):
23+
self.context = context
24+
25+
path = "SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters"
26+
key = "HostName"
27+
28+
remote_ops = RemoteOperations(connection.conn, False)
29+
remote_ops.enableRegistry()
30+
31+
try:
32+
ans = rrp.hOpenLocalMachine(remote_ops._RemoteOperations__rrp)
33+
reg_handle = ans["phKey"]
34+
35+
ans = rrp.hBaseRegOpenKey(remote_ops._RemoteOperations__rrp, reg_handle, path)
36+
key_handle = ans["phkResult"]
37+
38+
# Query
39+
try:
40+
data_type, reg_value = rrp.hBaseRegQueryValue(remote_ops._RemoteOperations__rrp, key_handle, key)
41+
self.context.log.highlight(f"{key}: {reg_value}")
42+
except Exception:
43+
self.context.log.fail(f"Registry key {path}\\{key} does not exist")
44+
return
45+
46+
rrp.hBaseRegCloseKey(remote_ops._RemoteOperations__rrp, key_handle)
47+
except DCERPCException as e:
48+
self.context.log.fail(f"DCERPC Error while querying or modifying registry: {e}")
49+
except Exception as e:
50+
self.context.log.fail(f"Error while querying or modifying registry: {e}")
51+
finally:
52+
remote_ops.finish()
53+

0 commit comments

Comments
 (0)