An effort to help the naked virus.
Part 1
By: Sea4


Its pretty simple really... You have a naked virus, and the AV scanners will see everything it has at first glance. The payload, the search routines, the write to file requests, and possibly your name are all exposed to the prying eyes of F-Prot and the like. So, what are you to do? Once all your virus code is commented and researched they'll have a scanstring for it in no time, and ways of cleaning it. But that is not what we want, we want to make it difficult for them. We have to make them earn their paychecks. We want to extend the life of your virus in the wild.

Enter: Encryption Techniques

Hopefully, with your basic knowledge of ASM you realize your computer reads the bytes of every file you run. Every few bytes are a command to the CPU. So certain bytes like CDh 21h are commands, this is the INT 21h command. When an AV scanner searches files, it looks for byte combinations that look similar to those found in virii. If it finds some, your virus it screwed. To prevent this catastrophe, we must alter the very bytes of your virus to make them appear as anything, but what they really are. You may notice that if you leaf through an assembly language tutorial or book, there alot of commands that directly manipulate bits. Since each byte consists of 8 bits, changing those bits totally changes the function of the bytes, making them appear unlike virus code to any curious AV product.

Before I start explaining stuff though, let me give you a quick list of memory sizes, and their number of bits.

Use that as a reference when I refer to memory sizes and such. Some are not even referred to much even amongst ASM masters. The real important ones are the first 5, and Segment.

Now, I propose to show you the various bit altering ASM commands, and how to use them to hide. Lets start out with the most popular way to hide behind encryption. The famous XOR command! You have probably used it so far to make a byte = 0. Fortunetly for us, it has far more capabilities. What it does exactly is take the two operands and keep only different bits, placing them in the destination operand. For example:

Lets assume AL = 3h ( which is 3d also ) and BL = 12h ( which is 18d )

Now for the binary values:

Notice that only the bits different in each of the two bytes are kept. This makes it possible to get the original number, by doing a second XOR. Watch:

Now, your brain might be turning, and getting ahead of me. You might be saying to yourself "I think I know were he is goin' with this." If you don't I'll explain. Say you have your naked virus... and you take every byte in it, then you XOR them all against a bit mask like C4h :). It would change every single byte to something totally different. Then when you want to run the virus, you just XOR them all again to get back the original bytes that contain the virus code.

If that sounds confusing I'll put it in real simple terms. The first XOR above can be considered your Encryption, because it makes the bytes different than what you want to use. The second XOR would therefore be considered the Decryption, because it puts the bytes back into a useable format.

To better illustrate what I mean, I'll XOR CDh 21h ( INT 21h ) against a bit mask to hide it. Watch this:

Hehe, now the CD21h has been turned into a 0683h. Before an AV scanner would recognize the INT 21h command. Now it only can only see the 0683h, which is totally different than INT 21h to a scanner. 06h = Push ES, and 83 isn't even a whole command by itself. So if we did that to all bytes in our virus, we could make the virus appear as something it is not. Before running the virus code of course you must get back the original bytes, and I'll show that with the 0683h value and the bit mask.

There it is. XOR encryption, at its very essence. Now you may be asking "That is all well, and good, but how the hell do I tell my virus to Encrypt/ Decrypt itself?" Well, that is a little more difficult to do, but pretty easy to understand. So here is an example of a virus using encryption, it can be compiled using A86.com:

If you use the outline, the virus should be a thousand times easier to understand. To sum it up even more. The virus reads each byte of its code, encrypts them individually, then puts them in the buffer where they are then written to a victim.

Wow! I thought this would be a short text file. Oh well, I had to make it all real simple so everyone would understand. All I basically taught was how to understand XOR, and how to make a virus ready for encryption. The main aspect is to make sure it works. Encryption adds a whole lot of ways to screw your virus up royally, and will probably give you the biggest headache ever. But if you get it done right, its certainly worth it.

Since I am not really finished with everything I know about encryption, I will be writing a second part. Until then I think it would be helpful if you write several virii using encryption. At first, I reccommend you read over the virus I included, a few times. As well as the outline. You can paste it into a file of its own, then compile it to see how it works. After you get a feel for what is going on, try to write your own one without cut & paste. For a real challenge to the beginners. Try and add encryption to your first appending virus. By the time you get used to XOR, and basic encryption loops the second part of this tutorial should be finished. Here are a few ideas I have been kicking around:

  1. Using the other bit manipulators. ( NOT, NEG, ROR, ROL and such )
  2. Double encryption ( Twice the headache of normal encryption ) :-)
  3. XCHG encryption ( Neato )
  4. How to call the De/Encrypt loops ( Trust me, its important when using the other bit manipulators )
  5. Encrypting your virus after it has been run. ( Not hard really )
  6. Writing dual function De/Encrypt loops
  7. Writing seperate loops for Decrypting and Encrypting
  8. A quick example of how to add encryption to an appending virus. Its not really hard, its just where you put the call.

Well, I figure thats enough for now. Keep those virii encrypted because, a naked virus is a dead virus.

- Sea4@ThePentagon.com