diff --git a/.gitignore b/.gitignore index 295f9e6..03fdb9b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ serveur client attaque +lib/test \ No newline at end of file diff --git a/lib/Makefile b/lib/Makefile new file mode 100644 index 0000000..000d6f2 --- /dev/null +++ b/lib/Makefile @@ -0,0 +1,2 @@ +test: test_chiffrement.c rondoudouPatch.c rondoudouPatch.h + gcc -Wall -g test_chiffrement.c rondoudouPatch.c -o test \ No newline at end of file diff --git a/lib/rondoudouPatch.c b/lib/rondoudouPatch.c new file mode 100644 index 0000000..d1ebb4d --- /dev/null +++ b/lib/rondoudouPatch.c @@ -0,0 +1,107 @@ +#include +#include +#include +#include "rondoudouPatch.h" + +//WARNING SUR TOUT LES TYPES !!! + +struct t_pile_addrs { + int index; + void ** tab[TAB_SIZE]; + struct t_pile_addrs * next; +}; + +uintptr_t rondoudou_patch_key; + +struct t_pile_addrs * pile_addrs; + +void rondoudou_patch_init(void) { + pile_addrs = (struct t_pile_addrs *)malloc(sizeof(struct t_pile_addrs)); + pile_addrs->index = -1; + pile_addrs->next = NULL; + + rondoudou_patch_key = 12345; +} + +int print_pile_aux(int profondeur, struct t_pile_addrs * pile) { + if (pile != NULL) { + int prof_max = print_pile_aux(profondeur + 1, pile->next); + int i; + int max; + if (pile->index != TAB_SIZE) { + max = pile->index + 1; + } else { + max = TAB_SIZE; + } + for (i = 0; i %p\n", (prof_max - profondeur)*TAB_SIZE + i, pile->tab[i]); + } + return prof_max; + } else { + return profondeur - 1; + } +} + +void print_pile(void) { + print_pile_aux(0, pile_addrs); +} + +/* + * + * ATTENTION !!!!! FONCTION ULTRA CHELOUE + * + */ +void ** find_address_in_stack(void * addr) { + void ** ret = 0; + int trouve = 0; + int i; + for (i=0; i<1000; i++) { + if ((*(&ret + i)) == addr) { + if (trouve) { + ret = (void **)(&ret + i); + break; + } + trouve = 1; + } + } + + return ret; +} + +void cipher(void * address) { + void ** addr = find_address_in_stack(address); + if (addr != 0) { + *addr = (void *)((uintptr_t)*addr ^ (uintptr_t)rondoudou_patch_key); + if ((pile_addrs->index) == (TAB_SIZE - 1)) { + struct t_pile_addrs * aux = (struct t_pile_addrs *)malloc(sizeof(struct t_pile_addrs)); + aux->index = 0; + aux->next = pile_addrs; + pile_addrs = aux; + } else { + pile_addrs->index++; + } + pile_addrs->tab[pile_addrs->index] = addr; + printf("APPEL A CIPHER\n"); + print_pile(); + } +} + +void decipher(void) { + if (pile_addrs->index == -1) { + if (pile_addrs->next == NULL) { + printf("Ouille ouille ouille qu'est ce que j'ai mal aux nouilles ! \n"); + exit(2); + } else { + struct t_pile_addrs * aux = pile_addrs; + pile_addrs = pile_addrs->next; + free(aux); + } + } + + *((pile_addrs->tab)[pile_addrs->index]) = (void *)((uintptr_t)(*((pile_addrs->tab)[pile_addrs->index])) ^ (uintptr_t)rondoudou_patch_key); + pile_addrs->index--; + printf("APPEL A DECIPHER\n"); + print_pile(); +} + +void changekey(void); diff --git a/lib/rondoudouPatch.h b/lib/rondoudouPatch.h new file mode 100644 index 0000000..f9abbde --- /dev/null +++ b/lib/rondoudouPatch.h @@ -0,0 +1,7 @@ +#define TAB_SIZE 3 + +void cipher(void * addr); +void decipher(void); +void changekey(void); +void rondoudou_patch_init(void); + diff --git a/lib/test_chiffrement.c b/lib/test_chiffrement.c new file mode 100644 index 0000000..f6c49bf --- /dev/null +++ b/lib/test_chiffrement.c @@ -0,0 +1,36 @@ +#include "rondoudouPatch.h" +#include + +void f() { + cipher(__builtin_return_address(0)); + printf("Dans f()\n"); + decipher(); +} + +void g() { + cipher(__builtin_return_address(0)); + printf("Dans g()\n"); + f(); + decipher(); +} + +void h() { + cipher(__builtin_return_address(0)); + printf("Dans h()\n"); + g(); + decipher(); +} + +void i() { + cipher(__builtin_return_address(0)); + printf("Dans i()\n"); + h(); + decipher(); +} + +int main() { + rondoudou_patch_init(); + cipher(__builtin_return_address(0)); + i(); + decipher(); +}