• Stars
    star
    153
  • Rank 241,704 (Top 5 %)
  • Language
    C
  • License
    MIT License
  • Created about 3 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Cobalt Strike Beacon Object File (BOF) that uses handwritten shellcode to return the process Environment strings without touching any DLL's.

Cobalt Strike "Where Am I?" Beacon Object File

Cobalt Strike Beacon Object File (BOF) that uses handwritten shellcode to return the process Environment strings without touching any DLL's.

This idea was inspired by Matt Eidelberg's DEF CON 29 talk Operation Bypass Catch My Payload If You Can.

  • In this talk, Matt shows how EDR heuristics can detect Cobalt Strike beacons based on their behavior.
  • Matt uses an example where after the beacon compromises the endpoint, the first thing it does is run the whoami.exe local binary.
  • This behavior of the host beacon process spawning a new whoami.exe process, triggers the EDR and the beacon is burned!
  • I've been doing allot of Windows Internals studying, and this video made a lightbulb go off.
  • I thought "Why not just get the whoami.exe info from the process? It's already right there in the beacon processes memory!"

So that's what I did! I created a Beacon Object File that grabs the information we'd want, right there from the beacon process memory!

Since the goal was to make it ninja/OPSEC safe, I figured why not just do it dynamically with Assembly? About halfway through creation, I bit the bullet and burned the extra time to make it into a blog post as well, so here it all is!

This is the walkthrough blog post on how I created this Cobalt Strike Beacon Object File from start to finish:

I discovered that TrustedSec had already created a BOF for this, and of course they did because they are awesome! If you'd like to view their original work you can find it here: trustedsec/CS-Situational-Awareness-BOF/env

Using the WhereAmI BOF from the Cobalt Strike Console

BOF Flow to get the Environment Variables Dynamically in Memory

Below is the high-level flow & WinDBG commands to map our path from the Thread Environment Block (TEB) to the Environment strings we will ultimately display in our Cobalt Strike interactive beacon console.

TEB (GS Register) --> PEB --> ProcessParameters --> Environment Block Address & Environment Size

# TEB Address
0:000> !teb
TEB at 00000000002ae000
# PEB Address from TEB
0:000> dt !_TEB 2ae000
   +0x060 ProcessEnvironmentBlock : 0x00000000`002ad000 _PEB
# ProcessParamters Address from PEB
0:000> dt !_PEB 2ad000
   +0x020 ProcessParameters : 0x00000000`007423b0 _RTL_USER_PROCESS_PARAMETERS
# Environment Address & Size from ProcessParameters
0:000> dt !_RTL_USER_PROCESS_PARAMETERS 7423b0
   +0x080 Environment      : 0x00000000`00741130 Void
   +0x3f0 EnvironmentSize  : 0x124e

Using WinDBG to Parse the PEB and View Environment Strings

  • We can see that !peb command parses out the PEB structure and displays to us the Loader (Ldr) information, the address & resolved strings of the ProcessParameters struct, as well as the Environment information we are targeting.

Compile

cd ./whereami/
make

References/Resources

Sektor7 Courses - Conquer Malware Dev (best courses ever)
Raphael Mudge - Beacon Object Files - Luser Demo
Cobalt Strike - Beacon Object Files
BOF Code References
trustedsec/CS-Situational-Awareness-BOF
anthemtotheego/InlineExecute-Assembly
ajpc500/BOFs
Implementing ASM in C Code with GCC
Learn Assembly

More Repositories

1

BokuLoader

A proof-of-concept Cobalt Strike Reflective Loader which aims to recreate, integrate, and enhance Cobalt Strike's evasion features!
C
1,119
star
2

azureOutlookC2

Azure Outlook Command & Control (C2) - Remotely control a compromised Windows Device from your Outlook mailbox. Threat Emulation Tool for North Korean APT InkySquid / ScarCruft / APT37. TTP: Use Microsoft Graph API for C2 Operations.
C
456
star
3

Ninja_UUID_Runner

Module Stomping, No New Thread, HellsGate syscaller, UUID Shellcode Runner for x64 Windows 10!
C
425
star
4

spawn

Cobalt Strike BOF that spawns a sacrificial process, injects it with shellcode, and executes payload. Built to evade EDR/UserLand hooks by spawning sacrificial process with Arbitrary Code Guard (ACG), BlockDll, and PPID spoofing.
C
412
star
5

injectAmsiBypass

Cobalt Strike BOF - Bypass AMSI in a remote process with code injection.
C
366
star
6

injectEtwBypass

CobaltStrike BOF - Inject ETW Bypass into Remote Process via Syscalls (HellsGate|HalosGate)
C
258
star
7

HOLLOW

EarlyBird process hollowing technique (BOF) - Spawns a process in a suspended state, inject shellcode, hijack main thread with APC, and execute shellcode
C
240
star
8

AsmHalosGate

x64 Assembly HalosGate direct System Caller to evade EDR UserLand hooks
C
167
star
9

winx64-InjectAllProcessesMeterpreter-Shellcode

64bit Windows 10 shellcode that injects all processes with Meterpreter reverse shells.
Assembly
129
star
10

HellsGatePPID

Assembly HellGate implementation that directly calls Windows System Calls and displays the PPID of the explorer.exe process
C
99
star
11

Nobelium-PdfDLRunAesShellcode

A recreation of the "Nobelium" malware based on Microsofts Malware analysis - Part 1: PDF2Pwn
C
99
star
12

halosgate-ps

Cobalt Strike BOF that uses a custom ASM HalosGate & HellsGate syscaller to return a list of processes
C
93
star
13

XSS-Clientside-Attacks

A repository of JavaScript XSS attacks against client browsers
JavaScript
86
star
14

xPipe

Cobalt Strike BOF to list Windows Pipes & return their Owners & DACL Permissions
C
75
star
15

x64win-DynamicNoNull-WinExec-PopCalc-Shellcode

64bit WIndows 10 shellcode dat pops dat calc - Dynamic & Null Free
Assembly
34
star
16

x64win-AddRdpAdminShellcode

64bit Windows 10 shellcode that adds user BOKU:SP3C1ALM0V3 to the system and the localgroups Administrators & "Remote Desktop Users"
Assembly
33
star
17

tailorMS-rXSS-Keylogger

Reflected Cross-Site Scripting (XSS) vulnerability in 'index.php' login-portal webpage of SourceCodesters Tailor Management System v1.0 allows remote attackers to harvest keys pressed via unauthenticated victim clicking malicious URL and typing.
Python
25
star
18

StockManagement-XSS-Login-CredHarvester

Reflected Cross-Site Scripting (XSS) vulnerability in 'index.php' login-portal webpage of SourceCodesters Stock Management System v1.0 allows remote attackers to harvest login credentials & session cookie via unauthenticated victim clicking malicious URL and entering credentials.
Python
20
star
19

gsSMTP-Csrf2Xss2RCE

Python
17
star
20

gsCMS-CustomJS-Csrf2Xss2Rce

GetSimple CMS Custom JS Plugin Exploit RCE Chain
Python
13
star
21

LibreHealth-authRCE

LibreHealth v2.0.0 suffers from an authenticated file upload vulnerability allowing remote attackers to gain remote code execution (RCE) on the hosting webserver via uploading a maliciously crafted image.
Python
11
star
22

CVE-2020-23839

Public PoC Disclosure for CVE-2020-23839 - GetSimple CMS v3.3.16 suffers from a Reflected XSS on the Admin Login Portal
Python
10
star
23

onlineCourseReg-RCE

From 0 to Remote Code Execution - exploit development files for Online Course Registration Web Application RCE
Python
8
star
24

BikeRental-FU-RCE

Python
8
star
25

slae64

Repo for SLAE64 Exam
Assembly
7
star
26

GetSimple-SmtpPlugin-CSRF2RCE

GetSimple CMS My SMTP Contact Plugin <= v1.1.1 - CSRF to RCE
Python
7
star
27

boku7.github.io

Blog
HTML
6
star
28

homeRent-SQLi-RCE

House Rental v1.0 suffers from an unauthenticated SQL Injection vulnerability allowing remote attackers to execute arbitrary code on the hosting webserver via sending a malicious POST request.
Python
5
star
29

fuzzingFTP

Python scripts for fuzzing FTP servers, with percision, over TCP
Python
4
star
30

slae32

Repo for all SLAE32 Exam Assignments
Assembly
3
star
31

burp-jars

3
star
32

aCal-RCE

Exploit Development files for aCal web application - reflected XSS to RCE.
Python
3
star
33

BarracudaDrivev6.5-LocalPrivEsc

Insecure Service File Permissions in bd service in Real Time Logics BarracudaDrive v6.5 allows local attackers to escalate privileges to admin via replacing the bd.exe file and restarting the computer where it will be run as 'LocalSystem' on the next startup automatically.
2
star
34

AV_Bypass-Splitter

Splitter script to identify Anti-Virus signature of an executable
Shell
1
star
35

xdev-templates

Random helpful xdev templates
Python
1
star
36

domQuestPro-SEH-BOF

Python
1
star