Skip to content
KitploitKITPLOIT
ToolsExploitsBlog
Log in
Submit
ToolsExploitsBlog
Submit

Hacking, PenTest, and Cybersecurity Tools for Your Security Arsenal!

Kitploit is a directory of hacking, cybersecurity, and pentesting tools. Discover the latest project updates to find vulnerabilities, analyze systems, automate testing, and strengthen your security.

··Feeds·Contact·Privacy·© 2026 Kitploit

Tool Directory

Categories

View all categories
Loading categories
CnaEmulator — Standalone emulation and testing harness for Cobalt Strike Aggressor Scripts (.cna) that validates syntax, mocks Beacon APIs, and executes BOFs via COFFLoader without a teamserver. | Kitploit
Tools/GitHubGitHub/iterat0r/cnaemulator
Dynamic Analysis (Sandboxing)ExploitationScripting & AutomationPost-ExploitationPenetration TestingCommand and ControlUtilities & FrameworksLearning & EducationRed TeamingPayload Development
GitHub
21387 days agoNot yet reviewed

Most Popular

View all →

Discover the most used tools by our community.

Explore all tools

Browse our collection of tools

View all tools →
iterat0r/cnaemulator

CnaEmulator

Standalone emulation and testing harness for Cobalt Strike Aggressor Scripts (.cna) that validates syntax, mocks Beacon APIs, and executes BOFs via COFFLoader without a teamserver.

View Repository
Share

CnaEmulator - Cobalt Strike Aggressor Script Emulator & Mock Harness

CnaEmulator is a standalone, general-purpose development, emulation, and testing harness for Cobalt Strike Aggressor Scripts (.cna). It allows security researchers, tool developers, and BOF authors to validate script syntax, simulate Beacon console alias commands, and execute in-memory Beacon Object Files (BOFs) directly via COFFLoader64.exe without launching a teamserver or GUI client.


[!WARNING] Disclaimer: This code was fully generated with Antigravity and has not been reviewed yet.

Capabilities

  1. Syntax Validation (check):
    • Compiles .cna scripts using the underlying Sleep 2.1 engine.
    • Accurately detects runaway strings, unescaped characters, parser syntax errors, and missing delimiters with exact file line numbers.
  2. Aggressor Function Emulation:
  • Emulates official Cobalt Strike Beacon functions from the HelpSystems/Fortra Aggressor Script Documentation.
  • Provides realistic mock values or positive non-error return values for process injection, token manipulation, filesystem, network, and GUI callback APIs.
  • Real BOF Binary Packing (bof_pack):
    • Implements native Little-Endian serialization matching Cobalt Strike's datap binary format:
      • 'i': 4-byte integer
      • 's': 2-byte short
      • 'z': length-prefixed null-terminated string (strlen + 1 prefix)
      • 'Z': length-prefixed wide UTF-16LE string
      • 'b': length-prefixed binary buffer
  • COFFLoader Execution Bridge (beacon_inline_execute):
    • Automatically intercepts beacon_inline_execute($bid, $bof_data, "go", $packed_args).
    • Converts the packed arguments into hex format.
    • Executes COFFLoader64.exe go <bof_path> <hex_args> as a child subprocess.
    • Streams live BOF console output directly to stdout in real time.
  • Universal Companion Test Suites & Automated Verification (test):
    • Auto-discovers and executes companion <script>.cna.tests or <script>.tests scenario suites.
    • Supports targeted CLI scenario testing and automatic alias guard clause verification.
  • Interactive Beacon Console (console):
    • Interactive command prompt (beacon> ) supporting registered aliases, arguments, help documentation, and live execution.

  • Directory Layout

    root@kitploit:~
    .
    ├── .gitignore                # Git ignore rules for compiled binaries & bytecode
    ├── COFFLoader64.exe          # 64-bit Standalone in-memory COFF relocator and loader
    ├── cna_emulator.bat          # Convenient CLI launcher script
    ├── README.md                 # Comprehensive documentation and usage guide
    ├── TESTING.md                # Component verification report & quality gates
    ├── TEST_SPEC.md              # 48-scenario 7-category test specification
    └── CnaEmulator/              # Java CNA Emulator component
        ├── .gitignore            # Git ignore rules for CnaEmulator subfolder
        ├── CnaEmulator.java      # Emulator source code and Sleep engine bridge
        ├── CnaEmulator.class     # Compiled bytecode
        ├── CnaEmulator.jar       # Packaged bytecode JAR
        ├── build.bat             # Build script to compile and package CnaEmulator
        ├── test.bat              # Standalone test runner script (48 scenarios)
        └── tests/                # Test suite and fixtures
            ├── TestCnaEmulator.java  # 48-scenario test harness
            └── fixtures/             # Universal test fixtures
                ├── sample_bof.cna        # Standalone sample Aggressor Script
                ├── sample_bof.cna.tests  # Companion test suite
                ├── multi_alias.cna       # Multi-alias sample script
                └── multi_alias.cna.tests # Multi-alias companion test suite
    

    Requirements & Prerequisites

    RequirementDescription & Setup
    Java JDK (17+)java and javac binaries. Set JAVA_HOME to your JDK path and ensure %JAVA_HOME%\bin is in PATH.
    Sleep 2.1 (sleep.jar)Scripting engine for Aggressor Scripts. Download from Sleep 2.1 or copy from Cobalt Strike. Set SLEEP_JAR (e.g. set "SLEEP_JAR=C:\path\to\sleep.jar"), or place sleep.jar in the root folder or in CnaEmulator\.
    In-Memory Loader (COFFLoader64.exe)Standalone loader binary (e.g., compiled from trustedsec/COFFLoader). Placed in the root directory or overridden via COFFLOADER_PATH.

    Quick Environment Setup (cmd.exe):

    root@kitploit:~
    set "JAVA_HOME=C:\path\to\jdk-17"
    set "PATH=%JAVA_HOME%\bin;%PATH%"
    set "SLEEP_JAR=C:\path\to\sleep.jar"
    

    Usage Guide

    1. Compiling from Source

    Before running the compiled classes or JAR, compile CnaEmulator.java:

    Using the Build Script:

    root@kitploit:~
    CnaEmulator\build.bat
    

    Or Manual Compilation & Packaging:

    root@kitploit:~
    :: Compile source to bytecode
    javac -cp "%SLEEP_JAR%" -d CnaEmulator CnaEmulator\CnaEmulator.java
    
    :: Package into executable bytecode JAR
    cd CnaEmulator
    jar cfe CnaEmulator.jar CnaEmulator *.class
    cd ..
    

    2. Execution Methods

    You can invoke CnaEmulator using any of the following methods from the project root directory:

    Method A: Batch Script Launcher (Recommended)

    The launcher script automatically handles JDK discovery, classpath setup, and path resolution:

    root@kitploit:~
    cna_emulator.bat <action> [arguments...]
    

    Method B: Compiled Executable JAR

    root@kitploit:~
    java -cp "CnaEmulator\CnaEmulator.jar;%SLEEP_JAR%" CnaEmulator <action> [arguments...]
    

    Method C: Direct Class Bytecode

    root@kitploit:~
    java -cp "CnaEmulator;%SLEEP_JAR%" CnaEmulator <action> [arguments...]
    

    3. Core Actions & Usage Examples

    A. Validate Script Syntax (check)

    Validates Aggressor Script syntax and compiles AST trees via Sleep 2.1 without executing code:

    root@kitploit:~
    cna_emulator.bat check <path\to\script.cna>
    

    Example with bundled fixture:

    root@kitploit:~
    cna_emulator.bat check CnaEmulator\tests\fixtures\sample_bof.cna
    

    Sample Output:

    root@kitploit:~
    [*] Checking syntax of: CnaEmulator\tests\fixtures\sample_bof.cna
    [+] sample_bof.cna syntax OK
    

    B. Execute Commands with Live BOF Dispatch (run)

    Executes a declared Aggressor alias, packs arguments into binary format (bof_pack), resolves the object file (script_resource), and invokes COFFLoader64.exe to execute the BOF in caller memory:

    root@kitploit:~
    cna_emulator.bat run <path\to\script.cna> <alias_name> [arguments...]
    

    Example with bundled fixture:

    root@kitploit:~
    cna_emulator.bat run CnaEmulator\tests\fixtures\sample_bof.cna sample_bof run test_target
    

    Sample Output:

    root@kitploit:~
    [*] Invoking: sample_bof 1 run test_target
    [*] Tasked beacon: Executing sample_bof with action: run
    
    [+] [COFFLoader Bridge] Executing: COFFLoader64.exe go sample_bof.o
        | Got contents of COFF file
        | Running/Parsing the COFF file
        | Ran/parsed the coff
        | Outdata Below:
        | ...
    [+] [COFFLoader Bridge] Completed with exit code: 0
    

    C. Automated Test Battery & Regression Testing (test)

    CnaEmulator test provides automated test execution:

    root@kitploit:~
    cna_emulator.bat test <path\to\script.cna> [alias] [arguments...]
    

    Execution Modes:

    1. Targeted Scenario Execution: If <alias> and [arguments...] are specified on the command line, only that specific scenario is executed.
    2. Companion Test File Discovery: If no arguments are provided, CnaEmulator checks for a companion test file adjacent to the script:
      • <script_dir>\<script_name>.cna.tests
      • <script_dir>\<script_name>.tests If found, all scenario lines in the companion file are executed sequentially.
    3. Dynamic Alias Inspection & Guard Testing: If no companion test file exists, CnaEmulator inspects all registered command aliases and executes a guard clause test to ensure invalid argument counts output usage errors without throwing unhandled exceptions.

    Examples:

    root@kitploit:~
    :: Run automated tests on the bundled sample script (executes sample_bof.cna.tests)
    cna_emulator.bat test CnaEmulator\tests\fixtures\sample_bof.cna
    
    :: Run automated tests on the bundled multi-alias script (executes multi_alias.cna.tests)
    cna_emulator.bat test CnaEmulator\tests\fixtures\multi_alias.cna
    
    :: Run a targeted scenario directly via CLI
    cna_emulator.bat test CnaEmulator\tests\fixtures\sample_bof.cna sample_bof query
    

    Authoring Companion Test Files (<script>.cna.tests): Create a plain text file adjacent to your .cna script. Each non-empty, non-comment line specifies an alias and its parameters:

    root@kitploit:~
    # Sample BOF Companion Test Suite
    # Format: <alias> [arguments...]
    sample_bof run test_target
    sample_bof query
    

    D. Interactive Simulated Beacon Console (console)

    Launches an interactive beacon> prompt supporting registered aliases, command history, and simulated execution:

    root@kitploit:~
    cna_emulator.bat console <path\to\script.cna>
    

    Interactive Session Example:

    root@kitploit:~
    ====================================================================
      CnaEmulator Interactive Beacon Console
      Loaded Script: sample_bof.cna
    ====================================================================
    Type 'help' to see registered commands, or 'exit' to quit.
    
    beacon> help
    Registered Beacon Commands:
      - sample_bof : Sample BOF execution command
    
    beacon> sample_bof run local_target
    [*] Tasked beacon: Executing sample_bof with action: run
    [+] [COFFLoader Bridge] Executing: COFFLoader64.exe go sample_bof.o
    ...
    beacon> exit
    

    4. Testing External BOF Projects

    CnaEmulator is completely general-purpose and can test Aggressor Scripts and BOF binaries located in any directory or external repository across your filesystem:

    root@kitploit:~
    :: Validate any external script syntax
    cna_emulator.bat check C:\Projects\CustomBof\my_bof.cna
    
    :: Execute external BOF alias commands with live arguments
    cna_emulator.bat run C:\Projects\CustomBof\my_bof.cna my_command target_argument
    
    :: Run companion test suites for external scripts
    cna_emulator.bat test C:\Projects\CustomBof\my_bof.cna
    
    :: Open interactive console with external script
    cna_emulator.bat console C:\Projects\CustomBof\my_bof.cna
    

    5. Running the CnaEmulator Self-Test Suite

    To run the complete 48-scenario specification compliance test suite for CnaEmulator:

    root@kitploit:~
    CnaEmulator\test.bat
    

    Expected Result:

    root@kitploit:~
    ====================================================================
      Execution Summary
    ====================================================================
      Total Scenarios : 48
      Passed          : 48
      Failed          : 0
      Assertions      : 172
      Elapsed Time    : ~2800 ms
    ====================================================================
    [+] ALL 48 TEST SCENARIOS PASSED CLEANLY (100% SPECIFICATION CONFORMANCE)
    

    Emulated Function Catalog

    Real Implementations (Functional Engine & Subprocess Bridge)

    Function / KeywordDescription
    bof_packPacks Little-Endian binary arguments (i, s, z, Z, b) with 4-byte buffer length prefix.
    beacon_inline_executeSpawns COFFLoader64.exe go <bof.o> <hex_args> subprocess and streams live stdout.
    script_resourceResolves relative resource paths across script dir, bin/, ../bin/, and relative paths.
    openf, readb, closefNative filesystem I/O for reading local .o BOF files into byte buffers.
    btask, berror, blog, blog2Formats and outputs tasking, status, and error messages to stdout/stderr.
    beacon_command_registerRegisters aliases, summaries, and help details into the live command catalog.
    beacon_commands, beacon_command_detailQueries registered command listings and help text for interactive/console use.
    barchReturns "x64".
    bdata, beacon_infoReturns mock Beacon metadata hash (id: 1, pid: 13020, user: SYSTEM, arch: x64).
    beacons, beacon_idsReturns active simulated beacon array (["1"]).
    alias, commandBinds command blocks as executable closures for interactive or CLI dispatch.

    [!NOTE] Dummy / Stub Implementations: All other Cobalt Strike APIs—including process execution/injection (bshell, bpowershell, bexecute, bspawn, binject), token manipulation (bsteal_token, brev2self, bgetuid), filesystem navigation (bpwd, bls, bupload, bdownload), pivoting (socks, rportfwd), UI prompts (prompt_text, prompt_confirm), and GUI hooks (popup, menu, item, on)—are implemented as dummy stubs returning positive non-error values (1, "NT AUTHORITY\SYSTEM", "C:\Windows\System32", true) or no-op blocks so scripts execute offline without failing.

    Download Tool