Skip to content

Commit

Permalink
feat: add principalType as new option (#1749)
Browse files Browse the repository at this point in the history
* feat: add principalType as new option

* fix: exception if non exsistent principalType is given
  • Loading branch information
DevSpork authored Aug 22, 2024
1 parent b6713d2 commit 3f5378a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions examples/getTGT.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def saveTicket(self, ticket, sessionKey):
ccache.saveFile(self.__user + '.ccache')

def run(self):
userName = Principal(self.__user, type=constants.PrincipalNameType.NT_PRINCIPAL.value)
userName = Principal(self.__user, type=options.principalType.value)
tgt, cipher, oldSessionKey, sessionKey = getKerberosTGT(clientName = userName,
password = self.__password,
domain = self.__domain,
Expand Down Expand Up @@ -87,14 +87,14 @@ def run(self):
group.add_argument('-dc-ip', action='store',metavar = "ip address", help='IP Address of the domain controller. If '
'ommited it use the domain part (FQDN) specified in the target parameter')
group.add_argument('-service', action='store', metavar="SPN", help='Request a Service Ticket directly through an AS-REQ')
group.add_argument('-principalType', nargs="?", type=lambda value: constants.PrincipalNameType[value.upper()] if value.upper() in constants.PrincipalNameType.__members__ else None, action='store', default=constants.PrincipalNameType.NT_PRINCIPAL, help='PrincipalType of the token, can be one of NT_UNKNOWN, NT_PRINCIPAL, NT_SRV_INST, NT_SRV_HST, NT_SRV_XHST, NT_UID, NT_SMTP_NAME, NT_ENTERPRISE, NT_WELLKNOWN, NT_SRV_HST_DOMAIN, NT_MS_PRINCIPAL, NT_MS_PRINCIPAL_AND_ID, NT_ENT_PRINCIPAL_AND_ID; default is NT_PRINCIPAL, ')

if len(sys.argv)==1:
parser.print_help()
print("\nExamples: ")
print("\t./getTGT.py -hashes lm:nt contoso.com/user\n")
print("\tit will use the lm:nt hashes for authentication. If you don't specify them, a password will be asked")
sys.exit(1)

options = parser.parse_args()

# Init the example's logger theme
Expand All @@ -114,6 +114,10 @@ def run(self):
logging.critical('Domain should be specified!')
sys.exit(1)

if options.principalType is None:
logging.critical('Invalid principalType!')
sys.exit(1)

if password == '' and username != '' and options.hashes is None and options.no_pass is False and options.aesKey is None:
from getpass import getpass
password = getpass("Password:")
Expand Down

0 comments on commit 3f5378a

Please sign in to comment.