LeonidR

CrackMe int

Dec 17th, 2013
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.90 KB | None | 0 0
  1. #include <fcntl.h>
  2. #include <stdlib.h>
  3. #include <signal.h>
  4. #include <string.h>
  5. #include <stdio.h>
  6. #include <sys/types.h>
  7. #include <unistd.h>
  8. #include <sys/stat.h>
  9.  
  10. #define PNAME2 "tmpPipeInput"
  11. #define PNAME1 "tmpPipeOutput"
  12.  
  13. int main(){
  14.     int fd1, fd2;
  15.  
  16.     int pin = 0;
  17.     char risposta[100];
  18.  
  19.     //creo le pipe se non sono già presenti
  20.  
  21.     mkfifo(PNAME2, 0666);
  22.     mkfifo(PNAME1, 0666);
  23.  
  24.     //apro le pipe utilizzate
  25.     if( ((fd1 = open(PNAME1, O_RDONLY)) < 0) || ((fd2 = open(PNAME2, O_WRONLY)) < 0)){
  26.         perror("Errore appertura pipe");
  27.         exit(EXIT_FAILURE);
  28.     }
  29.  
  30.     while(pin <= 99999){
  31.  
  32.         write (fd2,&pin,sizeof(int));
  33.  
  34.         int dim = 0;
  35.         while((dim < 100) && read(fd1, &risposta[dim], 1) && risposta[dim++]); //accumulo il messaggio
  36.  
  37.         //printf("%d - %s", pin, risposta);
  38.  
  39.         if(strstr(risposta, "corretto")){
  40.             printf("Pin trovato %d\n", pin);
  41.             return 0;
  42.         }
  43.  
  44.         pin++;
  45.     }
  46.  
  47.     return 0;
  48. }
Add Comment
Please, Sign In to add comment