Changeset 1628

Show
Ignore:
Timestamp:
06/19/08 16:45:51 (2 months ago)
Author:
common
Message:

libemu

  • sctest, introduce --cmd to allow overriding commands
    example sctest --cmd cmd="/bin/sh -c \"cd ~/.wine/drive_c/; wine 'c:\windows\system32\cmd_orig.exe' \"" will execute a real windows shell using wine if cmd is executed by shellcode
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • libemu/trunk/testsuite/sctest.c

    r1627 r1628  
    120120                        int port; 
    121121                }bind; 
     122 
     123                struct  
     124                { 
     125                        struct emu_hashtable *commands; 
     126                }commands; 
     127 
    122128        }override; 
    123129} opts; 
     130 
     131 
    124132 
    125133 
     
    15961604} 
    15971605 
     1606bool string_cmp(void *a, void *b) 
     1607{ 
     1608        if ( strcmp(a, b)  ) 
     1609                return true; 
     1610 
     1611        return false; 
     1612} 
     1613 
     1614uint32_t string_hash(void *key) 
     1615{ 
     1616    uint32_t hash = 0; 
     1617    char *c = (char *)key; 
     1618        uint8_t num = 0x13; 
     1619 
     1620        while (*c != 0) 
     1621        { 
     1622                hash = hash << (32-num) | hash >> (num); 
     1623//              hash = hash >> (32-num) | hash << (num); 
     1624                hash += *c; 
     1625                c++; 
     1626        } 
     1627 
     1628    return hash; 
     1629} 
    15981630 
    15991631 
     
    16771709                        dup2(psiStartInfo->hStdError,  fileno(stderr)); 
    16781710 
    1679                         system("/bin/sh -c \"cd ~/.wine/drive_c/; wine 'c:\\windows\\system32\\cmd_orig.exe' \""); 
     1711                        struct emu_hashtable_item *ehi = emu_hashtable_search(opts.override.commands.commands, "cmd"); 
     1712                        if (ehi != NULL) 
     1713                                system((char *)ehi->value); 
     1714                        else 
     1715                                system("/bin/sh -c \"cd ~/.wine/drive_c/; wine 'c:\\windows\\system32\\cmd_orig.exe' \""); 
     1716                         
    16801717                        exit(EXIT_SUCCESS); 
    16811718                } 
     
    24722509        { 
    24732510                {"a", "argos-csi"   , "PATH"    , "use this argos csi files as input"}, 
    2474                 {"b", "bind"            , "IP:PORT"     , "bind this ip:port"}, 
    2475                 {"c", "connect"         , "IP:PORT"     , "redirect connects to this ip:port"}, 
     2511                {"b", "bind"        , "IP:PORT" , "bind this ip:port"}, 
     2512                {"c", "connect"     , "IP:PORT" , "redirect connects to this ip:port"}, 
     2513                {"C", "cmd"         , "CMD"     , "command to execute for \"cmd\" in shellcode (default: cmd=\"/bin/sh -c \\\"cd ~/.wine/drive_c/; wine 'c:\\windows\\system32\\cmd_orig.exe' \\\"\")"}, 
    24762514                {"d", "dump"        , "INTEGER" , "dump the shellcode (binary) to stdout"}, 
    24772515                {"g", "getpc"       , NULL      , "run getpc mode, try to detect a shellcode"}, 
     
    24812519                {"l", "listtests"   , NULL      , "list all tests"}, 
    24822520                {"o", "offset"      , "[INT|HEX]", "manual offset for shellcode, accepts int and hexvalues"}, 
    2483                 {"p", "profile"                , "PATH"        , "write shellcode profile to this file"}, 
     2521                {"p", "profile"     , "PATH"    , "write shellcode profile to this file"}, 
    24842522                {"S", "stdin"       , NULL      , "read shellcode/buffer from stdin, works with -g"}, 
    24852523                {"s", "steps"       , "INTEGER" , "max number of steps to run"}, 
     
    27532791        opts.offset = 0; 
    27542792 
     2793        opts.override.commands.commands = emu_hashtable_new(16, string_hash, string_cmp); 
     2794 
    27552795        while ( 1 ) 
    27562796        { 
     
    27592799                static struct option long_options[] = { 
    27602800                        {"argos-csi"        , 1, 0, 'a'}, 
    2761                         {"bind"                         , 1, 0, 'b'}, 
    2762                         {"connect"              , 1, 0, 'c'}, 
     2801                        {"bind"             , 1, 0, 'b'}, 
     2802                        {"connect"          , 1, 0, 'c'}, 
     2803                        {"cmd"              , 1, 0, 'C'}, 
    27632804                        {"dump"             , 1, 0, 'd'}, 
    27642805                        {"getpc"            , 0, 0, 'g'}, 
    27652806                        {"graph"            , 1, 0, 'G'}, 
    27662807                        {"help"             , 0, 0, 'h'}, 
    2767                         {"interactive"      , 1, 0, 'i'}, 
     2808                        {"interactive"      , 0, 0, 'i'}, 
    27682809                        {"listtests"        , 0, 0, 'l'}, 
    27692810                        {"offset"           , 1, 0, 'o'}, 
    27702811                        {"profile"          , 1, 0, 'p'}, 
     2812                        {"steps"            , 1, 0, 's'}, 
    27712813                        {"stdin"            , 0, 0, 'S'}, 
    2772                         {"steps"            , 1, 0, 's'}, 
    27732814                        {"testnumber"       , 1, 0, 't'}, 
    27742815                        {"verbose"          , 0, 0, 'v'}, 
     
    27762817                }; 
    27772818 
    2778                 c = getopt_long (argc, argv, "a:b:c:d:gG:hilo:p:s:St:v", long_options, &option_index); 
     2819                c = getopt_long (argc, argv, "a:b:c:C:d:gG:hilo:p:s:St:v", long_options, &option_index); 
    27792820                if ( c == -1 ) 
    27802821                        break; 
     
    28182859                        break; 
    28192860 
     2861                case 'C': 
     2862                        { 
     2863                                char *cmd = strdup(optarg); 
     2864 
     2865                                char *value = strstr(cmd, "="); 
     2866                                *value = '\0'; 
     2867                                value++; 
     2868                                printf("command for %s is %s\n", cmd, value ); 
     2869                                emu_hashtable_insert(opts.override.commands.commands, cmd, value); 
     2870                        } 
     2871                        break; 
     2872 
    28202873                case 'd': 
    28212874                        dump(atoi(optarg));