Skip to content

Commit c2efe58

Browse files
committed
small adjustments + separate writing pre2k & non pre2k computers to different files
1 parent 8ebf8fe commit c2efe58

1 file changed

Lines changed: 23 additions & 10 deletions

File tree

nxc/modules/pre2k.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def options(self, context, module_options):
3030

3131
def on_login(self, context, connection):
3232
# Define the search filter
33-
if (self.all_option):
33+
if self.all_option:
3434
search_filter = "(&(objectClass=computer))"
3535
else:
3636
search_filter = "(&(objectClass=computer)(userAccountControl=4128))" # 4128 = 4096 (WORKSTATION_TRUST_ACCOUNT) | 32 (WORKSTATION_TRUST_ACCOUNT)
@@ -55,24 +55,37 @@ def on_login(self, context, connection):
5555

5656
# Save computers to file
5757
domain_dir = os.path.join(f"{NXC_PATH}/modules/pre2k", connection.domain)
58-
output_file = os.path.join(domain_dir, "precreated_computers.txt")
58+
output_file_pre2k = os.path.join(domain_dir, "precreated_computers.txt")
59+
output_file_non_pre2k = os.path.join(domain_dir, "computers.txt")
5960

6061
# Create directories if they do not exist
6162
os.makedirs(domain_dir, exist_ok=True)
6263

63-
with open(output_file, "w") as file:
64-
for computer in computers:
65-
file.write(f"{computer}\n")
64+
with open(output_file_pre2k, "w") as pre2k_file, open(output_file_non_pre2k, "w") as non_pre2k_file:
65+
for computer, uac in computers.items():
66+
if int(uac) == 4128:
67+
pre2k_file.write(f"{computer}\n")
68+
else:
69+
non_pre2k_file.write(f"{computer}\n")
6670

6771
# Print discovered (pre-created) computer accounts
6872
if computers:
6973
for computer, uac in computers.items():
70-
if (int(uac)) == 4128:
74+
if int(uac) == 4128:
7175
context.log.highlight(f"Pre-created computer account: {computer}")
72-
context.log.success(f"Found {len(computers)} pre-created computer accounts. Saved to {output_file}")
7376
else:
74-
context.log.highlight(f"Computer account: {computer}")
75-
context.log.success(f"Found {len(computers)} computer accounts. Saved to {output_file}")
77+
context.log.debug(f"Computer account: {computer}")
78+
79+
counter_pre2k = len([v for v in computers.values() if int(v) == 4128])
80+
counter_non_pre2k = len([v for v in computers.values() if int(v) != 4128])
81+
82+
context.log.success(f"Found {counter_pre2k} pre-created computer accounts. Saved to {output_file_pre2k}")
83+
84+
if counter_non_pre2k == 0:
85+
context.log.fail(f"Found {counter_non_pre2k} computer accounts.")
86+
context.log.display("Consider using the option -o ALL=true to query all computers in the domain")
87+
else:
88+
context.log.success(f"Found {counter_non_pre2k} computer accounts. Saved to {output_file_non_pre2k}")
7689
else:
7790
context.log.info("No pre-created computer accounts found.")
7891

@@ -114,7 +127,7 @@ def get_tgt(self, context, username, domain, kdcHost, ccache_base_dir):
114127
context.log.success(f"Successfully obtained TGT for {username}@{domain}")
115128
return True
116129
except Exception as e:
117-
context.log.fail(f"Failed to get TGT for {username}@{domain}: {e}")
130+
context.log.debug(f"Failed to get TGT for {username}@{domain}: {e}")
118131
return False
119132

120133
def save_ticket(self, context, username, ticket, sessionKey, ccache_base_dir):

0 commit comments

Comments
 (0)