Skip to content

Commit 0ff19ac

Browse files
authored
Merge pull request Pennyw0rth#465 from Dfte/Add---shadowrdp-module
Add the shadow RDP module
2 parents 65e2b3f + 87e383f commit 0ff19ac

1 file changed

Lines changed: 83 additions & 0 deletions

File tree

nxc/modules/shadowrdp.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
from impacket.dcerpc.v5 import rrp
2+
from impacket.examples.secretsdump import RemoteOperations
3+
4+
# Module by @Defte_
5+
# Enables or disables shadow RDP
6+
class NXCModule:
7+
name = "shadowrdp"
8+
description = "Enables or disables shadow RDP"
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+
self.action = None
17+
18+
def options(self, context, module_options):
19+
20+
if "ACTION" not in module_options:
21+
context.log.fail("ACTION option not specified!")
22+
exit(1)
23+
24+
if module_options["ACTION"].lower() not in ["enable", "disable"]:
25+
context.log.fail("ACTION must be either enable, disable or query")
26+
exit(1)
27+
self.action = module_options["ACTION"].lower()
28+
29+
def on_admin_login(self, context, connection):
30+
try:
31+
remoteOps = RemoteOperations(connection.conn, False)
32+
remoteOps.enableRegistry()
33+
if remoteOps._RemoteOperations__rrp:
34+
ans = rrp.hOpenLocalMachine(remoteOps._RemoteOperations__rrp)
35+
regHandle = ans["phKey"]
36+
37+
keyHandle = rrp.hBaseRegOpenKey(
38+
remoteOps._RemoteOperations__rrp,
39+
regHandle,
40+
"Software\\Policies\\Microsoft\\Windows NT\\Terminal Services\\"
41+
)['phkResult']
42+
43+
# Checks if the key already exists or not
44+
try:
45+
rrp.hBaseRegQueryValue(
46+
remoteOps._RemoteOperations__rrp,
47+
keyHandle,
48+
"Shadow\x00"
49+
)
50+
except Exception as e:
51+
if "ERROR_FILE_NOT_FOUND" in str(e):
52+
context.log.debug("here")
53+
ans = rrp.hBaseRegCreateKey(
54+
remoteOps._RemoteOperations__rrp,
55+
keyHandle,
56+
"Shadow\x00")
57+
58+
# Disable remote UAC
59+
if self.action == "disable":
60+
rrp.hBaseRegSetValue(
61+
remoteOps._RemoteOperations__rrp,
62+
keyHandle,
63+
"Shadow\x00",
64+
rrp.REG_DWORD,
65+
0
66+
)
67+
context.log.highlight("Shadow RDP disabled")
68+
69+
# Enable remote UAC
70+
if self.action == "enable":
71+
rrp.hBaseRegSetValue(
72+
remoteOps._RemoteOperations__rrp,
73+
keyHandle,
74+
"Shadow\x00",
75+
rrp.REG_DWORD,
76+
2
77+
)
78+
context.log.highlight("Shadow RDP with full access enabled")
79+
80+
except Exception as e:
81+
context.log.debug(f"Error {e}")
82+
finally:
83+
remoteOps.finish()

0 commit comments

Comments
 (0)