Categories

How to write shell code – I

Writing shell code is perceived as a black art by many. The good news is that it is far from that. Anyone with a basic knowledge of programming and a desire to catch up on some basic assembly programming and CPU architecture can churn out shell code in less than an hour.

Lots of people have asked me for clarifications and tips for writing shell code. To this purpose, I will try to introduce how to quickly write your first shell code program. Believe me you will feel awesome. I remember I did!

Lets try to look at a basic loop in assembly:

start:
xor ecx,ecx
mov ecx,5
loop start

XORing the ecx register with itself is a standard way to set it as zero. Every time the loop progresses through the code, the value in the ecx register is decremented by 1, until it is zero.

Voila! You have an executable! Moreover if you type in ls -all, you will notice the size of the assembly is only 1/9th of the size of the plain text code. Now lets use the tool available at www.safemode.org and type in: