# This file is part of creddump. # # creddump is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # creddump is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with creddump. If not, see . """ @author: Brendan Dolan-Gavitt @license: GNU General Public License 2.0 or later @contact: bdolangavitt@wesleyan.edu """ from framework.win32.rawreg import * from framework.addrspace import HiveFileAddressSpace from framework.win32.hashdump import get_bootkey from framework.win32.lsasecrets import get_secret_by_name,get_lsa_key from Crypto.Hash import HMAC from Crypto.Cipher import ARC4, AES from struct import unpack def get_nlkm(secaddr, lsakey, vista): return get_secret_by_name(secaddr, 'NL$KM', lsakey, vista) def decrypt_hash(edata, nlkm, ch): hmac_md5 = HMAC.new(nlkm,ch) rc4key = hmac_md5.digest() rc4 = ARC4.new(rc4key) data = rc4.encrypt(edata) return data def decrypt_hash_vista(edata, nlkm, ch): """ Based on code from http://lab.mediaservice.net/code/cachedump.rb """ aes = AES.new(nlkm[16:32], AES.MODE_CBC, ch) out = bytearray() for i in range(0, len(edata), 16): buf = edata[i : i+16] if len(buf) < 16: buf += (16 - len(buf)) * b"\00" out += aes.decrypt(buf) return out def parse_cache_entry(cache_data): (uname_len, domain_len) = unpack("