Skip to content

Commit

Permalink
[enhancement] Adding column to show if SPN exists in finddelegations.…
Browse files Browse the repository at this point in the history
…py (#1727)

* Added a SPN column to check for existence

* Created checkIfSPNExists() function
  • Loading branch information
p0dalirius committed May 23, 2024
1 parent 452ca84 commit 15eff88
Showing 1 changed file with 28 additions and 4 deletions.
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

1 comment on commit 15eff88

@GeisericII
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello! Would it be possible to slightly modify the findDelegation script to include RBCD over domain controllers? At the moment it's not being displayed, as shown in the following screenshot:
immagine

Moreover, I've noticed that SPNs do not seem to be corretly parsed:
immagine

I really like the idea of showing the SPNs! @p0dalirius

Please sign in to comment.