Guest User

Untitled

a guest
Oct 17th, 2016
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.50 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <time.h>
  4. #include <stdlib.h>
  5.  
  6. #include <signal.h>
  7. #include <stdio.h>
  8. #include <stdbool.h>
  9. #include <unistd.h>
  10.  
  11. volatile sig_atomic_t print_flag = false;
  12.  
  13. void handle_alarm( int sig ) {
  14.     printf("Time's up\n"); fflush(stdout);
  15.     exit(0);
  16. }
  17.  
  18. struct creds{
  19.     char* username;
  20.     char* password;
  21. };
  22. struct creds* creds1;
  23. struct creds* creds2;
  24. char kk[12] = {73,77,69,35,82,87,123,12,101,91};
  25. char kk2[12] = {25,18,4,4,4,2,18,20,20,6};
  26. char* hint;
  27. void takeInput(){
  28.     char user[100]; char pass[100];
  29.     printf("Username: "); fflush(stdout); fgets(user, 100, stdin); fflush(stdin);
  30.     printf("Password: "); fflush(stdout);  fgets(pass, 100, stdin); fflush(stdin);
  31.     strcpy(creds1->username, user);
  32.     strcpy(creds1->password, pass);
  33. }
  34. void takeInput2(){
  35.     char user[100]; char pass[100];
  36.     printf("Username: "); fflush(stdout);  fgets(user, 100, stdin); fflush(stdin);
  37.     printf("Password: "); fflush(stdout);  fgets(pass, 100, stdin); fflush(stdin);
  38.     strncpy(creds2->username, user, 100);
  39.     strncpy(creds2->password, pass, 100);
  40. }
  41. int checkUser(){
  42.     if(strcmp(creds1->username, "Palash\n")) return 0;
  43.     char a[12] = {4,52,21,66,33,36,12,99,23,63};
  44.     int c=0;
  45.     for(int i=0;i<10;i++){
  46.         c += creds1->password[i]^a[i]^kk[i];
  47.     }
  48.     return c==0;
  49. }
  50. int checkUser2(){
  51.     if(strcmp(creds2->username, "Palash2\n")) return 0;
  52.     int a=0,b=0,c=0,d=0,x=0;
  53.     char e[14] = {49, 56, 52, 48, 51, 57, 54, 53, 52, 56, 57, 50, 52};
  54.     for(int i=0;i<10;i++){
  55.         a += e[i]*53;
  56.         b += a %128 + creds2->password[i];
  57.         c = e[b%13];
  58.         d = ((c-48) * 23 + 32)%30;
  59.         x += d^kk2[i];
  60.     }
  61.     return x==0;
  62. }
  63. void secretFlag(){
  64.     strcpy(hint, "S3Mqty\n");
  65.     printf("Hint for next pwn: %s", hint); fflush(stdout);
  66.     system("/bin/cat flagBig.txt"); fflush(stdout);
  67. }
  68. int main(){
  69.  
  70.  
  71.     signal( SIGALRM, handle_alarm ); // Install handler first,
  72.     alarm( 2); // before scheduling it to be called.
  73.  
  74.     creds2 = malloc(24);
  75.     creds2->username = malloc(16);
  76.     creds2->password = malloc(16);
  77.     creds1 = malloc(24);
  78.     creds1->username = malloc(16);
  79.     creds1->password = malloc(16);
  80.     hint = malloc(48);
  81.     takeInput();
  82.     int c = checkUser();
  83.     if(!c){
  84.         printf("Lets try the other one\n"); fflush(stdout);
  85.         takeInput2();
  86.         c = checkUser2();
  87.     }
  88.     else {
  89.         printf("\n");
  90.         system("/bin/cat flagSmall.txt"); fflush(stdout);
  91.         return 0;
  92.     }
  93.     if(c){
  94.         printf("\n"); fflush(stdout);
  95.         system("/bin/cat flagMedium.txt"); fflush(stdout);
  96.     }else {
  97.         printf("Login failure\n"); fflush(stdout);
  98.     }
  99.     return 0;
  100. }
Add Comment
Please, Sign In to add comment