#stolen from impacket. Thank you all for your wonderful contributions to the communitytry: from Cryptodome.Cipher import ARC4 from Cryptodome.Cipher import DES from Cryptodome.Hash import MD4 except Exception: LOG.critical("Warning: You don't have any crypto installed. You need pycryptodomex") LOG.critical("See https://pypi.org/project/pycryptodomex/")
parser = argparse.ArgumentParser(description="Calculate the Random Session Key based on data from a PCAP (maybe).") parser.add_argument("-u","--user",required=True,help="User name") parser.add_argument("-d","--domain",required=True, help="Domain name") #parser.add_argument("-p","--password",required=True,help="Password of User") parser.add_argument("-H","--hash",required=True,help="NTLM hash of User") parser.add_argument("-n","--ntproofstr",required=True,help="NTProofStr. This can be found in PCAP (provide Hex Stream)") parser.add_argument("-k","--key",required=True,help="Encrypted Session Key. This can be found in PCAP (provide Hex Stream)") parser.add_argument("-v", "--verbose", action="store_true", help="increase output verbosity")
args = parser.parse_args()
#Upper Case User and Domain user = str(args.user).upper().encode('utf-16le') domain = str(args.domain).upper().encode('utf-16le')
#Calculate the ResponseNTKey h = hmac.new(password, digestmod=hashlib.md5) h.update(user+domain) respNTKey = h.digest()
#Use NTProofSTR and ResponseNTKey to calculate Key Excahnge Key NTproofStr = args.ntproofstr.decode('hex') h = hmac.new(respNTKey, digestmod=hashlib.md5) h.update(NTproofStr) KeyExchKey = h.digest()
#Calculate the Random Session Key by decrypting Encrypted Session Key with Key Exchange Key via RC4 RsessKey = generateEncryptedSessionKey(KeyExchKey,args.key.decode('hex'))