/* * [crip.c - written by PoWeR_PoRK of netric (http://www.netric.org)] * * Another utility to use for shellcode creation. Works a bit like * cdump but instead of converting to c-declaration this rips the * declaration from a c-source and converts it back to binary. * This might be handy for re-encoding or reverse enginering * third party shellcode. * */ #include #include #define CH_OK -1 #define CH_BAD 1 #define STR_NOT_FOUND 0xFFFFFFFF #define CHAR_FSLASH 0x2F // "\" #define CHAR_BSLASH 0x5C #define CHAR_STAR 0x2A #define CHAR_SO 0x22 void * getstdin(unsigned long * cc); unsigned char h2c(char * hchars); unsigned int findstring(char * buffer, char * key, int start); int main(int argc, char **argv[]) { unsigned long stdinsize; unsigned int cbuf=0, c=0, c2=0, oldc=0, tmpfstr=0; char hexb[2]; char usage[]= "Usage: crip []\n" "pipe driven utility for ripping a c declaration of a char array\n" "in hex notation, converting it to binary and write it back to stdout.\n" "\n" " The name of the identifier associated with\n" " the char array that has to be ripped.\n" "\n" "Example: cat exploit.c | crip shellcode[] | swipher -c 00 | cdump\n" "This will rip shellcode[] from exploit, pipe the binary from it to\n" "swipher and this will remove any 0-bytes in the shellcode before\n" "feeding it to cdump making it into a c-declaration once again.\n" "\n" "[crip was written by PoWeR_PoRK of netric]\n" " contact: powerpork@zonnet.nl || powerpork@netric.org\n" " site: http://www.netric.org\n"; if(strlen((char *)&argv[1])==0){ printf("%s", &usage); exit(0); } (void *)cbuf = getstdin(&stdinsize); ((char*)cbuf)[stdinsize]=0; tmpfstr=findstring(((char*)cbuf), (char*)argv[1], 0); if(tmpfstr==STR_NOT_FOUND){ printf("error: name of buffer not found\n"); exit(0); } tmpfstr=findstring(((char*)cbuf), "\"", tmpfstr); tmpfstr++; c2=findstring((char*)cbuf, ";", tmpfstr); for(c=tmpfstr;c