A Cobalt Strike BOF that searches running processes by name or PID and prints the matching process id and image name. Locally, enumeration is done through direct system calls (ZwQuerySystemInformation with SystemProcessInformation), without going through the Win32 API. When a remote host is given, enumeration runs over WMI (Win32_Process on \\host\root\cimv2) using the beacon's current token. Both x64 and WoW64 (x86 on x64) builds are supported.
- Make sure that Mingw-w64 (including mingw-w64-binutils) has been installed.
- From the tool folder (the one containing this README), type
maketo compile the object files. This producespgrep.x64.oandpgrep.x86.oin thedistfolder. - Use Cobalt Strike's script manager to import the
pgrep.cnascript.
Running the tool is straightforward. Once you imported the CNA script using Cobalt Strike's Script Manager, the command is available as a Cobalt Strike command that can be executed within a beacon:
pgrep <name|id> [host]— prints<pid> <image name>for every running process whose image name contains<name>(case-insensitive). If the argument consists only of digits, it is treated as a process id and only the process with that exact PID is printed. When nothing matches, it printsprocess not found. Without[host]the local system is searched via direct syscalls; with[host]the search runs on the remote host over WMI using the beacon's current token (a valid admin token on the remote host is required, e.g. frommake_token).
The BOF uses version-aware syscall stubs (Syscalls.h for x64, Syscalls-WoW64.h for WoW64) and supports Windows 7 SP1 (6.1.7601) through Windows 10/11 on both x64 and x86 (WoW64) architectures. Compiling the BOF code works on any system (Linux, macOS, Windows) that has the Mingw-w64 compiler installed.
Inspired by the TrustedSec tasklist BOF: https://github.com/trustedsec/CS-Situational-Awareness_BOFS