Bypassing Anti-virus

Whether compromising a system for legitimate or non-legitimate purposes, bypassing anti-virus software is often an integral step in any intrusion exercise. Fortunately for enterprise, anti-virus and anti-malware software is now commonplace in most organisiations.

Whilst many of the tools that attackers wish to implement are constantly being blacklisted, this isn't without reservation. Attackers are still getting malware into systems and penetration testers are still able to compromise systems. So the question is, how is this possible? The answer: Bypassing anti-virus, of course.

In this post I intent to present several tools that can be used in bypassing anti-virus/anti-malware software. I will provide a brief background on each tools operation and a summary of its use. But first, some background.

Anti-virus software typically works by using either signature-based detection or heuristic-based detection (some products use both).

Signature-based detection products rely on receiving updates from the anti-virus vendor. Anti-virus vendors such as McAfee, Symantec, Sophos etc. work 24 hours a day 7 days a week to continually update their databases with newly discovered malware. Every time a new piece of malware is identified, a 'fingerprint', or 'signature' of the malware is made. These uniquely identifiable signatures are periodically downloaded by anti-virus clients and are used to identify malicious files. Software that the vendor has identified as malicious is able to be caught by the anti-virus software because an infected file's 'signature' (or fingerprint) matches that of the signature downloaded from the vendor. Signature-based detection can be seen as analogous with making a comparison. ie We compare the infected file's signature with the signatures I have in my database. Do the signatures match? If they do, we know the program is malicious and it goes into quarantine. If not, the program is safe and we can let the program run.

Heuristic-based detection is somewhat different. In the mathematics and computer science disciplines, the term heuristic can be simply described as a 'best guess'. Instead of making a signature comparison, heuristic-based detection looks at what the software is actually doing, as opposed to what it looks like. Based on behavior, heuristic-based products quarantine software that is acting suspiciously. So if a program is misbehaving by trying to elevate its privileges on a system, there is a possibility it may be flagged for quarantine. Heuristics-based detection is often prone to false positives, and as such, is not as common as it's signature-based counterpart.

Now lets talk about their shortcomings of signature-based detection.

Signature-based detection is overcome by something known as obfuscation. Code obfuscation is the process of changing the appearance of a program's source code. This can be done in many different ways, including: substituting for loops for while loops; eradicating loops with recursion; compression techniques; renaming variables; altering strings; and so on.

So now if we think back to how signature-based detection works, we can quickly see that it is near impossible for an anti-virus vendor to blacklist all the possible combinations of how a program can appear. And here in lies the dilemma. Anti-virus vendors can indeed continue to blacklist known malware, but this falls short reasonable quickly when programs can be obfuscated in a myriad of different ways.

Whilst there a many ways one can obfuscate a program's code, I am only going to discuss three here. These are three of the most common and simple tools for achieving anti-virus avoidance.

UPX Packer
Packing is a simple way to disguise executables. By adding a decompression header to the front of a the packed executable, the executable is able to be read and inflated in memory by the operating system.

The Ultimate Packer for eXecutables (UPX)
is a free, open source, portable packer written by Markus F.X.J. Oberhumer, László Molnár and John F. Reiser.

Usage:
upx [-123456789dlthVL] [-qvfk] [-o file] file...

Commands:
-1 compress faster -9 compress better
-d decompress -l list compressed file
-t test compressed file -V display version number
-h give more help -L display software license
Options:
-q be quiet -v be verbose
-oFILE write output to 'FILE'
-f force compression of suspicious files
-k keep backup files
file.. executables to (de)compress
PE-Scrambler
PE-Scrambler is a simple utility written by Nick Harbour that scrambles and obfuscates binaries at the machine code instruction level. Altering the Opcodes at the lowest level, this utility is a highly effective obfuscator.

Usage:
> pescrambler.exe -i [inputfile.exe] -o [outputfile.exe]

Resources:
Interview with the author
Author's presentation on the tool

msfencode/msfpayload
These two tools come standard with the Metasploit Framework. Whilst in previous versions of Metasploit it required a bit of a hack to obfuscate Metasploit payloads, the latest release (3.3) makes the process trivial. I would like to point you to Adrian Crenshaw's posting on IronGeek for this one. He has recently posted a very nice video tutorial on the process.

So, what was the point of me telling you all this? Was it to tell you that anti-virus software is dead and you should just uninstall it completely from your network? Hardly.

My intentions here were to inform people that anti-virus, like all security controls, has its weaknesses. Anti-virus should no longer be looked at as the be all and end all of end-point system protection. It should be, like every other control, one of multiple mechanisms within a multi-tiered security architecture.

Here are some additional controls that can compliment anti-virus software:

Host-based intrusion prevention/detection systems
Host-based firewall logging (Win)
Host-based firewalling (Unix)
Application white-listing

Additional Resources:
Chris Brenton's talk on why AV is dead

Comments

  1. Hi there,

    That was a nice and informative write-up but I've a question.

    I use msfpayload to convert a payload into an exe for eg.trickortreat.exe Then using the multi/handler in msfconcole and typing exploit I wait for the file to be clicked on my host system (Win XP)which when clicked gives me the meterpreter session.

    However when I use PE Scrambler to obfuscate trickortreat.exe this time that file simply fails to give a response in msfconsole. I keep the filename of the output as the same as input.Is it because PE Scrambler and msfconsole dont work together? What can the problem be?? I've disabled my Norton Internet Security 2011 in this case to test this first without an AV/Firewall

    Also what knowledge is required to make your own crypter or finding vulnerabilities in Win OS & Win Apps. Most of the people that I've asked in forums and elsewhere have recommended C, C++ and x86 Assembly Language.
    Do u recommend anything else??

    Please help and advise

    ReplyDelete
  2. Hi there,

    That was a nice and informative write-up but I've a question.

    I use msfpayload to convert a payload into an exe for eg.trickortreat.exe Then using the multi/handler in msfconcole and typing exploit I wait for the file to be clicked on my host system (Win XP)which when clicked gives me the meterpreter session.

    However when I use PE Scrambler to obfuscate trickortreat.exe this time that file simply fails to give a response in msfconsole. I keep the filename of the output as the same as input.Is it because PE Scrambler and msfconsole dont work together? What can the problem be?? I've disabled my Norton Internet Security 2011 in this case to test this first without an AV/Firewall

    Also what knowledge is required to make your own crypter or finding vulnerabilities in Win OS & Win Apps. Most of the people that I've asked in forums and elsewhere have recommended C, C++ and x86 Assembly Language.
    Do u recommend anything else??

    Please help and advise

    ReplyDelete
  3. This really is a awesome post, I’m happy I recently found. I have been trying to find guest writers for my blog so if you ever decide that’s something you are interested in please feel free to contact me. I will be back to look at out more of your articles later!

    ReplyDelete
  4. This comment has been removed by a blog administrator.

    ReplyDelete

Popular posts from this blog

Cracking OS X Lion Passwords

Cracking Mac OS X Passwords

Metasploit Autopwn: Hacking made simple