I have been searching a lot and I didn't find anything. I still wonder: does it matter in which language you write shellcode? Will shellcode in Assembly, C, etc. work everywhere they can be used and be as good as the other?

  • Notepad is usefull! – F. Hauri Dec 11 '17 at 7:22

The term "shellcode" comes from the fact that it is typically used to gain shell access on the machine. In most cases, shellcode is used when there is a memory corruption-based vulnerability (e.g. buffer overflow) where the attacker is able to write to parts of memory that will be executed or caused to execute. This needs to be machine code, since it is being executed directly by the CPU.

Since there is often limited space to work with in the buffer, shellcode is often designed to be as short as possible, thus it is often written by hand in assembly and dumped to an escaped bytes sequence (e.g. "\x23\xa4\x00"). It is possible to write a C program, compile it, then dump the bytes like above, but the C compiler may introduce unnecessary complexities and add additional length. Usually, the shellcode will be short, and could pull down a second stage off the network if a longer payload is desired.

In short, you need machine code, and it doesn't really matter whether this code came from C or assembly, excepting what was said above. However, the definition of shellcode is somewhat loose and could be applied to interpreted languages as well (e.g. getting a shell by exploiting an unsanitized call to eval() in a Python application), although it is typically not the chosen word in these cases.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.