Skip to content

Commit b3b38d9

Browse files
committed
Move trigger_winreg to smb protocol
1 parent f17cc9c commit b3b38d9

4 files changed

Lines changed: 29 additions & 76 deletions

File tree

nxc/modules/backup_operator.py

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import time
21
import os
32
import datetime
43

@@ -30,7 +29,7 @@ def on_login(self, context, connection):
3029
connection.args.share = "SYSVOL"
3130
# enable remote registry
3231
context.log.display("Triggering RemoteRegistry to start through named pipe...")
33-
self.trigger_winreg(connection.conn, context)
32+
connection.trigger_winreg()
3433
rpc = transport.DCERPCTransportFactory(r"ncacn_np:445[\pipe\winreg]")
3534
rpc.set_smb_connection(connection.conn)
3635
if connection.kerberos:
@@ -115,29 +114,3 @@ def parse_sam(secret):
115114
context.log.display("netexec smb dc_ip -u user -p pass -x \"del C:\\Windows\\sysvol\\sysvol\\SECURITY && del C:\\Windows\\sysvol\\sysvol\\SAM && del C:\\Windows\\sysvol\\sysvol\\SYSTEM\"") # noqa: Q003
116115
else:
117116
context.log.display("Successfully deleted dump files !")
118-
119-
def trigger_winreg(self, connection, context):
120-
# Original idea from https://twitter.com/splinter_code/status/1715876413474025704
121-
# Basically triggers the RemoteRegistry to start without admin privs
122-
tid = connection.connectTree("IPC$")
123-
try:
124-
connection.openFile(
125-
tid,
126-
r"\winreg",
127-
0x12019F,
128-
creationOption=0x40,
129-
fileAttributes=0x80,
130-
)
131-
except SessionError as e:
132-
# STATUS_PIPE_NOT_AVAILABLE error is expected
133-
context.log.debug(str(e))
134-
# Give remote registry time to start
135-
time.sleep(1)
136-
137-
def _strip_root_key(self, dce, key_name):
138-
# Let's strip the root key
139-
key_name.split("\\")[0]
140-
sub_key = "\\".join(key_name.split("\\")[1:])
141-
ans = rrp.hOpenLocalMachine(dce)
142-
h_root_key = ans["phKey"]
143-
return h_root_key, sub_key

nxc/modules/ntlm_reflection.py

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def on_login(self, context, connection):
5050
self.context = context
5151
self.connection = connection
5252
if not connection.conn.isSigningRequired(): # Not vulnerable if SMB signing is enabled
53-
self.trigger_winreg(connection.conn, context)
53+
connection.trigger_winreg()
5454
rpc = transport.DCERPCTransportFactory(r"ncacn_np:445[\pipe\winreg]")
5555
rpc.set_smb_connection(connection.conn)
5656
if connection.kerberos:
@@ -80,29 +80,3 @@ def on_login(self, context, connection):
8080
self.context.log.debug(f"Unexpected error: {e}")
8181
except (BrokenPipeError, ConnectionResetError, NetBIOSError, OSError) as e:
8282
context.log.debug(f"ntlm_reflection: DCERPC transport error: {e.__class__.__name__}: {e}")
83-
84-
def trigger_winreg(self, connection, context):
85-
# Original idea from https://twitter.com/splinter_code/status/1715876413474025704
86-
# Basically triggers the RemoteRegistry to start without admin privs
87-
try:
88-
tid = connection.connectTree("IPC$")
89-
try:
90-
connection.openFile(
91-
tid,
92-
r"\winreg",
93-
0x12019F,
94-
creationOption=0x40,
95-
fileAttributes=0x80,
96-
)
97-
except SessionError as e:
98-
# STATUS_PIPE_NOT_AVAILABLE error is expected
99-
if "STATUS_PIPE_NOT_AVAILABLE" not in str(e):
100-
raise
101-
else:
102-
context.log.debug(f"Received expected error while triggering winreg: {e}")
103-
# Give remote registry time to start
104-
time.sleep(1)
105-
return True
106-
except (SessionError, BrokenPipeError, ConnectionResetError, NetBIOSError, OSError) as e:
107-
context.log.debug(f"Received unexpected error while triggering winreg: {e}")
108-
return False

nxc/modules/sccm-recon6.py

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11

2-
import time
32
from impacket.dcerpc.v5 import transport, rrp
43
from impacket.dcerpc.v5.rpcrt import RPC_C_AUTHN_GSS_NEGOTIATE
54
from impacket.dcerpc.v5.rpcrt import DCERPCException
6-
from impacket.smbconnection import SessionError
75
from nxc.helpers.misc import CATEGORY
86
from impacket.smbconnection import SMBConnection
97

@@ -23,7 +21,7 @@ def on_login(self, context, connection):
2321
self.context = context
2422
self.connection = connection
2523

26-
self.trigger_winreg(connection.conn, context)
24+
connection.trigger_winreg()
2725

2826
rpc = transport.DCERPCTransportFactory(r"ncacn_np:445[\pipe\winreg]")
2927
rpc.set_smb_connection(connection.conn)
@@ -130,21 +128,3 @@ def EnumerateDB(self, dce, hRootKey):
130128
self.context.log.display(f" SMB signing: {new_conn.isSigningRequired()}")
131129
else:
132130
self.context.log.highlight(f" SMB signing: {new_conn.isSigningRequired()} - TAKEOVER-2")
133-
134-
def trigger_winreg(self, connection, context):
135-
# Original idea from https://twitter.com/splinter_code/status/1715876413474025704
136-
# Basically triggers the RemoteRegistry to start without admin privs
137-
tid = connection.connectTree("IPC$")
138-
try:
139-
connection.openFile(
140-
tid,
141-
r"\winreg",
142-
0x12019F,
143-
creationOption=0x40,
144-
fileAttributes=0x80,
145-
)
146-
except SessionError as e:
147-
# STATUS_PIPE_NOT_AVAILABLE error is expected
148-
context.log.debug(str(e))
149-
# Give remote registry time to start
150-
time.sleep(1)

nxc/protocols/smb.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,32 @@ def _is_port_open(self, port, timeout=1):
735735
self.logger.debug(f"Error checking port {port} on {self.host}: {e}")
736736
return False
737737

738+
def trigger_winreg(self):
739+
# Original idea from https://twitter.com/splinter_code/status/1715876413474025704
740+
# Basically triggers the RemoteRegistry to start without admin privs
741+
try:
742+
tid = self.conn.connectTree("IPC$")
743+
try:
744+
self.conn.openFile(
745+
tid,
746+
r"\winreg",
747+
0x12019F,
748+
creationOption=0x40,
749+
fileAttributes=0x80,
750+
)
751+
except SessionError as e:
752+
# STATUS_PIPE_NOT_AVAILABLE error is expected
753+
if "STATUS_PIPE_NOT_AVAILABLE" not in str(e):
754+
raise
755+
else:
756+
self.logger.debug(f"Received expected error while triggering winreg: {e}")
757+
# Give remote registry time to start
758+
sleep(1)
759+
return True
760+
except (SessionError, BrokenPipeError, ConnectionResetError, NetBIOSError, OSError) as e:
761+
self.logger.debug(f"Received unexpected error while triggering winreg: {e}")
762+
return False
763+
738764
@requires_admin
739765
def execute(self, payload=None, get_output=False, methods=None) -> str:
740766
"""

0 commit comments

Comments
 (0)