Skip to content

Commit a472f49

Browse files
bhanunamikzebhanunamikze
authored andcommitted
fix: resolve silent BOF crash — add missing DFR declarations
Root cause: 3 unresolved imports caused Cobalt Strike to silently crash all BOFs before go() could execute: - GetSidSubAuthority/GetSidSubAuthorityCount called without ADVAPI32$ DFR prefix in helpers.c is_high_integrity() - NdrClientCall2 from RPCRT4 used by bkrp.c but never declared in bofdefs.h Since these were in common libraries linked into every BOF via ld -r, all 19 BOFs were affected. Fixes: - bofdefs.h: Add ADVAPI32, ADVAPI32, RPCRT4 DFR decls - helpers.c: Use ADVAPI32$ prefix for SID functions in BOF code path - bkrp.h: Remove duplicate NdrClientCall2 decl (now in bofdefs.h) - dpapi.cna: Fix keepass substr offset (7 -> 8)
1 parent 2c01b16 commit a472f49

File tree

5 files changed

+8
-11
lines changed

5 files changed

+8
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
**SharpDPAPI** ported to **Cobalt Strike Beacon Object Files (BOFs)** - 19 self-contained BOFs for DPAPI credential triage, all under 52KB each.
44

5-
> Full port of [GhostPack/SharpDPAPI](https://github.com/GhostPack/SharpDPAPI) by @harmj0y - including MS-BKRP RPC masterkey decryption, Chrome/Edge/Brave credential extraction, and machine-level DPAPI triage.
5+
> Full port of [GhostPack/SharpDPAPI](https://github.com/GhostPack/SharpDPAPI) - including MS-BKRP RPC masterkey decryption, Chrome/Edge/Brave credential extraction, and machine-level DPAPI triage.
66
77
---
88

dpapi.cna

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ beacon_command_register(
243243
alias keepass {
244244
local('%args $data $bid');
245245
$bid = $1;
246-
%args = _parse_args(substr($0, 7));
246+
%args = _parse_args(substr($0, 8));
247247

248248
$data = _load_bof("keepass");
249249
$args = bof_pack($bid, "zzzzzii",

include/bkrp.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,8 @@
1313

1414
#include "bofdefs.h"
1515

16-
/* ---- DFR for NdrClientCall2 (only declared here, not in bofdefs.h) ---- */
17-
#ifndef BKRP_NDRCLIENTCALL2_DECLARED
18-
#define BKRP_NDRCLIENTCALL2_DECLARED
19-
DECLSPEC_IMPORT void* CDECL RPCRT4$NdrClientCall2(
20-
void* pStubDescriptor, void* pFormat, ...);
21-
#endif
22-
2316
/* ---- Public API ---- */
17+
/* NdrClientCall2 DFR is declared in bofdefs.h */
2418

2519
/*
2620
* bkrp_decrypt_masterkey — Decrypt a masterkey's domain key via MS-BKRP RPC

include/bofdefs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ DECLSPEC_IMPORT LONG WINAPI ADVAPI32$RegCloseKey(HKEY);
197197
DECLSPEC_IMPORT BOOL WINAPI ADVAPI32$IsTextUnicode(const VOID*, int, LPINT);
198198
DECLSPEC_IMPORT BOOL WINAPI ADVAPI32$GetTokenInformation(HANDLE, TOKEN_INFORMATION_CLASS, LPVOID, DWORD, PDWORD);
199199
DECLSPEC_IMPORT BOOL WINAPI ADVAPI32$ConvertSidToStringSidW(PSID, LPWSTR*);
200+
DECLSPEC_IMPORT PDWORD WINAPI ADVAPI32$GetSidSubAuthority(PSID, DWORD);
201+
DECLSPEC_IMPORT PUCHAR WINAPI ADVAPI32$GetSidSubAuthorityCount(PSID);
200202

201203
/* --- ncrypt.dll --- */
202204
DECLSPEC_IMPORT SECURITY_STATUS WINAPI NCRYPT$NCryptOpenStorageProvider(NCRYPT_PROV_HANDLE*, LPCWSTR, DWORD);
@@ -245,6 +247,7 @@ DECLSPEC_IMPORT long WINAPI RPCRT4$RpcBindingFromStringBindingW(wchar_t*, voi
245247
DECLSPEC_IMPORT long WINAPI RPCRT4$RpcStringFreeW(wchar_t**);
246248
DECLSPEC_IMPORT long WINAPI RPCRT4$RpcBindingFree(void**);
247249
DECLSPEC_IMPORT long WINAPI RPCRT4$RpcBindingSetAuthInfoExW(void*, wchar_t*, unsigned long, unsigned long, void*, unsigned long, RPC_SECURITY_QOS*);
250+
DECLSPEC_IMPORT void* __cdecl RPCRT4$NdrClientCall2(void*, void*, ...);
248251

249252
/* --- msvcrt.dll (CRT-like functions available in Windows) --- */
250253
DECLSPEC_IMPORT int __cdecl MSVCRT$sprintf(char*, const char*, ...);

src/common/helpers.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ BOOL is_high_integrity(void) {
126126
if (!tml) { KERNEL32$CloseHandle(hToken); return FALSE; }
127127

128128
if (ADVAPI32$GetTokenInformation(hToken, TokenIntegrityLevel, tml, dwSize, &dwSize)) {
129-
DWORD* pCount = GetSidSubAuthorityCount(tml->Label.Sid);
130-
DWORD integrity = *GetSidSubAuthority(tml->Label.Sid, *pCount - 1);
129+
DWORD* pCount = (DWORD*)ADVAPI32$GetSidSubAuthorityCount(tml->Label.Sid);
130+
DWORD integrity = *ADVAPI32$GetSidSubAuthority(tml->Label.Sid, *pCount - 1);
131131
result = (integrity >= SECURITY_MANDATORY_HIGH_RID);
132132
}
133133

0 commit comments

Comments
 (0)