Skip to content

Commit ce7384a

Browse files
authored
add com_probe BOF
1 parent 55d4d34 commit ce7384a

5 files changed

Lines changed: 456 additions & 0 deletions

File tree

env_assessment/com_probe/Makefile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
override CC_X64 := x86_64-w64-mingw32-gcc
2+
STRIP_X64 ?= strip
3+
4+
# Force x64 always available, x86 always disabled (Linux CI)
5+
COMPILER_X64_AVAILABLE := yes
6+
COMPILER_X86_AVAILABLE := no
7+
8+
# Standard BOF compilation flags (optimized, position-independent)
9+
CFLAGS := -Os -std=c99 \
10+
-fno-stack-protector -fno-stack-check -mno-stack-arg-probe \
11+
-fno-builtin -fno-builtin-memset -fno-builtin-memcpy -fno-builtin-memmove \
12+
-ffunction-sections -fdata-sections -nostdlib \
13+
-fno-asynchronous-unwind-tables -fno-unwind-tables -fno-ident \
14+
-Wall -Wextra -Wno-unused-parameter -Wno-unused-variable \
15+
-fno-leading-underscore -fno-ms-extensions
16+
17+
18+
SRC = $(wildcard *.c)
19+
HEADERS = $(wildcard *.h)
20+
21+
OBJS_X64 = $(patsubst %.c, %.x64.o, $(SRC))
22+
23+
all: $(OBJS_X64)
24+
25+
# Object files depend on source AND all headers
26+
%.x64.o: %.c $(HEADERS)
27+
@echo "Building x64: $@"
28+
$(CC_X64) $(CFLAGS) -c -o $@ $<
29+
@if command -v $(STRIP_X64) >/dev/null 2>&1; then \
30+
$(STRIP_X64) --strip-unneeded $@ 2>/dev/null || true; \
31+
fi
32+
33+
34+
clean:
35+
rm -f *.o *.x64.o *.x86.o
36+

env_assessment/com_probe/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# com_probe BOF
2+
3+
Probe whether a COM object can be instantiated from a given CLSID. Tries in-process activation first (`CLSCTX_INPROC_SERVER`), falls back to local server (`CLSCTX_LOCAL_SERVER`). Objects are released after.
4+
5+
## Usage
6+
7+
```
8+
com_probe <CLSID> [IID]
9+
```
10+
11+
- `CLSID` — GUID string, e.g. `{AEB5B82E-51E7-41EA-9A0B-3D2C8BEDE7B4}`
12+
- `IID` — optional interface ID (defaults to `IID_IUnknown`)
13+
14+
## Example Output
15+
16+
```
17+
[i] Probing CLSID: {AEB5B82E-51E7-41EA-9A0B-3D2C8BEDE7B4} with IID: IID_IUnknown (default)
18+
[i] Attempting CLSCTX_INPROC_SERVER activation...
19+
[+] In-proc activation succeeded (HRESULT: S_OK (0x00000000))
20+
[i] Object released cleanly after in-proc activation
21+
```
22+
23+
```
24+
[i] Probing CLSID: {00000000-0000-0000-0000-000000000000} with IID: IID_IUnknown (default)
25+
[-] In-proc activation failed (HRESULT: CLASS_E_CLASSNOTAVAILABLE (0x80040154))
26+
[-] Local server activation failed (HRESULT: CLASS_E_CLASSNOTAVAILABLE (0x80040154))
27+
```

env_assessment/com_probe/beacon.h

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Beacon Object Files (BOF)
3+
* -------------------------
4+
* A Beacon Object File is a light-weight post exploitation tool that runs
5+
* with Beacon's inline-execute command.
6+
*
7+
* Additional BOF resources are available here:
8+
* - https://github.com/Cobalt-Strike/bof_template
9+
*
10+
* Cobalt Strike 4.x
11+
* ChangeLog:
12+
* 1/25/2022: updated for 4.5
13+
*/
14+
15+
#ifndef DECLSPEC_IMPORT
16+
#ifdef _WIN32
17+
#define DECLSPEC_IMPORT __declspec(dllimport)
18+
#else
19+
#define DECLSPEC_IMPORT
20+
#endif
21+
#endif
22+
23+
/* data API */
24+
typedef struct {
25+
char * original; /* the original buffer [so we can free it] */
26+
char * buffer; /* current pointer into our buffer */
27+
int length; /* remaining length of data */
28+
int size; /* total size of this buffer */
29+
} datap;
30+
31+
DECLSPEC_IMPORT void BeaconDataParse(datap * parser, char * buffer, int size);
32+
DECLSPEC_IMPORT char * BeaconDataPtr(datap * parser, int size);
33+
DECLSPEC_IMPORT int BeaconDataInt(datap * parser);
34+
DECLSPEC_IMPORT short BeaconDataShort(datap * parser);
35+
DECLSPEC_IMPORT int BeaconDataLength(datap * parser);
36+
DECLSPEC_IMPORT char * BeaconDataExtract(datap * parser, int * size);
37+
38+
/* format API */
39+
typedef struct {
40+
char * original; /* the original buffer [so we can free it] */
41+
char * buffer; /* current pointer into our buffer */
42+
int length; /* remaining length of data */
43+
int size; /* total size of this buffer */
44+
} formatp;
45+
46+
DECLSPEC_IMPORT void BeaconFormatAlloc(formatp * format, int maxsz);
47+
DECLSPEC_IMPORT void BeaconFormatReset(formatp * format);
48+
DECLSPEC_IMPORT void BeaconFormatAppend(formatp * format, char * text, int len);
49+
DECLSPEC_IMPORT void BeaconFormatPrintf(formatp * format, char * fmt, ...);
50+
DECLSPEC_IMPORT char * BeaconFormatToString(formatp * format, int * size);
51+
DECLSPEC_IMPORT void BeaconFormatFree(formatp * format);
52+
DECLSPEC_IMPORT void BeaconFormatInt(formatp * format, int value);
53+
54+
/* Output Functions */
55+
#define CALLBACK_OUTPUT 0x0
56+
#define CALLBACK_OUTPUT_OEM 0x1e
57+
#define CALLBACK_OUTPUT_UTF8 0x20
58+
#define CALLBACK_ERROR 0x0d
59+
60+
DECLSPEC_IMPORT void BeaconOutput(int type, char * data, int len);
61+
DECLSPEC_IMPORT void BeaconPrintf(int type, char * fmt, ...);
62+
63+
64+
/* Token Functions */
65+
DECLSPEC_IMPORT BOOL BeaconUseToken(HANDLE token);
66+
DECLSPEC_IMPORT void BeaconRevertToken();
67+
DECLSPEC_IMPORT BOOL BeaconIsAdmin();
68+
69+
/* Spawn+Inject Functions */
70+
DECLSPEC_IMPORT void BeaconGetSpawnTo(BOOL x86, char * buffer, int length);
71+
DECLSPEC_IMPORT void BeaconInjectProcess(HANDLE hProc, int pid, char * payload, int p_len, int p_offset, char * arg, int a_len);
72+
DECLSPEC_IMPORT void BeaconInjectTemporaryProcess(PROCESS_INFORMATION * pInfo, char * payload, int p_len, int p_offset, char * arg, int a_len);
73+
DECLSPEC_IMPORT BOOL BeaconSpawnTemporaryProcess(BOOL x86, BOOL ignoreToken, STARTUPINFO * si, PROCESS_INFORMATION * pInfo);
74+
DECLSPEC_IMPORT void BeaconCleanupProcess(PROCESS_INFORMATION * pInfo);
75+
76+
/* Utility Functions */
77+
DECLSPEC_IMPORT BOOL toWideChar(char * src, wchar_t * dst, int max);
78+

0 commit comments

Comments
 (0)