/* ** RopGadget - Dev v3.3 ** Jonathan Salwan - http://twitter.com/JonathanSalwan ** http://shell-storm.org ** 2011-10-16 ** ** Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions ** are met: ** 1. Redistributions of source code must retain the above copyright ** notice, this list of conditions and the following disclaimer. ** 2. Redistributions in binary form must reproduce the above copyright ** notice, this list of conditions and the following disclaimer in the ** documentation and/or other materials provided with the distribution. */ #include "ropgadget.h" /* free linked list */ static void free_add_element(t_makecode *element) { t_makecode *tmp; while (element) { tmp = element; element = tmp->next; free(tmp); } } /* returns addr of instruction */ static Elf32_Addr ret_addr_makecodefunc(t_makecode *list_ins, char *instruction) { char *p; while (list_ins) { p = list_ins->instruction; while (*p != 0) { if (!match(p, instruction, strlen(instruction))) return (list_ins->addr); p++; } list_ins = list_ins->next; } return (0); } /* returns the numbers of pop in the gadget. */ static int how_many_pop(char *gadget) { int cpt = 0; char *p; p = gadget; while(*p != '\0') { if (!strncmp(p, "pop", 3)) cpt++; p++; } return (cpt); } /* returns the numbers of "pop" befor pop_reg */ static int how_many_pop_before(char *gadget, char *pop_reg) { int cpt = 0; while (strncmp(gadget, pop_reg, strlen(pop_reg)) && *gadget != '\0') { if (!strncmp(gadget, "pop", 3)) cpt++; gadget++; } return (cpt); } /* returns the numbers of "pop" after pop_reg */ static int how_many_pop_after(char *gadget, char *pop_reg) { int cpt = 0; while(strncmp(gadget, pop_reg, strlen(pop_reg))) { if (*gadget == '\0') return (0); gadget++; } gadget += strlen(pop_reg); while (*gadget != '\0') { if (!strncmp(gadget, "pop", 3)) cpt++; gadget++; } return (cpt); } /* display padding */ static void display_padding(int i) { while (i != 0) { fprintf(stdout, "\t\t%sp += pack(\"next != NULL) importsc_mode.poctet = importsc_mode.poctet->next; while (i != importsc_mode.size && importsc_mode.poctet != NULL) { /* pop %edx */ fprintf(stdout, "\t\t%sp += pack(\"addr, importsc_mode.poctet->octet, ENDC); display_padding(how_many_pop_after(gad1, pop_reg)); /* mov (%edx),%ecx */ fprintf(stdout, "\t\t%sp += pack(\"back; i++; } fprintf(stdout, "\t\t%sp += pack(\"