Skip to content

Commit cc7d8aa

Browse files
committed
Wrap critical parts into try&except
1 parent 5e2ec73 commit cc7d8aa

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

nxc/modules/sccm-recon6.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

2+
import contextlib
23
from impacket.dcerpc.v5 import transport, rrp
34
from impacket.dcerpc.v5.rpcrt import RPC_C_AUTHN_GSS_NEGOTIATE
45
from impacket.dcerpc.v5.rpcrt import DCERPCException
@@ -31,14 +32,15 @@ def on_login(self, context, connection):
3132
dce = rpc.get_dce_rpc()
3233
if connection.kerberos:
3334
dce.set_auth_type(RPC_C_AUTHN_GSS_NEGOTIATE)
34-
dce.connect()
35-
dce.bind(rrp.MSRPC_UUID_RRP)
36-
37-
# Open HKEY_LOCAL_MACHINE
38-
ans = rrp.hOpenLocalMachine(dce)
39-
hRootKey = ans["phKey"]
4035

4136
try:
37+
dce.connect()
38+
dce.bind(rrp.MSRPC_UUID_RRP)
39+
40+
# Open HKEY_LOCAL_MACHINE
41+
ans = rrp.hOpenLocalMachine(dce)
42+
hRootKey = ans["phKey"]
43+
4244
self.EnumerateSS(dce, hRootKey)
4345
try:
4446
self.EnumerateDB(dce, hRootKey)
@@ -49,8 +51,12 @@ def on_login(self, context, connection):
4951
self.context.log.info(f"Probably not a primary site server or a distribution point: {e}")
5052
else:
5153
self.context.log.fail(f"Unexpected error: {e}")
54+
except Exception as e:
55+
self.context.log.fail(f"Unexpected error: {e}")
5256

53-
dce.disconnect()
57+
finally:
58+
with contextlib.suppress(Exception):
59+
dce.disconnect()
5460

5561
def EnumerateSS(self, dce, hRootKey):
5662
# Open the target registry key

0 commit comments

Comments
 (0)