> For the complete documentation index, see [llms.txt](https://legacy.thehacker.recipes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://legacy.thehacker.recipes/evasion/av/stealth.md).

# Stealth with C2

This technique can be used only after having obtained an initial access on the target

{% hint style="danger" %}
**This is a work-in-progress**. It's indicated with the 🛠️ emoji in the page name or in the category name. Wanna help? Please reach out to me: [@\_nwodtuhs](https://twitter.com/_nwodtuhs)
{% endhint %}

## What is a Command & Control (C2) Reminder

## Cobalt / Havoc

once you have a shell on the victim, one of the most discreet ways to execute code is through object file because the idea is to avoid creating a sub-process but rather to allocate memory to run code and then resume its initial size.

#### Object file

Here is an example of how to launch the BoF (Beacon Object File) once compiled. The source code is available [here ](https://github.com/CMEPW/bof-collection/blob/main/src/checkVM/checkVM2.c)and the goal is to verify if we are dealing with a virtual machine or not.

<figure><img src="https://2817308836-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MHRw3PMJtbDDjbxm5ub%2Fuploads%2FKh5qWNTPJylihULcAYze%2Fbof-VM.png?alt=media&amp;token=72ccecc3-5cd0-4f71-be20-da2c98531162" alt=""><figcaption></figcaption></figure>

#### How to write BoF (Beacon Object File)

For example, if you need the `RegCloseKey` function.

Look at the Windows documentation (in our example <https://learn.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regclosekey>) to get the list of the arguments.

In our case :&#x20;

```c
LSTATUS RegCloseKey(
  [in] HKEY hKey
);
```

Then, get the name of the library used (at the bottom of the page) in our case it is : `Advapi32.lib`

We have to structure it like this : `DECLSPEC_IMPORT LSTATUS WINAPI <lib>$<Function>(<Args List>);`

Still in our case, we will get this: `DECLSPEC_IMPORT LSTATUS WINAPI ADVAPI32$RegCloseKey(HKEY);`

Simply use the function like this in our code: `ADVAPI32$RegCloseKeyA(hKey);`

{% hint style="info" %}
*In addition, to use theses functions download the library "beacon.h" available* [*here*](https://hstechdocs.helpsystems.com/manuals/cobaltstrike/current/userguide/content/beacon.h)*.*
{% endhint %}

It is also possible to load a library and then call the method using methods like `GetProcAddress` or `LoadLibraryA.`

Below is an example of how to use this approach:

{% embed url="<https://github.com/CMEPW/bof-collection/blob/main/src/getAV/getAV-ll.c>" %}

More information at this URL: <https://hstechdocs.helpsystems.com/manuals/cobaltstrike/current/userguide/content/topics/beacon-object-files_main.htm>.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://legacy.thehacker.recipes/evasion/av/stealth.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
