Skip to content

Commit f58f8fd

Browse files
committed
tlsdump auxiliary module: update to work on 64-bit Python
1 parent 166aed0 commit f58f8fd

1 file changed

Lines changed: 20 additions & 8 deletions

File tree

analyzer/windows/modules/auxiliary/tlsdump.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,21 @@
33
# See the file 'docs/LICENSE' for copying permission.
44

55
import logging
6-
from ctypes import byref, c_void_p, sizeof
7-
6+
from ctypes import byref, c_bool, c_void_p, sizeof
87
from lib.api.process import Process
98
from lib.common.abstracts import Auxiliary
109
from lib.common.defines import KERNEL32, PROCESSENTRY32, TH32CS_SNAPPROCESS
1110
from lib.common.exceptions import CuckooError
1211

1312
log = logging.getLogger(__name__)
13+
1414
INVALID_HANDLE_VALUE_PTR = c_void_p(-1).value
1515

1616
# Ensure snapshot handle is not truncated on 64-bit.
1717
KERNEL32.CreateToolhelp32Snapshot.restype = c_void_p
18+
# Ensure bool return types are not sign-extended on 64-bit.
19+
KERNEL32.Process32First.restype = c_bool
20+
KERNEL32.Process32Next.restype = c_bool
1821

1922

2023
class TLSDumpMasterSecrets(Auxiliary):
@@ -32,22 +35,33 @@ def __init__(self, options, config):
3235
def start(self):
3336
proc_info = PROCESSENTRY32()
3437
proc_info.dwSize = sizeof(PROCESSENTRY32)
38+
3539
snapshot = KERNEL32.CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)
3640
if snapshot in (None, INVALID_HANDLE_VALUE_PTR):
3741
log.warning("Failed to create process snapshot")
42+
del self.options["tlsdump"]
3843
return
44+
3945
flag = KERNEL32.Process32First(snapshot, byref(proc_info))
4046
pid = 0
47+
4148
while flag:
42-
if proc_info.sz_exeFile == b"lsass.exe":
49+
exename = proc_info.sz_exeFile
50+
if isinstance(exename, bytes):
51+
exename = exename.decode("utf-8", errors="replace")
52+
if exename == "lsass.exe":
4353
pid = proc_info.th32ProcessID
4454
log.info("lsass.exe found, pid %d", pid)
45-
flag = 0
55+
break
4656
flag = KERNEL32.Process32Next(snapshot, byref(proc_info))
57+
4758
KERNEL32.CloseHandle(snapshot)
59+
4860
if not pid:
4961
log.warning("Unable to find lsass.exe process")
62+
del self.options["tlsdump"]
5063
return
64+
5165
try:
5266
p = Process(options=self.options, config=self.config, pid=pid)
5367
filepath = p.get_filepath()
@@ -56,8 +70,6 @@ def start(self):
5670
if "process access denied" in e.message:
5771
log.warning("You're not running the Agent as Administrator")
5872
else:
59-
log.warning(
60-
"An unknown error occurred while trying to inject into the lsass.exe process to dump TLS master secrets: %s",
61-
e,
62-
)
73+
log.warning("An unknown error occurred while trying to inject into the lsass.exe process to dump TLS master secrets: %s", e)
74+
6375
del self.options["tlsdump"]

0 commit comments

Comments
 (0)