Bypassing AntiVirus using
PowerShell
Profile
Satoshi Ogawa
Twitter:abend@number3to4
Burp Suite Japan User Group
ISOG-WG1
Empire
Post Exploitation
Framework
https://github.com/E
mpireProject/Empire
Empire
Victim Empire
http/https
Execution
Script
“Victim” is executed the script that is made by
Empire , Attacker can operate “Victim”.
C2 Server
Empire’s Script
Empire’s script has 2 types, PowerShell ,Python.
The attacker causes “Victim” to execute the script.
“Victim” regularly access the C2 server using
protocols such as http.
Empire’s PowerShell Script(PowerShell)
Empire’s PowerShell script
powershell –Nop –sta –w 1 –enc XXXXXXXX
Using these options
 NoP ・・・ NoProfile
 Sta ・・・ Single Thread Apartment
 w ・・・ WindowStyle
 enc ・・・ EncodedCommand(base64)
Empire’s PowerShell script
14 anti virus application can detect the script is
made by Empire.
Empire’s PowerShell script
Decode “EncodedCommand”
Empire’s PowerShell script
11 anti virus application can detect the script is
decoded BASE64.
Bypass one Anti Virus
One Anti Virus can’t detect “Invoke-Expression”
that is changed from “IEX”.
Technique of Obufcation 1
If($PSVERSIoNTabLe.PSVerSion.MAJoR -Ge 3)
Powershell is case-insensitive like MAJoR.
Technique of Obufcation 2
$GPF=[rEF].AsSEMBly.GetTypE('System.Managem
ent.Automation.Utils')."GETFiE`lD"('cachedGroup
PolicySettings','N'+'onPublic,Static');
Even if you write method or attribute value as a
character string, it is executed like “GETFiE`lD”.
> “abcd”.”Contains”(“bc”) ⇒ True
Technique of Obufcation 3
$GPF=[rEF].AsSEMBly.GetTypE('System.Managem
ent.Automation.Utils')."GETFiE`lD"('cachedGroup
PolicySettings','N'+'onPublic,Static');
“`” is an escape character and makes no sense
except reserved words.
Technique of Obufcation 4
Reserved word
`0 Null `r Carriage Return
`a alerm `t Tab
`b backspace `v Vertical Tab
`f form feed
`n new line
Technique of Obufcation 5
$GPF=[rEF].AsSEMBly.GetTypE('System.Managem
ent.Automation.Utils')."GETFiE`lD"('cachedGroup
PolicySettings','N'+'onPublic,Static');
“`l” is no meaning. “GETFiE`lD” is same GetField.
Invoke-Mimikatz
Invoke-Mimikatz is powershell script that can
execute Mimikatz.exe. Invoke-Mimikatz is
executed with the EXE file expanding the base64-
encoded character string on the memory.
Invoke-Mimikatz
For variable $PEBytes64, the character string
encoded with base64 of the 64-bit EXE file is set.
$PEBytes32 is for 32-bit.
Invoke-Mimikatz
Encode an arbitrary EXE file with base64 and set
it to variable $PEBytesXX. Also, delete
unnecessary options of the MAIN function. And
change the file name and function name.
Invoke-Mimikatz
By being able to execute arbitrary EXE files with
Powershell, it can be bypassed many antiviruses.
Invoke-Mimikatz
Change strings
that you want to
execute EXE file
is encoded
BASE64.
Invoke-Mimikatz
Maybe these
code is not
necessary your
exe file.
Invoke-Mimikatz
Customized Invoke-Mimikatz.ps1 is executed in
memory , it can be executed any exe file and
fileless.
Any EXE file
Invoke-Mimikatz.ps1
Anti Virus Software
I think that it is difficult for AV to detect
execution of malicious code.
Finally
• Pattern matching is difficult , so Sandbox is required.
(I expect Windows sandbox)
• Change settings to get execution log of powershell
• Limit PowerShell with AppLocker if you do not need to
run it
But, Applocker is not perfect because it is bypassable.
https://www.slideshare.net/abend_cve_9999_0001/bypassing-windows-security-functionsen

Bypassing anti virus using powershell