‘Introduction to Shellcoding – How to Exploit Buffer Overflows’
The paper starts from a simple buffer overflow scenario, and explains how to detect the vulnerability and how to write an appropriate shellcode for it.’
‘The original article can be found at: http://tigerteam.se/dl/papers/intro_to_shellcoding.pdf‘
‘What Is a Shellcode?
Shellcode is a piece of machine-readable code, or script code that has just one mission; to open up a command interpreter (shell) on the target system so that an attacker can type in commands in the same fashion as a regular authorized user or system administrator of that system can do (with a few not-so-important exceptions of course). However, in order to get remote access to the shell, you’re going to need some kind of networking support in that shellcode too. There’s more to shellcoding than just having a program execute /bin/sh or cmd.exe. This white paper will introduce you to shellcodes, how they’re used in practice, and how they are used with buffer overflow vulnerabilities.
Since it’s important that the shellcode is very small, the shellcode hacker usually writes the code in the assembly programming language. In this white paper I will be using x86 Intel syntax assembly under Linux. The GNU compiler (gcc) uses AT&T syntax, which is somewhat different from Intel syntax. All assembly examples can be compiled with Netwide Assembler nasm a portable Intel syntax assembler available for a wide variety of operating systems. nasm is readily available in most GNU/Linux distributions.
What About the Code in Shellcode?
Shellcode is primarily used to exploit buffer overflows (including heap overflows) or format string bugs in binary, machine-readable software. In these software, the shellcode has to be machine-readable too, and to make things more complicated it can’t contain any null bytes (0x00). Null (0) is a string delimiter which instructs all C string functions (and other implementations) to, once found, stop processing the string (thus, a null-terminated string). There are other delimiters like linefeed (0x0A), carriage return (0x0D), 0xFF, and others. Some depend on how the programmer wrote the program (or the vulnerable function that handles input) and other implementations depend on underlying C library functions or 3rd party libraries, etc.’