Skip to content

Commit

Permalink
Accept Kerberos standard principal format as credentials information
Browse files Browse the repository at this point in the history
  • Loading branch information
jrisc committed Jan 16, 2024
1 parent ff0f5c4 commit 6516d6f
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions impacket/examples/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
target_regex = re.compile(r"(?:(?:([^/@:]*)/)?([^@:]*)(?::([^@]*))?@)?(.*)")


# Regular expression to parse credentials information
credential_regex = re.compile(r"(?:(?:([^/:]*)/)?([^:]*)(?::(.*))?)?")
# Regular expression to parse Active Directory credentials information
ad_credential_regex = re.compile(r"(?:(?:([^/:]*)/)?([^:]*)(?::(.*))?)?")

# Regular expression to parse standard Kerberos credentials information
krb5_credential_regex = re.compile(r"([^@:]*)@([^/@:]*)(?::(.*))?")

def parse_target(target):
""" Helper function to parse target information. The expected format is:
Expand All @@ -47,6 +49,8 @@ def parse_target(target):
def parse_credentials(credentials):
""" Helper function to parse credentials information. The expected format is:
<USERNAME@><DOMAIN><:PASSWORD>
OR
<DOMAIN></USERNAME><:PASSWORD>
:param credentials: credentials to parse
Expand All @@ -55,6 +59,10 @@ def parse_credentials(credentials):
:return: tuple of domain, username and password
:rtype: (string, string, string)
"""
domain, username, password = credential_regex.match(credentials).groups('')
res = krb5_credential_regex.match(credentials)
if res:
username, domain, password = res.groups('')
else:
domain, username, password = ad_credential_regex.match(credentials).groups('')

return domain, username, password

0 comments on commit 6516d6f

Please sign in to comment.