Defense Evasion

Check Defenses

# Defender Status
(Get-MpComputerStatus).RealTimeProtectionEnabled

# Language Mode
$ExecutionContext.SessionState.LanguageMode

# AppLocker
## From Registry
Get-ChildItem 'HKLM:Software\Policies\Microsoft\Windows\SrpV2'
Get-ChildItem 'HKLM:Software\Policies\Microsoft\Windows\SrpV2\Exe'
# From Get-AppLockerPolicy cmdlet
$policy = Get-AppLockerPolicy -Effective
$policy.RuleCollections
# From GPO
beacon> ldapsearch (objectClass=groupPolicyContainer) --attributes displayName,gPCFileSysPath
beacon> ls $gPCFileSysPath
beacon> download $gPCFileSysPath

PS> Parse-PolFile -Path $file.pol

Evasion

Check Binary

Obfuscate Binary

Cobalt Strike Profile

  • SSH into team server and edit the profile:

  • Add the following chunk:

  • Restart the server

amsi_disable DOES NOT apply to the powershell command - use powerpick or psinject instead.

  • psexec spawnto

  • Some notable examples include System.Management.Automation.dll, which is required by powerpick and psinject. cryptdll.dll, samlib.dll, and vaultcli.dll are required by mimikatz.

  • So, PPID spoofing can help in avoiding detection:

Cobalth Strike Artifacts & Resources

  • Launch Visual Studio Code. Go to File > Open Folder and select C:\Tools\cobaltstrike\arsenal-kit\kits\artifact.

  • Navigate to src-common and open patch.c. Scroll to line ~45 and modify the for loop. This is for the svc exe payloads.

  • Scroll to line ~116 and modify the other for loop. This is for the normal exe payloads.

  • Save the changes (File > Save) and close the folder (File > Close Folder). On the Windows taskbar, right-click on the Terminal icon launch Ubuntu. Change the working directory.

  • Open the Cobalt Strike client and load artifact.cna from C:\Tools\cobaltstrike\custom-artifacts\mailslot.

  • Go to File > Open Folder and select C:\Tools\cobaltstrike\custom-resources. Select template.x64.ps1. Rename the func_get_proc_address function on line 3 to get_proc_address. Rename the func_get_delegate_type function on line 10 to get_delegate_type.

  • Scroll to line 32 and replace it with:

  • Select compress.ps1 and Use Invoke-Obfuscation to create a unique obfuscated version.

  • Open the Cobalt Strike client and load resources.cna from C:\Tools\cobaltstrike\custom-resources.

AppLocker Bypass

  • Path Wildcards

  • Writable Directories (%WINDIR%*)

  • LOLBAS (MSBuild)

Course Reference

PowerShell CLM

  • This can be abused by creating a custom COM object that will load an arbitrary DLL into the PowerShell process. This is a similar process to when we added registry entries for COM hijacking.

  • Now run the command to use it:

  • AppLocker can enforce DLL rules, but these are rarely enabled due to the performance concerns. When disabled, you can load arbitrary DLLs using rundll32. This requires that the DLL have at least one exported function that you call.

Last updated