Skip to content

Commit f6436fd

Browse files
authored
Create remoteuac.py
Signed-off-by: Deft_ <aurelien.chalot@protonmail.com>
1 parent 95ac371 commit f6436fd

1 file changed

Lines changed: 84 additions & 0 deletions

File tree

nxc/modules/remoteuac.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
from impacket.dcerpc.v5 import rrp
2+
from impacket.examples.secretsdump import RemoteOperations
3+
4+
# Module by @Defte_
5+
# Enables UAC (prevent non RID500 account to get high priv token remotely)
6+
# Disables UAC (allow non RID500 account to get high priv token remotely)
7+
class NXCModule:
8+
name = "remoteuac"
9+
description = "Enable or disable remote UAC"
10+
supported_protocols = ["smb"]
11+
opsec_safe = True
12+
multiple_hosts = True
13+
14+
def __init__(self, context=None, module_options=None):
15+
self.context = context
16+
self.module_options = module_options
17+
self.action = None
18+
19+
def options(self, context, module_options):
20+
21+
if "ACTION" not in module_options:
22+
context.log.fail("ACTION option not specified!")
23+
exit(1)
24+
25+
if module_options["ACTION"].lower() not in ["enable", "disable"]:
26+
context.log.fail("ACTION must be either enable, disable or query")
27+
exit(1)
28+
self.action = module_options["ACTION"].lower()
29+
30+
def on_admin_login(self, context, connection):
31+
try:
32+
remoteOps = RemoteOperations(connection.conn, False)
33+
remoteOps.enableRegistry()
34+
if remoteOps._RemoteOperations__rrp:
35+
ans = rrp.hOpenLocalMachine(remoteOps._RemoteOperations__rrp)
36+
regHandle = ans["phKey"]
37+
38+
keyHandle = rrp.hBaseRegOpenKey(
39+
remoteOps._RemoteOperations__rrp,
40+
regHandle,
41+
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System"
42+
)['phkResult']
43+
44+
# Checks if the key already exists or not
45+
try:
46+
rrp.hBaseRegQueryValue(
47+
remoteOps._RemoteOperations__rrp,
48+
keyHandle,
49+
"LocalAccountTokenFilterPolicy\x00"
50+
)
51+
except Exception as e:
52+
if "ERROR_FILE_NOT_FOUND" in str(e):
53+
context.log.debug("here")
54+
ans = rrp.hBaseRegCreateKey(
55+
remoteOps._RemoteOperations__rrp,
56+
keyHandle,
57+
"LocalAccountTokenFilterPolicy\x00")
58+
59+
# Disable remote UAC
60+
if self.action == "disable":
61+
rrp.hBaseRegSetValue(
62+
remoteOps._RemoteOperations__rrp,
63+
keyHandle,
64+
"LocalAccountTokenFilterPolicy\x00",
65+
rrp.REG_DWORD,
66+
1
67+
)
68+
context.log.highlight("Remote UAC disabled")
69+
70+
# Enable remote UAC
71+
if self.action == "enable":
72+
rrp.hBaseRegSetValue(
73+
remoteOps._RemoteOperations__rrp,
74+
keyHandle,
75+
"LocalAccountTokenFilterPolicy\x00",
76+
rrp.REG_DWORD,
77+
0
78+
)
79+
context.log.highlight("Remote UAC enabled")
80+
81+
except Exception as e:
82+
context.log.debug(f"Error {e}")
83+
finally:
84+
remoteOps.finish()

0 commit comments

Comments
 (0)