25 #include <sys/ptrace.h>
48 static int final_result_counter = 0;
50 static int oldformat = 0;
64 g_hash_table_iter_init(&iter,
probes);
65 while (g_hash_table_iter_next(&iter,
72 g_hash_table_destroy(
probes);
82 struct probe *trigger,
struct probe *base) {
95 "RESULT:: (i:%d) rop (2) CFIViolation \"CFI violation!\""
96 " (retaddr=0x%"PRIxADDR",violations=%d,total=%d,"
97 "fpviolations=%d,jmpfpviolations=%d,jccfpviolations=%d,"
98 "isfpviolation=%d,gadgetstart=0x%"PRIxADDR","
109 fprintf(stdout,
"%s: CFI violation %s",
probe_name(probe),
118 array_list_append(rop_violation_list,buf);
122 fprintf(stdout,
"RESULT:: (i:%d) rop (0) CFIClean \"CFI clean\""
123 " (retaddr=0x%"PRIxADDR",violations=%d,total=%d,"
124 "fpviolations=%d,jmpfpviolations=%d,jccfpviolations=%d,"
125 "isfpviolation=%d,gadgetstart=0x%"PRIxADDR","
136 fprintf(stdout,
"%s: CFI clean",
probe_name(probe));
137 fprintf(stdout,
" (retaddr=0x%"PRIxADDR",violations=%d,total=%d,fpviolations=%d,jmpfpviolations=%d,jccfpviolations=%d)\n",
159 {
"overlay",
'V',
"<name_or_id>:<spec_opts>",0,
"Lookup name or id as an overlay target once the main target is instantiated, and try to open it. All spec_opts (normal target/dwdebug opts) then apply to the overlay target.",0 },
176 return ARGP_ERR_UNKNOWN;
179 if (state->quoted > 0)
180 opts->
argc = state->quoted - state->next;
182 opts->
argc = state->argc - state->next;
183 if (opts->
argc > 0) {
185 memcpy(opts->
argv,&state->argv[state->next],opts->
argc*
sizeof(
char *));
186 state->next += opts->
argc;
193 case ARGP_KEY_NO_ARGS:
194 case ARGP_KEY_SUCCESS:
206 argptr = index(arg,
':');
208 verror(
"bad overlay spec!\n");
211 argv_list = array_list_create(32);
212 array_list_append(argv_list,
"dumptarget_overlay");
218 while (*argptr ==
' ')
226 while (*argptr !=
'\0') {
227 if (*argptr ==
'\\') {
246 else if (inquote && *argptr == quotechar) {
253 else if (*argptr ==
'\'' || *argptr ==
'"') {
259 else if (!inquote && *argptr ==
' ') {
260 *nargptr = *argptr =
'\0';
262 array_list_append(argv_list,vargptr);
283 array_list_append(argv_list,vargptr);
286 array_list_append(argv_list,NULL);
289 array_list_len(argv_list) - 1,
290 (
char **)argv_list->
list,
293 verror(
"could not parse overlay spec!\n");
294 array_list_free(argv_list);
298 array_list_free(argv_list);
302 return ARGP_ERR_UNKNOWN;
312 int main(
int argc,
char **argv) {
322 struct target *rtarget;
339 verror(
"could not parse target arguments!\n");
348 if (!gadgets || g_hash_table_size(gadgets) == 0) {
349 verror(
"No gadgets in file!\n");
355 verror(
"could not instantiate target!\n");
361 fprintf(stderr,
"could not open %s!\n",targetstr);
378 verror(
"could not find overlay thread '%s', exiting!\n",
386 verror(
"could not instantiate overlay target '%s'!\n",
394 fprintf(stderr,
"could not open overlay target!\n");
406 rop_violation_list = array_list_create(128);
407 probes = g_hash_table_new(g_direct_hash,g_direct_equal);
408 g_hash_table_iter_init(&iter,gadgets);
409 while (g_hash_table_iter_next(&iter,(gpointer)&key,(gpointer)&gadget)) {
412 fprintf(stderr,
"could not install probe on gadget at 0x%"PRIxADDR"\n",
417 g_hash_table_insert(
probes,(gpointer)probe,(gpointer)probe);
425 fprintf(stdout,
"Starting watch loop!\n");
433 printf(
"target interrupted at 0x%"PRIxREGVAL"; trying to resume!\n",
437 fprintf(stderr,
"could not resume target\n");
446 fprintf(stdout,
"target %s exiting, removing probes safely...\n",
452 verror(
"could not resume target!\n");
460 printf(
"target exited, cleaning up.\n");
469 printf(
"target interrupted at 0x%"PRIxREGVAL" -- bad status (%d)\n",
482 if (array_list_len(rop_violation_list)) {
484 fprintf(stdout,
"RESULT:: (f:%d) rop (1) Violations \"ROP violations detected.\" ::RESULT\n",
485 ++final_result_counter);
487 fprintf(stdout,
"ROP violations detected!\n");
489 fprintf(stdout,
"Gadgets used:\n");
491 for (i = 0; i < array_list_len(rop_violation_list); ++
i) {
492 char *rv = (
char *)array_list_item(rop_violation_list,i);
493 fprintf(stdout,
"%s",rv);
500 fprintf(stdout,
"RESULT:: (f:%d) rop (0) NoViolations \"No ROP violations detected.\" ::RESULT\n",
501 ++final_result_counter);
503 fprintf(stdout,
"No ROP violations detected!\n");
507 printf(
"%s finished.\n",targetstr);
511 printf(
"%s monitoring failed!\n",targetstr);
515 printf(
"%s monitoring failed with %d!\n",targetstr,tstat);
struct target * target_instantiate_overlay(struct target *target, tid_t tid, struct target_spec *spec)
GHashTable * rop_load_gadget_stream(FILE *stream)
struct rc_argp_state opts
tid_t target_lookup_overlay_thread_by_name(struct target *target, char *name)
struct argp_option rc_argp_opts[]
int probe_unregister(struct probe *probe, int force)
void * target_argp_driver_state(struct argp_state *state)
struct target_spec * overlay_spec
tid_t target_lookup_overlay_thread_by_id(struct target *target, int id)
struct target_spec * tspec
static uint64_t unsigned int i
void sigh_cleanup_probes(int signo, siginfo_t *siginfo, void *x)
int target_resume(struct target *target)
int target_pause(struct target *target)
struct probe * entry_probe
#define verror(format,...)
int target_install_default_sighandlers(void(*sighandler)(int signo, siginfo_t *siginfo, void *x))
char * overlay_name_or_id
int target_snprintf(struct target *target, char *buf, int bufsiz)
REGVAL target_read_reg(struct target *target, tid_t tid, REG reg)
ADDR probe_addr(struct probe *probe)
struct array_list * rop_violation_list
result_t rop_handler(struct probe *probe, tid_t tid, void *data, struct probe *trigger, struct probe *base)
void target_default_cleanup()
int main(int argc, char **argv)
int probe_free(struct probe *probe, int force)
error_t rc_argp_parse_opt(int key, char *arg, struct argp_state *state)
void * probe_priv(struct probe *probe)
void * probe_summarize(struct probe *probe)
GHashTable * rop_load_gadget_file(char *filename)
void * calloc(size_t nmemb, size_t size)
int target_open(struct target *target)
target_status_t target_monitor(struct target *target)
struct target_spec * target_argp_driver_parse_one(struct argp *driver_parser, void *driver_state, int argc, char **argv, target_type_t target_types, int filter_quoted)
struct target * target_instantiate(struct target_spec *spec, struct evloop *evloop)
struct probe * probe_rop_checkret(struct target *target, tid_t tid, struct rop_gadget *rg, probe_handler_t pre_handler, probe_handler_t post_handler, void *handler_data)
void * malloc(size_t size)
char * probe_name(struct probe *probe)
void target_driver_argp_init_children(struct argp_state *state)
struct rop_gadget * gadget