Skip to content

Commit 6135e12

Browse files
authored
Merge pull request Pennyw0rth#464 from Dfte/Add---remoteuac-module
Create remote-uac.py
2 parents c1e1205 + 62afd52 commit 6135e12

1 file changed

Lines changed: 65 additions & 0 deletions

File tree

nxc/modules/remote-uac.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
from impacket.dcerpc.v5 import rrp
2+
from impacket.examples.secretsdump import RemoteOperations
3+
4+
5+
class NXCModule:
6+
"""Module by @Defte_"""
7+
name = "remote-uac"
8+
description = "Enable or disable remote UAC"
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+
Enables UAC (prevent non RID500 account to get high priv token remotely)
21+
Disables UAC (allow non RID500 account to get high priv token remotely)
22+
23+
ACTION: "enable" or "disable" (required)
24+
"""
25+
if "ACTION" not in module_options:
26+
context.log.fail("ACTION option not specified!")
27+
return
28+
29+
if module_options["ACTION"].lower() not in ["enable", "disable"]:
30+
context.log.fail("ACTION must be either enable, disable or query")
31+
return
32+
self.action = module_options["ACTION"].lower()
33+
34+
def on_admin_login(self, context, connection):
35+
try:
36+
remoteOps = RemoteOperations(connection.conn, False)
37+
remoteOps.enableRegistry()
38+
if remoteOps._RemoteOperations__rrp:
39+
ans = rrp.hOpenLocalMachine(remoteOps._RemoteOperations__rrp)
40+
regHandle = ans["phKey"]
41+
42+
keyHandle = rrp.hBaseRegOpenKey(remoteOps._RemoteOperations__rrp, regHandle, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System")["phkResult"]
43+
44+
# Checks if the key already exists or not
45+
try:
46+
rrp.hBaseRegQueryValue(remoteOps._RemoteOperations__rrp, keyHandle, "LocalAccountTokenFilterPolicy\x00")
47+
except Exception as e:
48+
if "ERROR_FILE_NOT_FOUND" in str(e):
49+
context.log.debug("Registry key 'LocalAccountTokenFilterPolicy' does not exist, creating it")
50+
ans = rrp.hBaseRegCreateKey(remoteOps._RemoteOperations__rrp, keyHandle, "LocalAccountTokenFilterPolicy\x00")
51+
52+
# Disable remote UAC
53+
if self.action == "disable":
54+
rrp.hBaseRegSetValue(remoteOps._RemoteOperations__rrp, keyHandle, "LocalAccountTokenFilterPolicy\x00", rrp.REG_DWORD, 1)
55+
context.log.highlight("Remote UAC disabled")
56+
57+
# Enable remote UAC
58+
if self.action == "enable":
59+
rrp.hBaseRegSetValue(remoteOps._RemoteOperations__rrp, keyHandle, "LocalAccountTokenFilterPolicy\x00", rrp.REG_DWORD, 0)
60+
context.log.highlight("Remote UAC enabled")
61+
62+
except Exception as e:
63+
context.log.debug(f"Error {e}")
64+
finally:
65+
remoteOps.finish()

0 commit comments

Comments
 (0)