‘Writing Small Shellcode In Windows’


This paper describes an attempt to write Win32 shellcode that is as small as possible, to perform a common task subject to reasonable constraints. The solution presented implements a bindshell in 191 bytes of null-free code, and outlines some general ideas for writing small shellcode.’


‘The information has been provided by Dafydd Stuttard.
The original article can be found at: http://www.ngssoftware.com/papers/WritingSmallShellcode.pdf


Size is important for shellcode because when exploiting vulnerabilities in compiled software we are often constrained in the amount of data we can work with. Smaller solutions than ours are certainly possible, but at this size the amount of work involved increases exponentially as each additional byte is trimmed from the code.
It is assumed that the reader has some familiarity with x86 assembly language.

The task to be performed by our code is as follows:
 1. Bind a shell to port 6666.
 2. Allow one connection to the shell.
 3. Exit cleanly.

It must work on Windows NT4, 2000, XP and 2003, and will be launched using:
    void main()
          unsigned char sc[256] = ”;
               ‘shellcode goes here’,
               lea eax, sc
               push eax

Hence, we can observe the following:
 * The shellcode cannot contain any null bytes.
 * The shellcode must be run from the stack.
 * Winsock has not been initialised.
 * We may assume that eax points to the start of our code.
Our full solution is in the Appendix to this paper. First, we present some notes on the approach taken and some of the details of the solution.

The full whitepaper can be downloaded from: http://www.ngssoftware.com/papers/WritingSmallShellcode.pdf.’

Categories: Reviews