Changeset 1627

Show
Ignore:
Timestamp:
06/19/08 16:03:28 (4 months ago)
Author:
common
Message:

libemu

  • sctest, opts orderd by name,
    introduced --connect/-c and --bind/-b to override connect/binds when run --interactive
Files:

Legend:

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

    r1607 r1627  
    107107        char *profile_file; 
    108108        bool interactive; 
     109 
     110        struct  
     111        { 
     112                struct 
     113                { 
     114                        char *host; 
     115                        int port; 
     116                }connect; 
     117                struct  
     118                { 
     119                        char *host; 
     120                        int port; 
     121                }bind; 
     122        }override; 
    109123} opts; 
    110124 
     
    17411755} 
    17421756 
     1757#include <sys/socket.h> 
     1758#include <netinet/in.h> 
     1759#include <arpa/inet.h> 
     1760 
     1761 
    17431762uint32_t user_hook_bind(struct emu_env *env, struct emu_env_hook *hook, ...) 
    17441763{ 
     
    17521771        struct sockaddr* addr   = va_arg(vl,  struct sockaddr *); 
    17531772        socklen_t addrlen = va_arg(vl,  socklen_t ); 
     1773 
     1774        if (opts.override.bind.host != NULL ) 
     1775        { 
     1776                struct sockaddr_in *si = (struct sockaddr_in *)addr; 
     1777                si->sin_addr.s_addr = inet_addr(opts.override.bind.host); 
     1778        } 
     1779 
     1780        if (opts.override.connect.port > 0) 
     1781        { 
     1782                struct sockaddr_in *si = (struct sockaddr_in *)addr;; 
     1783                si->sin_port = htons(opts.override.bind.port); 
     1784        } 
    17541785 
    17551786        va_end(vl); 
     
    17811812        int s                                   = va_arg(vl,  int); 
    17821813        struct sockaddr* addr   = va_arg(vl,  struct sockaddr *); 
     1814 
     1815        if (opts.override.connect.host != NULL ) 
     1816        { 
     1817                struct sockaddr_in *si = (struct sockaddr_in *)addr; 
     1818                si->sin_addr.s_addr = inet_addr(opts.override.connect.host); 
     1819        } 
     1820 
     1821        if (opts.override.connect.port > 0) 
     1822        { 
     1823                struct sockaddr_in *si = (struct sockaddr_in *)addr;; 
     1824                si->sin_port = htons(opts.override.connect.port); 
     1825        } 
     1826 
     1827 
    17831828        socklen_t addrlen = va_arg(vl,  socklen_t); 
    17841829 
     
    24262471        struct help_info help_infos[] = 
    24272472        { 
    2428         {"v", "verbose"     , NULL              , "be verbose, can be used multiple times, f.e. -vv"}, 
    2429                 {"s", "steps"       , "INTEGER" , "max number of steps to run"}, 
    2430                 {"t", "testnumber"  , "INTEGER" , "the test to run"}, 
    2431                 {"l", "listtests"   , NULL              , "list all tests"}, 
    2432                 {"d", "dump"        , "INTEGER" , "dump the shellcode (binary) to stdout"}, 
    2433                 {"g", "getpc"       , NULL              , "run getpc mode, try to detect a shellcode"}, 
     2473                {"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"}, 
     2476                {"d", "dump"        , "INTEGER" , "dump the shellcode (binary) to stdout"}, 
     2477                {"g", "getpc"       , NULL      , "run getpc mode, try to detect a shellcode"}, 
    24342478                {"G", "graph"       , "FILEPATH", "save a dot formatted callgraph in filepath"}, 
    2435                 {"h", "help"        , NULL              , "show this help"}, 
    2436                 {"S", "stdin"           , NULL          , "read shellcode/buffer from stdin, works with -g"}, 
    2437                 {"o", "offset"          , "[INT|HEX]", "manual offset for shellcode, accepts int and hexvalues"}, 
    2438                 {"i", "interactive"     , NULL          , "proxy api calls to the host operating system"}, 
     2479                {"h", "help"        , NULL      , "show this help"}, 
     2480                {"i", "interactive" , NULL      , "proxy api calls to the host operating system"}, 
     2481                {"l", "listtests"   , NULL      , "list all tests"}, 
     2482                {"o", "offset"      , "[INT|HEX]", "manual offset for shellcode, accepts int and hexvalues"}, 
     2483                {"p", "profile"         , "PATH"        , "write shellcode profile to this file"}, 
     2484                {"S", "stdin"       , NULL      , "read shellcode/buffer from stdin, works with -g"}, 
     2485                {"s", "steps"       , "INTEGER" , "max number of steps to run"}, 
     2486                {"t", "testnumber"  , "INTEGER" , "the test to run"}, 
     2487                {"v", "verbose"     , NULL              , "be verbose, can be used multiple times, f.e. -vv"}, 
    24392488        }; 
    24402489 
     
    25232572        } 
    25242573 
     2574        emu_memory_write_dword(mem, 0xef787c3c,  4711); 
     2575        emu_memory_write_dword(mem, 0x0,  4711); 
     2576        emu_memory_write_dword(mem, 0x00416f9a,  4711); 
     2577        emu_memory_write_dword(mem, 0x0044fcf7, 4711); 
     2578        emu_memory_write_dword(mem, 0x00001265, 4711); 
     2579        emu_memory_write_dword(mem, 0x00002583, 4711); 
     2580        emu_memory_write_dword(mem, 0x00e000de, 4711); 
     2581        emu_memory_write_dword(mem, 0x01001265, 4711); 
     2582        emu_memory_write_dword(mem, 0x8a000066, 4711); 
    25252583 
    25262584        /* set the flags */ 
     
    27002758                int option_index = 0; 
    27012759                static struct option long_options[] = { 
    2702                         {"verbose"          , 0, 0, 'v'}, 
    2703                         {"steps"            , 1, 0, 's'}, 
    2704                         {"testnumber"       , 1, 0, 't'}, 
    2705                         {"listtests"        , 0, 0, 'l'}, 
     2760                        {"argos-csi"        , 1, 0, 'a'}, 
     2761                        {"bind"                         , 1, 0, 'b'}, 
     2762                        {"connect"              , 1, 0, 'c'}, 
    27062763                        {"dump"             , 1, 0, 'd'}, 
    27072764                        {"getpc"            , 0, 0, 'g'}, 
    27082765                        {"graph"            , 1, 0, 'G'}, 
    2709                         {"help"                         , 0, 0, 'h'}, 
    2710                         {"stdin"                        , 0, 0, 'S'}, 
    2711                         {"offset"                       , 1, 0, 'o'}, 
    2712                         {"argos-csi"            , 1, 0, 'a'}, 
    2713                         {"profile"                      , 1, 0, 'p'}, 
    2714                         {"interactive"          , 1, 0, 'i'}, 
     2766                        {"help"             , 0, 0, 'h'}, 
     2767                        {"interactive"      , 1, 0, 'i'}, 
     2768                        {"listtests"        , 0, 0, 'l'}, 
     2769                        {"offset"           , 1, 0, 'o'}, 
     2770                        {"profile"          , 1, 0, 'p'}, 
     2771                        {"stdin"            , 0, 0, 'S'}, 
     2772                        {"steps"            , 1, 0, 's'}, 
     2773                        {"testnumber"       , 1, 0, 't'}, 
     2774                        {"verbose"          , 0, 0, 'v'}, 
    27152775                        {0, 0, 0, 0} 
    27162776                }; 
    27172777 
    2718                 c = getopt_long (argc, argv, "vs:t:ld:gG:hSo:a:p:i", long_options, &option_index); 
     2778                c = getopt_long (argc, argv, "a:b:c:d:gG:hilo:p:s:St:v", long_options, &option_index); 
    27192779                if ( c == -1 ) 
    27202780                        break; 
     
    27222782                switch ( c ) 
    27232783                { 
    2724                 case 'v': 
    2725                         opts.verbose++; 
     2784 
     2785                case 'a': 
     2786                        opts.from_argos_csi = strdup(optarg); 
     2787                        printf("argos-csi %s\n", opts.from_argos_csi); 
    27262788                        break; 
    27272789 
    2728                 case 's': 
    2729                         opts.steps = atoi(optarg); 
     2790                case 'b': 
     2791                        { 
     2792                                opts.override.bind.host = strdup(optarg); 
     2793                                char *port; 
     2794                                if (( port = strstr(opts.override.bind.host, ":")) != NULL) 
     2795                                { 
     2796                                        *port = '\0'; 
     2797                                        port++; 
     2798                                        opts.override.bind.port = atoi(port); 
     2799                                } 
     2800 
     2801                                printf("override bind %s:%i\n", opts.override.bind.host, opts.override.bind.port); 
     2802                        } 
    27302803                        break; 
    27312804 
    2732                 case 't': 
    2733                         opts.testnumber = atoi(optarg); 
    2734                         break; 
    2735  
    2736                 case 'l': 
    2737                         list_tests(); 
    2738                         return 0; 
     2805                case 'c': 
     2806                        { 
     2807                                opts.override.connect.host = strdup(optarg); 
     2808                                char *port; 
     2809                                if (( port = strstr(opts.override.connect.host, ":")) != NULL) 
     2810                                { 
     2811                                        *port = '\0'; 
     2812                                        port++; 
     2813                                        opts.override.connect.port = atoi(port); 
     2814                                } 
     2815 
     2816                                printf("override connect %s:%i\n", opts.override.connect.host, opts.override.connect.port); 
     2817                        } 
    27392818                        break; 
    27402819 
     
    27582837                        break; 
    27592838 
    2760                 case 'S': 
    2761                         opts.from_stdin = true; 
     2839                case 'i': 
     2840                        opts.interactive = true; 
     2841                        break; 
     2842 
     2843                case 'l': 
     2844                        list_tests(); 
     2845                        return 0; 
    27622846                        break; 
    27632847 
     
    27702854                        break; 
    27712855 
    2772                 case 'a': 
    2773                         opts.from_argos_csi = strdup(optarg); 
    2774                         printf("argos-csi %s\n", opts.from_argos_csi); 
    2775                         break; 
    27762856 
    27772857                case 'p': 
     
    27802860                        break; 
    27812861 
    2782  
    2783                 case 'i': 
    2784                         opts.interactive = true; 
     2862                case 's': 
     2863                        opts.steps = atoi(optarg); 
    27852864                        break; 
     2865 
     2866 
     2867                case 'S': 
     2868                        opts.from_stdin = true; 
     2869                        break; 
     2870 
     2871                case 't': 
     2872                        opts.testnumber = atoi(optarg); 
     2873                        break; 
     2874 
     2875                case 'v': 
     2876                        opts.verbose++; 
     2877                        break; 
     2878 
     2879 
     2880 
     2881 
     2882 
    27862883 
    27872884                default: