Skip to content

Commit 83514bf

Browse files
authored
Merge pull request Pennyw0rth#374 from joaovarelas/main
Add module to lookup hostname of Hyper-V host - 'hyperv-host.py'
2 parents 739791e + b9d788b commit 83514bf

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+
"""Module by @joaovarelas"""
8+
9+
name = "hyperv-host"
10+
description = "Performs a registry query on the VM to lookup its HyperV Host"
11+
supported_protocols = ["smb"]
12+
opsec_safe = True
13+
multiple_hosts = True
14+
15+
def __init__(self, context=None, module_options=None):
16+
self.context = context
17+
self.module_options = module_options
18+
19+
def options(self, context, module_options):
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+
try:
29+
remote_ops = RemoteOperations(connection.conn, False)
30+
remote_ops.enableRegistry()
31+
32+
ans = rrp.hOpenLocalMachine(remote_ops._RemoteOperations__rrp)
33+
reg_handle = ans["phKey"]
34+
35+
# Query
36+
try:
37+
ans = rrp.hBaseRegOpenKey(remote_ops._RemoteOperations__rrp, reg_handle, path)
38+
key_handle = ans["phkResult"]
39+
40+
data_type, reg_value = rrp.hBaseRegQueryValue(remote_ops._RemoteOperations__rrp, key_handle, key)
41+
self.context.log.highlight(f"{key}: {reg_value}")
42+
43+
rrp.hBaseRegCloseKey(remote_ops._RemoteOperations__rrp, key_handle)
44+
45+
except DCERPCException as e:
46+
self.context.log.debug(f"Registry key {path}\\{key} does not exist: {e}")
47+
48+
except DCERPCException as e:
49+
self.context.log.fail(f"DCERPC Error while querying registry: {e}")
50+
except Exception as e:
51+
self.context.log.fail(f"Error while querying registry: {e}")
52+
finally:
53+
remote_ops.finish()

0 commit comments

Comments
 (0)