
Cobalt Strike Aggressor Scripts (.cna) के लिए स्टैंडअलोन एमुलेशन और परीक्षण हार्नेस जो सिंटैक्स को मान्य करता है, Beacon APIs को मॉक करता है, और बिना teamserver के COFFLoader के माध्यम से BOFs को निष्पादित करता है।
CnaEmulator Cobalt Strike Aggressor Scripts (.cna) के लिए एक स्टैंडअलोन, सामान्य-उद्देश्य विकास, एमुलेशन, और परीक्षण हार्नेस है। यह सुरक्षा शोधकर्ताओं, टूल डेवलपर्स, और BOF लेखकों को टीमसर्वर या GUI क्लाइंट लॉन्च किए बिना स्क्रिप्ट सिंटैक्स को मान्य करने, Beacon कंसोल alias कमांड्स को सिम्युलेट करने, और COFFLoader64.exe के माध्यम से सीधे इन-मेमोरी Beacon Object Files (BOFs) को निष्पादित करने की अनुमति देता है।
[!WARNING] अस्वीकरण: यह कोड पूरी तरह से Antigravity के साथ जनरेट किया गया था और अभी तक इसकी समीक्षा नहीं की गई है।
check):
.cna स्क्रिप्ट्स को कंपाइल करता है।bof_pack):
datap बाइनरी फॉर्मेट से मेल खाते हुए नेटिव Little-Endian सीरियलाइज़ेशन को लागू करता है:
'i': 4-बाइट इंटीजर's': 2-बाइट शॉर्ट'z': लंबाई-प्रीफिक्स्ड null-टर्मिनेटेड स्ट्रिंग (strlen + 1 प्रीफिक्स)'Z': लंबाई-प्रीफिक्स्ड वाइड UTF-16LE स्ट्रिंग'b': लंबाई-प्रीफिक्स्ड बाइनरी बफरbeacon_inline_execute):
beacon_inline_execute($bid, $bof_data, "go", $packed_args) को इंटरसेप्ट करता है।COFFLoader64.exe go <bof_path> <hex_args> को निष्पादित करता है।test):
<script>.cna.tests या <script>.tests परिदृश्य सूट्स को स्वतः खोजता और निष्पादित करता है।console):
beacon> )।.
├── .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
| आवश्यकता | विवरण और सेटअप |
|---|---|
| Java JDK (17+) | java और javac बाइनरीज़। अपने JDK पथ पर JAVA_HOME सेट करें और सुनिश्चित करें कि %JAVA_HOME%\bin PATH में है। |
Sleep 2.1 (sleep.jar) | Aggressor Scripts के लिए स्क्रिप्टिंग इंजन। Sleep 2.1 से डाउनलोड करें या Cobalt Strike से कॉपी करें। SLEEP_JAR सेट करें (जैसे set "SLEEP_JAR=C:\path\to\sleep.jar"), या sleep.jar को रूट फ़ोल्डर में या CnaEmulator\ में रखें। |
इन-मेमोरी लोडर (COFFLoader64.exe) | स्टैंडअलोन लोडर बाइनरी (जैसे, trustedsec/COFFLoader से कंपाइल किया गया)। रूट डायरेक्टरी में रखा गया या COFFLOADER_PATH के माध्यम से ओवरराइड किया गया। |
त्वरित एनवायरनमेंट सेटअप (cmd.exe):
set "JAVA_HOME=C:\path\to\jdk-17"
set "PATH=%JAVA_HOME%\bin;%PATH%"
set "SLEEP_JAR=C:\path\to\sleep.jar"
कंपाइल किए गए क्लासेस या JAR को चलाने से पहले, CnaEmulator.java को कंपाइल करें:
बिल्ड स्क्रिप्ट का उपयोग करना:
CnaEmulator\build.bat
या मैनुअल कंपाइलेशन और पैकेजिंग:
:: 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 ..
आप प्रोजेक्ट रूट डायरेक्टरी से निम्नलिखित में से किसी भी विधि का उपयोग करके CnaEmulator को इनवोक कर सकते हैं:
लॉन्चर स्क्रिप्ट स्वचालित रूप से JDK डिस्कवरी, क्लासपाथ सेटअप, और पथ रिज़ॉल्यूशन को संभालती है:
cna_emulator.bat <action> [arguments...]
java -cp "CnaEmulator\CnaEmulator.jar;%SLEEP_JAR%" CnaEmulator <action> [arguments...]
java -cp "CnaEmulator;%SLEEP_JAR%" CnaEmulator <action> [arguments...]
check)कोड निष्पादित किए बिना Sleep 2.1 के माध्यम से Aggressor Script सिंटैक्स को मान्य करता है और AST ट्रीज़ को कंपाइल करता है:
cna_emulator.bat check <path\to\script.cna>
बंडल किए गए फिक्स्चर के साथ उदाहरण:
cna_emulator.bat check CnaEmulator\tests\fixtures\sample_bof.cna
नमूना आउटपुट:
[*] Checking syntax of: CnaEmulator\tests\fixtures\sample_bof.cna
[+] sample_bof.cna syntax OK
run)घोषित Aggressor alias को निष्पादित करता है, आर्गुमेंट्स को बाइनरी फॉर्मेट (bof_pack) में पैक करता है, ऑब्जेक्ट फ़ाइल (script_resource) को रिज़ॉल्व करता है, और कॉलर मेमोरी में BOF को निष्पादित करने के लिए COFFLoader64.exe को इनवोक करता है:
cna_emulator.bat run <path\to\script.cna> <alias_name> [arguments...]
बंडल किए गए फिक्स्चर के साथ उदाहरण:
cna_emulator.bat run CnaEmulator\tests\fixtures\sample_bof.cna sample_bof run test_target
नमूना आउटपुट:
[*] 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
test)CnaEmulator test स्वचालित टेस्ट निष्पादन प्रदान करता है:
cna_emulator.bat test <path\to\script.cna> [alias] [arguments...]
निष्पादन मोड:
<alias> और [arguments...] निर्दिष्ट हैं, तो केवल वही विशिष्ट परिदृश्य निष्पादित होता है।CnaEmulator स्क्रिप्ट के निकट एक कंपैनियन टेस्ट फ़ाइल की जाँच करता है:
<script_dir>\<script_name>.cna.tests<script_dir>\<script_name>.tests
यदि मिल जाती है, तो कंपैनियन फ़ाइल में सभी परिदृश्य लाइनें क्रमिक रूप से निष्पादित होती हैं।CnaEmulator सभी पंजीकृत कमांड aliases का निरीक्षण करता है और एक गार्ड क्लॉज़ टेस्ट निष्पादित करता है ताकि यह सुनिश्चित हो सके कि अमान्य आर्गुमेंट काउंट अनहैंडल्ड एक्सेप्शन फेंके बिना उपयोग त्रुटियाँ आउटपुट करते हैं।उदाहरण:
:: 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
कंपैनियन टेस्ट फ़ाइलें लिखना (<script>.cna.tests):
अपनी .cna स्क्रिप्ट के निकट एक सादा टेक्स्ट फ़ाइल बनाएँ। प्रत्येक गैर-रिक्त, गैर-कमेंट लाइन एक alias और उसके पैरामीटर्स को निर्दिष्ट करती है:
# Sample BOF Companion Test Suite
# Format: <alias> [arguments...]
sample_bof run test_target
sample_bof query
console)पंजीकृत aliases, कमांड इतिहास, और सिम्युलेटेड निष्पादन का समर्थन करने वाला एक इंटरैक्टिव beacon> प्रॉम्प्ट लॉन्च करता है:
cna_emulator.bat console <path\to\script.cna>
इंटरैक्टिव सत्र उदाहरण:
====================================================================
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
CnaEmulator पूरी तरह से सामान्य-उद्देश्य है और आपके फाइलसिस्टम में किसी भी डायरेक्टरी या बाहरी रिपॉजिटरी में स्थित Aggressor Scripts और BOF बाइनरीज़ का परीक्षण कर सकता है:
:: 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
CnaEmulator के लिए पूर्ण 48-परिदृश्य विनिर्देश अनुपालन टेस्ट सूट चलाने के लिए:
CnaEmulator\test.bat
अपेक्षित परिणाम:
====================================================================
Execution Summary
====================================================================
Total Scenarios : 48
Passed : 48
Failed : 0
Assertions : 172
Elapsed Time : ~2800 ms
====================================================================
[+] ALL 48 TEST SCENARIOS PASSED CLEANLY (100% SPECIFICATION CONFORMANCE)
| फ़ंक्शन / कीवर्ड | विवरण |
|---|---|
bof_pack | 4-बाइट बफर लंबाई प्रीफिक्स के साथ Little-Endian बाइनरी आर्गुमेंट्स (i, s, z, Z, b) को पैक करता है। |
beacon_inline_execute | COFFLoader64.exe go <bof.o> <hex_args> सबप्रोसेस को स्पॉन करता है और लाइव stdout को स्ट्रीम करता है। |
script_resource | स्क्रिप्ट डायरेक्टरी, bin/, ../bin/, और सापेक्ष पथों में सापेक्ष रिसोर्स पथों को रिज़ॉल्व करता है। |
openf, readb, closef | स्थानीय .o BOF फ़ाइलों को बाइट बफर्स में पढ़ने के लिए नेटिव फाइलसिस्टम I/O। |
btask, berror, blog, blog2 | stdout/stderr पर टास्किंग, स्थिति, और त्रुटि संदेशों को फॉर्मेट और आउटपुट करता है। |
beacon_command_register | लाइव कमांड कैटलॉग में aliases, सारांश, और सहायता विवरण पंजीकृत करता है। |
beacon_commands, beacon_command_detail | इंटरैक्टिव/कंसोल उपयोग के लिए पंजीकृत कमांड लिस्टिंग और सहायता टेक्स्ट को क्वेरी करता है। |
barch | "x64" रिटर्न करता है। |
bdata, beacon_info | मॉक Beacon मेटाडेटा हैश (id: 1, pid: 13020, user: SYSTEM, arch: x64) रिटर्न करता है। |
beacons, beacon_ids | सक्रिय सिम्युलेटेड beacon ऐरे (["1"]) रिटर्न करता है। |
alias, |
[!NOTE] डमी / स्टब इम्प्लीमेंटेशन: अन्य सभी Cobalt Strike APIs—जिनमें प्रोसेस निष्पादन/इंजेक्शन (
bshell,bpowershell,bexecute,bspawn,binject), टोकन मैनिपुलेशन (bsteal_token,brev2self,bgetuid), फाइलसिस्टम नेविगेशन (bpwd,bls,bupload,bdownload), पिवोटिंग (socks,rportfwd), UI प्रॉम्प्ट्स (prompt_text,prompt_confirm), और GUI हुक्स (popup,menu,item,on) शामिल हैं—डमी स्टब्स के रूप में लागू किए गए हैं जो सकारात्मक गैर-त्रुटि मान (1,"NT AUTHORITY\SYSTEM","C:\Windows\System32",true) या नो-ऑप ब्लॉक्स रिटर्न करते हैं ताकि स्क्रिप्ट्स विफल हुए बिना ऑफ़लाइन निष्पादित हो सकें।
command| इंटरैक्टिव या CLI डिस्पैच के लिए कमांड ब्लॉक्स को एक्ज़ीक्यूटेबल क्लोज़र्स के रूप में बाइंड करता है। |