Advertisement
Guest User

Untitled

a guest
May 30th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.42 KB | None | 0 0
  1. int decodeUserPass(char *authorization) {
  2.  
  3.     // Ausgabe der Logindaten
  4.     if (authorization != NULL) {
  5.  
  6.         char *auth64 = authorization;
  7.         char *authDecode = (char *) calloc(sizeof(char), BUFFERSMALL);
  8.         char *clear_user = (char *) calloc(sizeof(char), BUFFERSMALL);
  9.         char *clear_password = (char *) calloc(sizeof(char), BUFFERSMALL);
  10.         char *sha1_password_base64 = (char *) calloc(sizeof(char), BUFFERSMALL);
  11.         char *sha1_password = (char *) calloc(sizeof(char), BUFFERSMALL);
  12.         int i = 0;
  13.  
  14.         // Ausgabe base64 codierter auth-string
  15.         //printf("%s\n",auth64);
  16.  
  17.         // Ausgabe dekodierter auth-string
  18.         Base64decode(authDecode, auth64);
  19.         //printf("%s\n",authDecode);
  20.  
  21.         // Suche Stelle des Doppelpunkts
  22.         while (strncmp(authDecode + i, ":", 1) != 0) {
  23.             i++;
  24.         }
  25.  
  26.         // Benutzernamen ausgeben
  27.         strncpy(clear_user, authDecode, (size_t) i);
  28.         printf("Benutzer: %s\n", clear_user);
  29.  
  30.         // Passwort ausgeben
  31.         strcpy(clear_password, authDecode + i + 1);
  32.         printf("Passwort: %s\n\n", clear_password);
  33.  
  34.         // SHA1 von password ausgeben
  35.         makeSha1(clear_password, sha1_password);
  36.         printf("SHA1: %s\n", sha1_password);
  37.  
  38.         // Base64 SH1 von password ausgeben
  39.         Base64encode(sha1_password_base64, sha1_password, (int) strlen(sha1_password));
  40.         printf("SHA1_Base64: %s\n\n", sha1_password_base64);
  41.  
  42.         int status = checkUserPass(clear_user, sha1_password_base64);
  43.  
  44.         free(clear_password);
  45.         free(clear_user);
  46.         free(sha1_password_base64);
  47.         free(sha1_password);
  48.         free(authDecode);
  49.  
  50.         return status;
  51.     }
  52.     return 0;
  53. }
  54.  
  55. int checkUserPass(char *user, char *base64) {
  56.     char *pathbuffer = (char *) calloc(sizeof(char), BUFFERSMALL);
  57.     strcpy(pathbuffer, getRoot());
  58.     strcat(pathbuffer, (const char *) "/htpasswd");
  59.  
  60.     char *file;
  61.     file = loadFile(pathbuffer);
  62.     free(pathbuffer);
  63.     if (file == NULL){
  64.         return 0;
  65.     }
  66.     char *userpass = (char *) calloc(sizeof(char), BUFFERSMALL);
  67.     strPaste(userpass, user, BUFFERSMALL);
  68.     strPaste(userpass, ":{SHA}", BUFFERSMALL);
  69.     strPaste(userpass, base64, BUFFERSMALL);
  70.  
  71.     if (strstr(file, userpass)) {
  72.         free(userpass);
  73.         free(file);
  74.         return 1;
  75.     }
  76.     free(userpass);
  77.     free(file);
  78.     return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement