Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

AV Evasion

Disclaimers: I am not an expert on either AV solutions for both end-user as well as enterprise solutions, but have picked up a little bit.

How AV works in general:

Software has is categorized in one of the following lists :

BlackListing - blocked
WhiteListing - allowed to run

Malware is generally detected using one of the following:

Signature Based - Signature based detections uses specific header/strings/file size or patterns (packer used/byte sequence ..etc) within a file to check if it is good or bad.  These signatures are often found from malware samples.  Of course there can be false positives here.
Disadvantage: If you test enough you can find the signature and slightly change it, also compiling with a different compiler can change the signature.


Behavior Based - here the AV will try to determine the behavior of the software to see if it matches known techniques used by security tools or malware.  This is where often we may see a “trojan.gen” it is matching a heuristic pattern found in other malware.
Disadvantage: The software has to be analyzed within a sandbox and often encrypted/compressed of self modifying code is not analyzed during this. (Due to this you often have encrypted payloads being flagged)

Something else to note is that your AV requires a lot of resources and cannot analyze a program indefinitely, so if malicious actions are carried out afterwards  So also while sandboxes try to be hidden from malware often malware can scan for them and sleep until after the evaluation is complete.

(Note is that generally AV products do not do anything about exploitation, but Mcafee Enterprise solution does)

Not All AV's are the same:

Often we will find on VT (VirusTotal) the engines are more gears for heuristics and have beta signatures so it's not quite like your home AV solution.  Also false positives are more common.

In Memory Detections:

Below are common detection techniques pretty much consider them as “Tells” as well as tools to detect such odd behavior

• Memory Detection
  ◇ Process
     ▪ Parent Process
     ▪ Process Name
     ▪ Process Signer
     ▪ Valid Signature - code signing some MS products are not scanned since false positives will break an entire network
     ▪ Command Line Agrs
     ▪ Current working directory- Temp files are often flagged
  ◇ Thread
     ▪ Thread ID
     ▪ Start Address
     ▪ Start Address Module
     ▪ Priority
  ◇ Memory Properties
     ▪ Base Address
     ▪ Type of Memory
     ▪ State of Memory
     ▪ Size
     ▪ File
     ▪ Initial Permissions  (not in process hacker)
     ▪ Permissions

Tools for Detections:

Process Hacker
LOKI
YARA (used by some AV's)
Get-InjectedThread


Something to note here, "odd" things should not translate to “Intent” of an application being malicious.  AV solutions generally give a free pass to system critical as well as other security tools, because if a critical system file is flagged and it is a false positive that's going to be a lot of angry customers. We have our tools and we have an idea of what we are looking for but what exactly?

• Detection
  ◇ Thread Start Address - No module associated with the start address. Look for DLL that is not mapped in the current process mapped files. Programs call functions which are run under the program or a function in the DLL as a memory mapped DLL.
  ◇ Memory Permissions - RWX permissions common pattern or AllocateProtect and Protect Pairs, for example starting in RW then adding the X flag is a common indictator in offensive tools.
  ◇ Memory Content - Headers of a PE not associated with files on disk or the strings with that file. EG MZ This program cannot be run in DOS mode.
• Memory Detection Applications
  ◇ Point IN TIme Analysis - non persistent software deployed once. runs through current processes and threads, investigates content and properites reports signs of malicious activity allows human to make determination.. some false positives are OK
  ◇ RealTIme Detection/prevention - Less false positives are OK it can break the network or machine.  Persistent software; Even Driven Investigates content and properties correlating multiple signs.  From there is can do nothing or send an alert or terminate the action.  Some AV  and other solutions use these techniques

Now one should note that memory detection applications especially the ones preventing if they have a false positive remember those angry customers well they will be back. So now that we have a rough idea as to what exactly that we are dealing with how do we avoid it?

First let me ask when you start up chrome or firefox are you downloading a portable version and running it each time from a temporary directory? No that'd be crazy so stageless files on disk for the initial payload would help it would better blend in and appear more natural.  As we know nowadays IR (Incident Response) always should and will dump the memory, so consider encrypting that memory. Remember that each payload has it's own heuristics :

Evasion:

Before going to in memory first let us look at common methods for AV evasion :

• Polymorphism/Metamorphism - new signature on each run
• Encryption
• Sanbox Detection
• Process Injection
• Applocker Bypasses

Shellcoder loaders, are perhaps not commonly used but you can use python/c/powershell and more to load shellcode into memory during execution of your program or script.  Using ShellForge we can quickly take C source code, perhaps our dropper with a sleep function have it in assembly and have that shell code injected as part of a larger staged payload. The dropped file maybe a powershell script which will use an applocker bypass and inject our payload into an existing process.  

Detection is done by detecting anomalies and are not a indicator of intent: So not doing the things that we are going to be detected is important
• Thread Start Address
  ◇ EXE/DLL OK
  ◇ Process Hollowing: stick to architecture
  ◇ Avoid Hijacking Existing Remote Threads
• Do not start a new thread with an abitrary pointer.
  ◇  Instead hijack existing threads use SetThreadContext/LoadLibrary/CreateRemoteThread.. For LoadLibrary you will have to drop to disk.
• Memory Permissions:
  ◇  Avoid RWX instead map a DLL and over write the memory
• Memory Content:
  ◇ Don't look like a DLL unless expected
  ◇ Obfuscate or remove strings that can be used in IR
  ◇ avoid stagers
      ▪ Harder to notice the attacker by the content in the memory
Append NOP to start of payload

• Process Injection
  ◇ Allocate memory in remote process
  ◇ copy program to remote process
  ◇ Create thread to run program

• Process Hollowing
  ◇ Allocate memory in remote process
  ◇ Copy program to remote process
  ◇ Hijack existing thread to run program


A word on OPSEC:

After your payload is somewhat not quite ready to head out to the target say before you have used your code signing certificate we have to see what can be found if that file is captured.

Against your payload run (consider saving it as a bin here)

strings -e {s,S,b,l,B,L} payload.exe
strings payload.exe
hexdump -C payload.exe

In Metasploit using post modules such as “payload_inject” “reflective_dll_inject" and executing a new payload.

ProcessHollowing is fine for same architecture.


(Refrences and most will be posted @ 8000 character limit)


Let's discuss a bit the future of AV, in recent tests with using signature based detection researchers studying worm variants detected 323 features and were able to identify 5 more variants that were previously unknown. Using only 20 of the features they had a success rate of greater than 90%. AntiVirus researchers have also started to analyze OPCODE, assembly language instructions which interact with the CPU, as of right now researchers dealing with obfuscated malware are just over 85% successful, using this technique for detection.

(The Effects of Traditional Anti-Virus Labels on Malware Detection Using Dynamic Runtime Opcodes)


References:

https://en.wikipedia.org/wiki/Antivirus_software
https://en.wikipedia.org/wiki/Static_program_analysis
https://en.wikipedia.org/wiki/Dynamic_program_analysis
https://en.wikipedia.org/wiki/Heuristic_analysis
https://www.symantec.com/connect/article...-reference
The Antivirus Hacker’s Handbook
AntiVirus FIrewall Evasion Techniques Evolution Of Download Deploy Shellcode
WhitePaper: Bypassing Antivirus with a Sharp Syringe
Outsmarted: Why Malware Works in the face of Antivirus Software
The Effects of Traditional Anti-Virus Labels on Malware Detection Using Dynamic Runtime Opcodes
Perfect explaination
thanks man
YAK_CODER
TELEGRAM
(Mar 6, 2018 10:25 AM)YAK_CODER Wrote:  Perfect explaination
thanks man

Thank you I know it is a long read, nearly forgot payload heuristics

Payload Heuristics :
Quote:

Payload                       Migrates        RWX         Module-less Thread

EXE                                      x               x                       x
DLL                                      x               x                       x
DLL(x64->x86)                                       x    
PowerShell                          x        
Python                                 x
Service-EXE                         x
Service-EXE (x64->x86)        x                                          x
VBA                                       x               x                       x
Java                                     x
Java(x64)                              x                                        x

It's a nice addition to the community but perhaps this is more convenient and in-depth in terms of explanation: https://blog.cobaltstrike.com/2018/02/08...y-evasion/
Yes this is a a very good resource I missed that one in my original post and when I try to go back and edit it gives me an error that the post is far too long, I tried to stay away from just focusing on cobalt strike payloads and tried to keep it more general so with a bit of work users can apply these methods of evasion to their toolset. I did not get into stageless or staged payloads and how they work but the Cobalt Strike video series on this subject covers this as well as other mainly Cobalt Strike techniques. Also "Taking Back NetCat" really is what started me on this path when I created the following thread https://hackforums.net/showthread.php?tid=5767518 .
Great...many thanks learning all the time
(Mar 8, 2018 10:16 AM)emmabee Wrote:  Great...many thanks learning all the time

Awesome keep it up knowledge is very important never stop learning and don't be scared to get out of your comfort zone.
Dammn boi, thanks for the education.
You're Welcome, I hope that people test their payloads, doing things manually really is possible while it may take a little bit more than just running a tool it works rather well. I tested multiple payloads with process hacker with python/cs/powershell/cs/ shellcode loaders custom and including common solutions.

I also did some work with carving various injected processes while loaded in RAM to recover the file. Perhaps we need an anti-forensics discussion at some point.
HQ post,bookmarking this for future reference.
Posting to come back to, can be useful for dev
Free Direct File Hosting Service
Donations
LTC - Lgw3s3GzaWgVcCD2H1n2u1bnWHKPFU2SKo | BTC - 1LYMHXxtcyN1JrcSBkXgh1LrRzsLtV2AKk
HQ Thread, from HQ Member .
This article need to be PINNED .
Thnaks a lott for your big effort ;) :)
Thank you for all of the positive comments I appreciate it. If you want check out the references I made sure to include them so one can read and learn a bit more.
Great post and much appreciated. So much to learn . . . it never ends.
HQ tutorial mate keeping contributing to community.
Well written.
-snip-