Skip to content

Conversation

@enzok
Copy link
Contributor

@enzok enzok commented Dec 17, 2025

Implement Capesolo support

kevoreilly and others added 30 commits December 17, 2024 11:06
… 38a9847cb5ce4918bdfee2d54d5d3b79e1399cce15c7b68d86e8f0a5f48e3131)
…6b8ff55c452cc87e35d69928cccbcfc5af848db1abb4fe0364510986e068b)
Allows ability to properly track CryptKey handles (.NET often times operates on dupe key instead of original)
- Log Process ID in NtReadVirtualMemory/NtWriteVirtualMemory/ReadProcessMemory/WriteProcessMemory if the process handle used does not represent the current running process
- Remove a dupe arg from NtOpenThread
- Better logging for NtGetContextThread; logs have appropriate arguments based on the context flags
- Cloned this logic to NtSetContextThread as well
- Added PID/TID to NtGet/SetContextThread

Changes inspired by trying to detect https://research.checkpoint.com/2025/waiting-thread-hijacking/

I've found it's quite difficult to keep track of all all of the handles being mapped to various identifiers (PID/TID) from the various APIs in a signature without these improvements.
…aps=1' for loader snaps output in analysis log
kevoreilly and others added 27 commits November 7, 2025 10:17
Introduce `_pipe_sprintf` for formatted string output and
`InteractiveBreakpointCallback` for handling interactive
breakpoints. Update `SetConfigBP` and `SetInitialBreakpoints`
to conditionally use the new callback based on configuration,
enhancing breakpoint functionality for interactive debugging.
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @enzok, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly upgrades the CAPE sandbox's capabilities by introducing an interactive debugger, strengthening its defenses against analysis, and refining its core hooking and logging infrastructure. The changes aim to provide deeper insights into malware behavior while making the sandbox more resilient to detection and evasion techniques. The codebase has been modernized for improved performance and maintainability.

Highlights

  • Interactive Debugger (CAPEsolo): Introduced a new interactive debugger module, CAPEsolo, which communicates via a named pipe. It supports a wide range of commands including instruction page viewing, memory dumps, register manipulation, breakpoint management (set, delete, run until), stepping (in, over, out), stack inspection, module and thread listing, flag modification, NOPing instructions, and patching bytes. This significantly enhances real-time analysis capabilities.
  • Enhanced Anti-Analysis & Stealth: Implemented several new anti-analysis techniques, including spoofing CPU core count, physical memory, disk size, and power capabilities to evade VM detection. Added mechanisms to protect Ntdll and other hooked modules from write attempts and unhooking, with exceptions handled by the debugger. Removed outdated WoW64 workarounds, streamlining the codebase.
  • Improved API Hooking & Module Handling: Refactored core API hooking logic, introducing new hook types like HOOK_PUSH_RETN and HOOK_NATIVE_PUSH_RETN for better compatibility and stealth. Enhanced trampoline creation for 64-bit processes to handle far jumps/calls and RIP-relative instructions more robustly. Improved module loading and unloading notifications, and added more detailed logging for process and thread context manipulation, including WoW64-specific contexts.
  • Expanded Yara Scanning Capabilities: Updated internal Yara rules to include new patterns for WMI functions and debug print functions, improving the ability to identify and hook relevant APIs. Introduced GetAddressesByYara to efficiently retrieve multiple function addresses via Yara scans, and refined the parsing of Yara options to trigger specific actions like memory dumps or breakpoint settings.
  • Detailed Network & System Call Logging: Significantly enhanced NtDeviceIoControlFile logging to parse and detail specific AFD IOCTLs (BIND, CONNECT, RECV, SEND), providing granular insights into network activity, including aggregated send/receive buffers and handling of asynchronous operations. Expanded logging for process and thread operations to include DllPath and cross-process IDs.
  • Codebase Modernization & Refactoring: Replaced stdext::hash_multimap with std::unordered_multimap and integrated the uthash library for more efficient hash table implementations. Removed several deprecated Scylla-related export/section lookup functions. Consolidated configuration parsing and default settings, and added new config options for fine-grained control over hooking behavior, debugger features, and anti-analysis measures.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces significant enhancements, primarily the implementation of Capesolo, an interactive debugger. The changes are extensive and include major refactoring and improvements across the codebase. Key updates involve a more robust 64-bit hooking mechanism, performance improvements in Yara scanning, and the removal of the problematic WoW64 workaround. Additionally, many hooks have been improved for more detailed logging and enhanced anti-analysis capabilities. I've identified a couple of issues related to memory access and logical flow that should be addressed.

Comment on lines +2673 to +2686
Matching = pRtlCompareMemory((PVOID)EntryPointBytes, pEntryPointBytes, ChunkSize);

if (Matching == ChunkSize)
{
#ifdef DEBUG_COMMENTS
DebugOutput("VerifyHeaders: Entry point matches.\n");
#endif
RetVal = 1;
}
else
{
DebugOutput("VerifyHeaders: Entry point does not match, 0x%x of 0x%x matching\n", Matching, ChunkSize);
RetVal = 0;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The logic for verifying headers and the entry point is flawed. The result of the header check (RetVal) is overwritten by the result of the entry point check. If the header check fails (RetVal = 0) but the entry point check succeeds, the function will incorrectly return 1 (match), indicating an overall success. The function should return 0 if any of the checks fail.

Matching = pRtlCompareMemory((PVOID)EntryPointBytes, pEntryPointBytes, ChunkSize);

	if (Matching != ChunkSize)
	{
		DebugOutput("VerifyHeaders: Entry point does not match, 0x%x of 0x%x matching\n", Matching, ChunkSize);
		RetVal = 0;
	}
#ifdef DEBUG_COMMENTS
	else if (RetVal == 1)
	{
		DebugOutput("VerifyHeaders: Entry point matches.\n");
	}
#endif

Comment on lines +2110 to +2111
PDWORD AddressOfNames = (PDWORD)((PUCHAR)Base + ExportDir->AddressOfNames);
PWORD AddressOfNameOrdinals = (PWORD)((PUCHAR)Base + ExportDir->AddressOfNameOrdinals);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The pointers AddressOfNames and AddressOfNameOrdinals are calculated from the export directory but are not checked for accessibility before being used inside the loop. This could lead to a crash if the PE header is malformed or corrupted. It's good practice to validate these pointers after they are calculated, similar to how AddressOfFunctions is checked.

PDWORD AddressOfNames = (PDWORD)((PUCHAR)Base + ExportDir->AddressOfNames);
		PWORD AddressOfNameOrdinals = (PWORD)((PUCHAR)Base + ExportDir->AddressOfNameOrdinals);
		if (!IsAddressAccessible(AddressOfNames) || !IsAddressAccessible(AddressOfNameOrdinals))
			return NULL;

Moved the declaration of the function pointer
_NtQueryInformationThread from static to non-static,
allowing broader access outside the current translation unit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants