Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[enhancement] Adding column to show if SPN exists in finddelegations.py #1727

Merged
merged 2 commits into from
May 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions examples/findDelegation.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,28 @@
from impacket.smbconnection import SMBConnection, SessionError


def checkIfSPNExists(ldapConnection, sAMAccountName, rights):
# Check if SPN exists
spnExists = "-"
if rights == "N/A":
query = "(servicePrincipalName=HOST/%s)" % sAMAccountName.rstrip("$")
else:
query = "(servicePrincipalName=%s)"%rights

respSpnExists = ldapConnection.search(
searchFilter=query,
attributes=["servicePrincipalName", "distinguishedName"],
sizeLimit=1
)
results = [item for item in respSpnExists if isinstance(item, ldapasn1.SearchResultEntry)]
if len(results) != 0:
spnExists = "Yes"
else:
spnExists = "No"

return spnExists


class FindDelegation:
@staticmethod
def printTable(items, header):
Expand Down Expand Up @@ -225,7 +247,8 @@ def run(self):
logging.debug('Bypassing disabled account %s ' % sAMAccountName)
else:
for rights, objType in zip(rbcdRights,rbcdObjType):
answers.append([rights, objType, 'Resource-Based Constrained', sAMAccountName])
spnExists = checkIfSPNExists(ldapConnection, sAMAccountName, rights)
answers.append([rights, objType, 'Resource-Based Constrained', sAMAccountName, str(spnExists)])

#print unconstrained + constrained delegation relationships
if delegation in ['Unconstrained', 'Constrained', 'Constrained w/ Protocol Transition']:
Expand All @@ -234,13 +257,14 @@ def run(self):
logging.debug('Bypassing disabled account %s ' % sAMAccountName)
else:
for rights in rightsTo:
answers.append([sAMAccountName, objectType, delegation, rights])
spnExists = checkIfSPNExists(ldapConnection, sAMAccountName, rights)
answers.append([sAMAccountName, objectType, delegation, rights, str(spnExists)])
except Exception as e:
logging.error('Skipping item, cannot process due to error %s' % str(e))
pass

if len(answers)>0:
self.printTable(answers, header=[ "AccountName", "AccountType", "DelegationType", "DelegationRightsTo"])
if len(answers) > 0:
self.printTable(answers, header=["AccountName", "AccountType", "DelegationType", "DelegationRightsTo", "SPN Exists"])
print('\n\n')
else:
print("No entries found!")
Expand Down
Loading