Search blog.co.uk

About me

tibbar

tibbar

Calendar

<<  <  July 2008  >  >>
Mo Tu We Th Fr Sa Su
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      

Last comments

Defeating Anti-Virus with Crypters

by tibbar @ 2006-02-16 - 00:30:29

I've promised I would explain why you cannot trust Anti-Virus software.

As this is a long topic, I will spread the tutorial over several blog entries, when I have time to spend here.

To understand how to defeat AV, you first need to understand how they work.

The key principle that has underpinned virus detection for the last 10 years, is to recognise viri not by their behaviour, but through a digital signature of their code.

Let me explain this more carefully... the AV program has probably around 100,000 files to scan on a typical hard drive. It's a very slow process to check each file in detail, so what AV do is to have a database of signatures (each signature is a piece of binary code that uniquely identifies the virus), and they simply check each file for a known signature.

This is much quicker than actually trying to determine what a particular executable's behaviour is.

Many AV can also do "heuristic" scanning. This sounds rather clever, but in fact it is not! Usually this means the AV will flag near matches to signatures as well, when performing the scan.

Finally, many AV will perform a "memory scan". This sounds like they are scanning the memory of each running process for known virus signatures. The truth is somewhat different - most AV "memory scans" are actually doing the following:

1) enumerate all running process names
2) for each process, scan the disk image of the process for known virus signatures.

only one or two products actually perform a real memory scan (none of the mainstream AV do a real memory scan).

Ok, so what we now know is that to defeat AV, the malware needs to be free of any bytes of code that match known virus signatures.

This means there are several options open to the hacker. She can:

a) write her own malware from scratch, which will be new and unknown to AV

b) use a "packer / crypter" to alter the binary image on disk, so that AV cannot match any signatures to the "packed / crypted" file.

c) use a code perversion engine, that will substitute equivalent opcodes for each opcode used in the executable's code. This is an extremely complex process and no public tools exist to achieve this fully (I have been working on this, but the tool is not complete). Z0mbie wrote a basic perversion tool some time back. His comments about it are:

Almost all trojans and viruses are detected using simple signatures. Which means that simple crc is calculated on the entire file, or on some parts of the code being checked.

There are thousands of simple signatures already stored in the antiviral databases. Each signature is equivalent to hours of an aver's work.

Using simple length disassembler and some simple rules, it is possible to analyze an arbitrary executable file and change some instructions in it, so that it will run the same as before, but file's checksum will be changed.

This means that antivirus will no longer be able to identify these files by using the previous checksums.

A tool called "Code Pervertor" was written some years ago. It can analyze a PE file and swap a few equivalent instructions, such as "test eax, eax" with "or eax, eax" and vice versa.

Another similar process is "diversification", which means the random changing of some data offsets within all system DLLs and services. Diversification complicates exploitation based on fixed address usage and will probably soon be implemented as a security measure.

Now imagine that some worm "perverted" and "diversified" all executable files it found on a machines over the net. It is likely that the same vulnerable machines will also contain trojans. So when all these trojans become unique, what avers will do?

There are two methods of detecting such a modified files.

First method is to modify files before analyzing, the same as "code pervertors" do, but without the randomization. For example, if some instructions can be interchanged with each other, perform one-way changes only, for example replace all "or eax, eax" with "test eax, eax", but not vice versa.

This method has tons of negative aspects: there can be many different methods of file modification, but some of them can be irreversible.

The second method consists of re-writing all checksum algorithms and recalculating all the signatures. The new checksum algorithm should become invariant to simple modifications such as swapping equal or interchangable instructions with each other.

This method is something like image recognition, where the new algorithm can return an equal result for many different data inputs.

This method also has a serious disadvantage. If someone introduced a new file modification method, the checksum algorithm will have to be once again changed and all the antiviral signatures recalculated.

A few hundred infected machines with automatic "pervertors" will catch all the new just-released worms and viruses and modify 'em "on the fly", automatically spawning new variants.

Option c) if ever achieved will render all AV absolutely useless. Scary eh?

Option a) is a reasonable choice, but our hacker may not have the necessary skills to write all the nasty tools she needs, and also once they are released in the wild, AV will eventually put signatures on them, which will mean she has wasted her time coding them.

This leaves option b) as the best solution to defeating AV at the current time.

Now, what exactly do I mean by packing / crypting?

Essentially, the technique involves taking all the code and data from an executable file, and applying an encryption algorithm to it, to ensure no signatures can be matched on it.

The new "packed / crypted" executable will include the encrypted data and code from the original executable, plus a "stub". The "stub" is a piece of code that can decrypt and reconstruct the original executable dynamically at runtime.

This means that on disk, the crypted executable is undetected to AV scanners, but once it is executed, it will behave and appear exactly like the original file.

A packer is exactly the same as a crypter, except that instead of using an encryption algorithm, it uses a compression algorithm. This makes the file both undetected and much smaller in size.

This all sounds pretty bad from the AV perspective. Fortuntely, in practice, the number of crypters and packers available on public sites is quite small. The AV firms analyse packers and crypters that they find, and alter the AV signatures to detect files that are packer / crypted using known packers / crypters. Some AV will include a decryption algorithm in their scanners, so they can find out what lies beneath!

Now, for some bad news... It is surprisingly easy to create your own crypter, and most private hacking groups have made their own custom crypters or packers.

One public crypter that beat most AV for a period of over a year, was morphine from www.hxdef.org. This is quite an advanced crypter, but given the resources available to AV firms, I was shocked how slowly they responded.

Let me reinforce this point. All private packers or crypters are undetected to AV. This means malware will not be detected by AV scanners, when using private packers or crypters.

So you should never trust you AV when it tells you a file is clean. If that file comes from an untrusted source be very suspicious. Use run as limited user if you must execute it. Also consider using a virtual machine and try using online scanners like http://www.virustotal.com to perform multi-scans against all AV engines - these tend to catch more things, than a single AV.

Next blog will tell you how to write you own crypter...


 
 

Trackback address for this post:

authimage

Comments, Trackbacks: Hide subcomments

skip2468skip2468 [Member]
16/02/06 @ 00:59

Thank you for all the very interesting and useful information including the link/s

tibbartibbar [Member]
16/02/06 @ 02:32

well the best way of saying thx is to visit the sponsors :D

paradox [Visitor]

16/02/06 @ 02:42

Nice blog,
Self-mutating code.. polymorphic engines are around but they are not truly polymorphic they still follow A set of rules.. Be good if you could finally get your code working ^_^
maybe I should start a blog

Alex [Visitor]

16/02/06 @ 07:59

Wow, thats something unexpected (that AVs mainly do only signature scans), but when I have limited knowledge of malware, I can't expect anything other than surprises.

So from the way you descibed it, AVs scan for signatures in packers, right?

Well, then why not take the idea of creating polymorphic code, then why not write a polymorphic packer/crypter (a cryper would probably easier, i think), which would rewrite the cypter on-the-fly, and maybe pack all the files, and I would think that would be easier to do than to try to morph the code.

Now, if you were to write anti-virus software, what would you try to do? Would you try and see what files actually do? (please, remember, I have a very limited idea of things here, so I'm probably talking out of my ass) Run the program inside a debugger (the Av being the debugger), and see if it tries to set up some kind of hooks, or access certain memory, or otherwise analise behaviour?

"well the best way of saying thx is to visit the sponsors :D"
Err, I feel stupid, but where are the sponsor links? or are they the blog.* links?

tibbartibbar [Member]
16/02/06 @ 09:38

polymorphic crypters exist and cause major problems for AV, this is why morphine stayed undetected for a long time - the AV writers had to think a bit harder on how the polymorphic signature changes.

at present there is no truely polymorphic packer, but it would not be impossible to create.

AV should move to a system of anaylsing behaviour, by running the suspected app in a sandbox environment - e.g. using emulated winapi to see what it actually does.

Of course this is much slower. The best solution imo is a combination of signatures for disk scanning and sandbox analysis before execution is allowed.

oh and the sponsors are the google ads appearing on the sides of the blog. if any look interesting to you, and you find the material i publish useful, please take a minute or two to visit them.

tibbar.

Alex [Visitor]

16/02/06 @ 10:56

Thanks for the info tibbar, do you know anything about how signatures for morphine were developed?

"oh and the sponsors are the google ads appearing on the sides of the blog. if any look interesting to you, and you find the material i publish useful, please take a minute or two to visit them." Doh! I forgot I had Adblock turned off *Whitelists tibbar.blog.co.uk, then goes and clicks on links*

jonny" [Visitor]

16/02/06 @ 14:06

yes but the crypters have a BIG problem
.. the fact that the malware can be easily
found in memory ..
this is exactly what happened to me ..
I had for 8 years my personal undetectable
server ,made by changing something in the upx stub and after that correcting the upx crc .. so that the avs recognize it like a legit upx packed file , unpake it ,with theyr OWN routines (not with the modded stub :-)) and get a meaningless file ..
but recently some avs were able to find the server in memory ..still not on the disk ..(that's funny) ..
so I thing that the best way is to work on the unpacked file by perversion or better having the source code , modifing something ..

tibbartibbar [Member]
16/02/06 @ 14:12

correct, but the mainstream AV are not doing this yet. only a couple of less popular ones do this at the moment.

jonny\" [Visitor]

16/02/06 @ 14:38

mmm.. if I'm not wrong it was the latest norton that get it ..
what are these less popular ones that should do it at the moment ?

tibbartibbar [Member]
16/02/06 @ 15:07

last time i checked, norton, mcafee and kav do not perform memory scans, but i could be wrong.

Brad [Visitor]

17/02/06 @ 22:54

I'm definitely not up-to-par with this information, but I do have a very well-rounded understanding of computers. I have toyed with several security tools, and my question is why not just create a tool that creates unique packers/crypters from random strings?

benny [Visitor]

04/04/06 @ 15:26

nod32 rocks for this !! , pretty hard to bypass , no ?

somename [Visitor]

24/12/06 @ 11:27

KAV6 scans memory then scans all files and DLLs in a process, every file it imports etc. It doesn't scan inside the memoryspace as far as I can tell, but primitive tools would call ReadProcessMemory (which could be hooked! so whats the point), KAV6 can use much better tricks from its kernel scanning tools or even access the PhysicalMemory device to do scanning if needed when a real malware threat emerges ITW.

True, they do signature scanning, but they have many types of signatures including masks, heuristic signatures (combination of checking imports or small bits of code or masks or other tricks that are no longer disclosed for obvious reasons)

The same goes for NOD32 and surely others, they have smart people who have worked against viruses. When perversion becomes big engines like NOD32 will still do well I feel.

The fact you fail to see is that AV need to worry about the malware out there, not theory.

Put one of these crypted files on a 100,000 public machines like in a Blaster worm and every AV with an emulator (KAV uses an emulator and static unpacking combo) will be unpacking it in no time flat and your packer will be dead. Face the truth.

True, there are problems with engines detecting things like this, in a controlled environment anything is possible.

True there are also many more misses but it is the work of the malware community that cause most misses. Making them busy was the main thing that has changed over the years, much much more malware per day and changes in the way malware evolves until a new codebase is used. It can last a long time and become undetected over and over against many types of AV engine OR most importantly against the individual analysts in a large company that don't see each sample together and can connect them as variants of each other. Inexperienced analysts would fall prey to this.

These are much bigger factors in the real world and in AV companies working days. Their staff numbers continue to rise and will have to stay this way until Vista is heavily adopted. Perhaps then things will quieten down..

somename [Visitor]

24/12/06 @ 11:30

NORMAN AV uses a Sandbox and can also be fooled, it has an emulation limit of half a million CPU cycles.. could be 5 million.

There is a commercial one available, Norman is definitely a future competitor. They have decent signatures.

Τhalia [Visitor]
http://funel.blogspot.com
28/01/07 @ 17:05

I saw somewhere an extensive study of AVs against packed/crypted malware.

F-Secure,KAV,NOD32,Bit_Defender were top in packed malware recognition.

Morphine was already detected by most of the AVs and only 2-3 packers were still doing the job, tricking even the best of the AV vendors.

NAV was tricked easily sometimes.

Very Funny

Michael Kangnais [Visitor]

11/05/07 @ 08:35

Is there anything come up on Code perverting or diversification. What is meaning of polymorphic code. Does someone know code of stub which can bypass Norton

Smithson [Visitor]
http://smithson.blog.co.uk/
04/07/07 @ 12:36

Very useful. Thx i had some problems with my Win XP

Leave a comment :

Your email address will not be displayed on this site.
Your URL will be displayed.
Allowed XHTML tags: <!, p, ul, ol, li, dl, dt, dd, address, blockquote, ins, del, a, span, bdo, br, em, strong, dfn, code, samp, kdb, var, cite, abbr, acronym, q, sub, sup, tt, i, b, big, small, img>
URLs, email, AIM and ICQs will be converted automatically.
Options:
 
(Line breaks become <br />)
(Set cookies for name, email & url)
All comments on this blog will be moderated by the author.
Validation code:
Please enter the above code here:
For protection from spambots (case-sensitive).

Recent Posts

  1. Reflecting on better times
    by tibbar on 2008-07-21
  2. CodeCrypter 1 Year On
    by tibbar on 2006-12-26
  3. Hooking drivers
    by tibbar on 2006-12-22
  4. linux server framework
    by tibbar on 2006-10-19
  5. ReactOS
    by tibbar on 2006-07-15
  6. update
    by tibbar on 2006-06-18
  7. What comes next?
    by tibbar on 2006-04-11
  8. Kernel Mode Ircbot
    by tibbar on 2006-04-06
  9. codeCrypter next release plans
    by tibbar on 2006-03-31
  10. jotti scan
    by tibbar on 2006-03-23