Skip to content

Commit

Permalink
Added error checks for wow64 processes
Browse files Browse the repository at this point in the history
  • Loading branch information
Meckazin committed Jan 30, 2024
1 parent b20de8d commit f5edf4c
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 1 deletion.
15 changes: 15 additions & 0 deletions CookieKatz-BOF/ChromeKatz/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,4 +365,19 @@ extern "C" {
}
return TRUE;
}

BOOL IsWow64(HANDLE hProcess) {
BOOL isBrowserWow64 = FALSE;
if (!IsWow64Process(hProcess, &isBrowserWow64)) {
BeaconPrintf(CALLBACK_ERROR, "IsWow64Process failed for browser process, Error: %i\n", GetLastError());
CloseHandle(hProcess);
return TRUE;
}
if (isBrowserWow64) {
CloseHandle(hProcess);
return TRUE;
}

return FALSE;
}
}
11 changes: 11 additions & 0 deletions CookieKatz-BOF/CookieKatzBOF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ extern "C" {
banner();
BeaconPrintf(CALLBACK_OUTPUT, "Kittens love cookies too! >:3\n");

#ifndef _WIN64
BeaconPrintf(CALLBACK_OUTPUT, "32bit version is not currently supported.\n");
return 1;
#endif // !_WIN64

DWORD chromePid = 0;
LPCSTR targetConfig = NULL;
datap parser;
Expand Down Expand Up @@ -127,6 +132,12 @@ extern "C" {
BeaconPrintf(CALLBACK_OUTPUT, "Targeting PID: %d\n", chromePid);
}

if (IsWow64(hChrome))
{
BeaconPrintf(CALLBACK_ERROR, "Target process is 32bit. Only 64bit browsers are supported!\n");
return;
}

uintptr_t baseAddress = 0;
DWORD moduleSize = 0;
if (!GetRemoteModuleBaseAddress(hChrome, dllName, baseAddress, &moduleSize)) {
Expand Down
3 changes: 3 additions & 0 deletions CookieKatz-BOF/DFR.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ DFR(KERNEL32, K32GetModuleBaseNameW)
DFR(KERNEL32, K32GetModuleInformation)
#define K32GetModuleInformation KERNEL32$K32GetModuleInformation

DFR(KERNEL32, IsWow64Process)
#define IsWow64Process KERNEL32$IsWow64Process

DFR(MSVCRT, memcpy)
#define memcpy MSVCRT$memcpy
DFR(MSVCRT, malloc)
Expand Down
5 changes: 5 additions & 0 deletions CookieKatz-BOF/FindChromeProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ extern "C" {
banner();
BeaconPrintf(CALLBACK_OUTPUT, "Kittens love cookies too! >:3\n\n");

#ifndef _WIN64
BeaconPrintf(CALLBACK_OUTPUT, "32bit version is not currently supported.\n");
return 1;
#endif // !_WIN64

datap parser;
BeaconDataParse(&parser, args, len);
if (parser.original == 0)
Expand Down
17 changes: 17 additions & 0 deletions CookieKatz/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ int main(int argc, char* argv[]) {
banner();
printf("Kittens love cookies too!\n\n");

#ifndef _WIN64
printf("[-] 32bit version is not currently supported.\n");
return 1;
#endif // !_WIN64

BOOL chrome = TRUE;
BOOL ProcessList = FALSE;
DWORD pid = 0;
Expand Down Expand Up @@ -97,6 +102,12 @@ int main(int argc, char* argv[]) {
printf("[-] Failed to get process handle to PID: %lu\n", pid);
return 1;
}

if (IsWow64(hChrome))
{
printf("[-] Target process is 32bit. Only 64bit browsers are supported!\n");
return 1;
}
}

LPCWSTR processName;
Expand Down Expand Up @@ -151,6 +162,12 @@ int main(int argc, char* argv[]) {
printf("[-] Failed to find right process\n");
return 1;
}

if (IsWow64(hChrome))
{
printf("[-] Target process is 32bit. Only 64bit browsers are supported!\n");
return 1;
}
}
#ifdef _DEBUG
wprintf(TEXT("[*] Targeting process PID: %d\n"), pid);
Expand Down
16 changes: 16 additions & 0 deletions CookieKatz/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,4 +318,20 @@ BOOL GetProcessHandle(DWORD pid, HANDLE* hProcess) {
}
*hProcess = hHandle;
return TRUE;
}

BOOL IsWow64(HANDLE hProcess) {
BOOL isBrowserWow64 = FALSE;
if (!IsWow64Process(hProcess, &isBrowserWow64)) {
DebugPrintErrorWithMessage(TEXT("IsWow64Process failed for browser process"));
CloseHandle(hProcess);
return TRUE;
}
if (isBrowserWow64) {
DebugPrint(TEXT("[-] Target process is 32bit. Only 64bit browsers are supported!"));
CloseHandle(hProcess);
return TRUE;
}

return FALSE;
}
3 changes: 2 additions & 1 deletion CookieKatz/Process.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ BOOL FindCorrectProcessPID(LPCWSTR processName, DWORD* pid, HANDLE* hProcess);
BOOL GetRemoteModuleBaseAddress(HANDLE hProcess, const wchar_t* moduleName, uintptr_t& baseAddress, DWORD* moduleSize);

BOOL GetProcessHandle(DWORD pid, HANDLE* hProcess);
BOOL GetProcessName(HANDLE hProcess, BOOL& chrome);
BOOL GetProcessName(HANDLE hProcess, BOOL& chrome);
BOOL IsWow64(HANDLE hProcess);

0 comments on commit f5edf4c

Please sign in to comment.