Skip to content

Commit 5d8a629

Browse files
committed
Extract no-preauth-roasting into separate function
1 parent 5b489b5 commit 5d8a629

1 file changed

Lines changed: 39 additions & 36 deletions

File tree

nxc/protocols/ldap.py

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -965,42 +965,7 @@ def asreproast(self):
965965

966966
def kerberoasting(self):
967967
if self.args.no_preauth_targets:
968-
usernames = []
969-
for item in self.args.no_preauth_targets:
970-
if os.path.isfile(item):
971-
with open(item, encoding="utf-8") as f:
972-
usernames.extend(line.strip() for line in f if line.strip())
973-
else:
974-
usernames.append(item.strip())
975-
976-
skipped = []
977-
hashes = []
978-
979-
for spn in usernames:
980-
base_name = spn.split("/", 1)[0].split("@", 1)[0].rstrip()
981-
982-
if base_name.lower() == "krbtgt" or base_name.endswith("$"):
983-
skipped.append(base_name)
984-
continue
985-
986-
if not self.username:
987-
self.logger.fail("Likely executed without password flag. Please run the command with -p ''")
988-
return
989-
hashline = KerberosAttacks(self).get_tgs_no_preauth(self.username, spn)
990-
if hashline:
991-
hashes.append(hashline)
992-
993-
if skipped:
994-
self.logger.display(f"Skipping account: {', '.join(skipped)}")
995-
if hashes:
996-
self.logger.display(f"Total of records returned {len(hashes)}")
997-
else:
998-
self.logger.highlight("No entries found!")
999-
1000-
for line in hashes:
1001-
self.logger.highlight(line)
1002-
with open(self.args.kerberoasting, "a+", encoding="utf-8") as f:
1003-
f.write(line + "\n")
968+
self.roast_no_preauth()
1004969
return
1005970

1006971
if self.args.targeted_kerberoast:
@@ -1200,6 +1165,44 @@ def kerberoasting(self):
12001165
else:
12011166
self.logger.fail(f"Error retrieving TGT for {self.domain}\\{self.username} from {self.kdcHost}")
12021167

1168+
def roast_no_preauth(self):
1169+
usernames = []
1170+
for item in self.args.no_preauth_targets:
1171+
if os.path.isfile(item):
1172+
with open(item, encoding="utf-8") as f:
1173+
usernames.extend(line.strip() for line in f if line.strip())
1174+
else:
1175+
usernames.append(item.strip())
1176+
1177+
skipped = []
1178+
hashes = []
1179+
1180+
for spn in usernames:
1181+
base_name = spn.split("/", 1)[0].split("@", 1)[0].rstrip()
1182+
1183+
if base_name.lower() == "krbtgt" or base_name.endswith("$"):
1184+
skipped.append(base_name)
1185+
continue
1186+
1187+
if not self.username:
1188+
self.logger.fail("Likely executed without password flag. Please run the command with -p ''")
1189+
return
1190+
hashline = KerberosAttacks(self).get_tgs_no_preauth(self.username, spn)
1191+
if hashline:
1192+
hashes.append(hashline)
1193+
1194+
if skipped:
1195+
self.logger.display(f"Skipping account: {', '.join(skipped)}")
1196+
if hashes:
1197+
self.logger.display(f"Total of records returned {len(hashes)}")
1198+
else:
1199+
self.logger.highlight("No entries found!")
1200+
1201+
for line in hashes:
1202+
self.logger.highlight(line)
1203+
with open(self.args.kerberoasting, "a+", encoding="utf-8") as f:
1204+
f.write(line + "\n")
1205+
12031206
def query(self):
12041207
"""
12051208
Query the LDAP server with the specified filter and attributes.

0 commit comments

Comments
 (0)