Static Analysis
Defender detection
PS C:\Tools\ExpandDefenderSig> Import-Module C:\Tools\ExpandDefenderSig\ExpandDefenderSig.ps1
PS C:\Tools\ExpandDefenderSig> ls "C:\ProgramData\Microsoft\Windows Defender\Definition Updates\{50326593-AC5A-4EB5-A3F0-047A75D1470C}\mpavbase.vdm" | Expand-DefenderAVSignatureDB -OutputFileName mpavbase.raw
Directory: C:\Tools\ExpandDefenderSig
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 4/9/2024 12:50 PM 79092299 mpavbase.raw
PS C:\Tools\ExpandDefenderSig> C:\Tools\Strings\strings64.exe .\mpavbase.raw | Select-String -Pattern "WNcry@2ol7"
WNcry@2ol7d
WNcry@2ol7DefenderCheck
Also try with gocheck ; ThreatCheck or AVred:
AmsiScanner
Powershell scripts - AMSITrigger
Hunt for malicious string
Bypass
Approches for EvasionXOR Encryption

XOR our shellcode with the value 0x5C (make sure to get rid of new lines, as this breaks the recipe).

Replace the shellcode in the program with the output, and then add a short loop which XORs each byte with 0x5C just before writing the shellcode to memory
Still detected:

AES Encryption

Modified code
"No threat found!"


But .... Behavorial detection

Basic Bypass
Amsitrigger flag "System.AppDomain" in PowerUp.ps1

Reverse the string
Other methods:
Remove default comments
Rename the script, functions names and variables
Modify the variable names of the Win32 API clals that are detected
Obfuscate PEBytes content -> use packers: https://github.com/mgeeky/ProtectMyTooling
Implement a reverse function for PEBytes to avoid static signatures
Add a sandbox check to waste dynamic analysis resources
Remove reflective PE warnings
Use obfuscated commands for Invoke-XXX
Simple obfuscation:
String manipulation
Example 1: SafetyKatz
Run DefenderCheck - String flagged
Open VisualStudio
Ctrl + H - Find and replace "Credentials" with "Credents" (make sur the new string is not present in the code)
Select Scope as "Entire Solution" - "Replace All"
Build and recheck with DefenderCheck
Download Mimikatz and Out-CompressedDll.ps1
Out-CompressedDll mimikatz.exe outputfile.txt
Copy the value of the variable $EncodedCompressedFile and replace "compresedMimikatzString" in the Constants.cs of SafetyKatz
Copy the byte size from the output and replace it in Program.cs
Build and recheck with DefenderCheck
Example 2: BetterSafetyKatz
Download "mimikatz_trunk.zip", convert the file to base64
Modify the Program.cs file:
Add a new variable that contains the base64
Comment the code that downloads or accepts the mimikatz file as argument
Convert the base64 string to bytes and pass it to "zipStream" variable
Obfuscation
C# Obfuscation
ConfuserEx
Launch ConfuserEx
In Project tab select the Base Directory where the binary file is located.
In Project tab Select the Binary File that we want to obfuscate.
In Settings tab add the rules.
In Settings tab edit the rule and select the preset as
Normal.In Protect tab click on the protect button.
The new obfuscated binary is in the Confused folder under the Base Directory.
Nimcrypt2
Example with Rubeus
InvisibilityCloak
Obfuscar
Command Line Obfuscation
Powershell Obfuscation
Basic obfuscation
x64 binaries
Packers
Sandbox check
Payload Delivery
Use NetLoader with CsWhispers to add D/Invoke and indirect syscall execution
Download CsWhispers, open it in Visual Studio and Check 'Allow unsafe code' under build configuration.
Create a new file called CsWhispers.txt under CsWhispers.Sample and append NT API and struct equivalents that are required to be replaced in the NetLoader project.
Finally, append the NetLoader project into CSWhispers.Sample and replace appropriate WinAPIs with their NT equivalents. Build the solution.
Obfuscate the generated assembly using Nimcrypt2.
NetLoader can be used to loadbinary from filepathor URL and patch AMSI & ETW while executing.
AssemblyLoader can be used to load the Netloader in-memory from a URL which then loads a binary from a filepath or URL.
Change Signature
Metasploit Payload
IEX Blocked
EDR/AV block this command
Instead of using Invoke-Expression, simply copy and paste the script directly into the PowerShell terminal, storing it in a variable and then loading it into memory using an alternative method.

Other Tools
ToolsPayload CreationInteresting Books
Interesting BooksEvading EDR: The Definitive Guide to Defeating Endpoint Detection Systems The author uses his years of experience as a red team operator to investigate each of the most common sensor components, discussing their purpose, explaining their implementation, and showing the ways they collect various data points from the Microsoft operating system. In addition to covering the theory behind designing an effective EDR, each chapter also reveals documented evasion strategies for bypassing EDRs that red teamers can use in their engagements.
Resources
Last updated
