LeonidR

CrackMe char

Dec 17th, 2013
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.00 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 "tmpPipeInputChars"
  11. #define PNAME1 "tmpPipeOutputChars"
  12.  
  13. int main(){
  14.     int fd1, fd2;
  15.  
  16.     int pin = 0;
  17.     char cod[10];
  18.     char risposta[100];
  19.  
  20.     //creo le pipe se non sono già presenti
  21.  
  22.     mkfifo(PNAME2, 0666);
  23.     mkfifo(PNAME1, 0666);
  24.  
  25.     //apro le pipe utilizzate
  26.     if( ((fd1 = open(PNAME1, O_RDONLY)) < 0) || ((fd2 = open(PNAME2, O_WRONLY)) < 0)){
  27.         perror("Errore appertura pipe");
  28.         exit(EXIT_FAILURE);
  29.     }
  30.  
  31.     while(pin <= 99999){
  32.  
  33.         sprintf(cod, "%d", pin);
  34.  
  35.         write (fd2,cod,strlen(cod)+1);
  36.  
  37.         int dim = 0;
  38.         while((dim < 100) && read(fd1, &risposta[dim], 1) && (risposta[dim] != 0))
  39.             dim ++; //accumulo il messaggio
  40.  
  41.         //printf("%d - %s", pin, risposta);
  42.  
  43.         if(strstr(risposta, "corretto")){
  44.             printf("Pin trovato %d\n", pin);
  45.             return 0;
  46.         }
  47.  
  48.         pin++;
  49.     }
  50.     close(fd1);
  51.     close(fd2);
  52.     return 0;
  53. }
Add Comment
Please, Sign In to add comment