Changeset 1627
- Timestamp:
- 06/19/08 16:03:28 (4 months ago)
- Files:
-
- libemu/trunk/testsuite/sctest.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
libemu/trunk/testsuite/sctest.c
r1607 r1627 107 107 char *profile_file; 108 108 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; 109 123 } opts; 110 124 … … 1741 1755 } 1742 1756 1757 #include <sys/socket.h> 1758 #include <netinet/in.h> 1759 #include <arpa/inet.h> 1760 1761 1743 1762 uint32_t user_hook_bind(struct emu_env *env, struct emu_env_hook *hook, ...) 1744 1763 { … … 1752 1771 struct sockaddr* addr = va_arg(vl, struct sockaddr *); 1753 1772 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 } 1754 1785 1755 1786 va_end(vl); … … 1781 1812 int s = va_arg(vl, int); 1782 1813 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 1783 1828 socklen_t addrlen = va_arg(vl, socklen_t); 1784 1829 … … 2426 2471 struct help_info help_infos[] = 2427 2472 { 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"}, 2434 2478 {"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"}, 2439 2488 }; 2440 2489 … … 2523 2572 } 2524 2573 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); 2525 2583 2526 2584 /* set the flags */ … … 2700 2758 int option_index = 0; 2701 2759 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'}, 2706 2763 {"dump" , 1, 0, 'd'}, 2707 2764 {"getpc" , 0, 0, 'g'}, 2708 2765 {"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'}, 2715 2775 {0, 0, 0, 0} 2716 2776 }; 2717 2777 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); 2719 2779 if ( c == -1 ) 2720 2780 break; … … 2722 2782 switch ( c ) 2723 2783 { 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); 2726 2788 break; 2727 2789 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 } 2730 2803 break; 2731 2804 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 } 2739 2818 break; 2740 2819 … … 2758 2837 break; 2759 2838 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; 2762 2846 break; 2763 2847 … … 2770 2854 break; 2771 2855 2772 case 'a':2773 opts.from_argos_csi = strdup(optarg);2774 printf("argos-csi %s\n", opts.from_argos_csi);2775 break;2776 2856 2777 2857 case 'p': … … 2780 2860 break; 2781 2861 2782 2783 case 'i': 2784 opts.interactive = true; 2862 case 's': 2863 opts.steps = atoi(optarg); 2785 2864 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 2786 2883 2787 2884 default:
