Guest User

Untitled

a guest
Dec 23rd, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. /* binary log file example with simple XOR encryption
  2. * Thu May 5 00:30:19 PDT 2011 by epixoip
  3. */
  4.  
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <ctype.h>
  8. #include <stdlib.h>
  9.  
  10. #define PLAINS_LOG "creds.log"
  11.  
  12. char key[16]="y&^4d0xj_P^*b2Z8";
  13.  
  14. struct credentials
  15. {
  16. char user[255];
  17. char pass[255];
  18. };
  19.  
  20. char *xor(char *str)
  21. {
  22. int key_count = 0;
  23. char *temp, *ptr;
  24. int len, i;
  25.  
  26. temp=str;
  27. for(len=0; *temp !='\0';temp++, len++);
  28.  
  29. ptr=malloc(sizeof(char)*(len+1));
  30.  
  31. for (i=0; i < len; i++)
  32. {
  33. ptr[i] = str[i] ^ key[key_count];
  34.  
  35. key_count++;
  36. if (key_count == strlen(key))
  37. key_count = 0;
  38. }
  39.  
  40. ptr[len]='\0';
  41. return ptr;
  42. }
  43.  
  44. void credentials_write(char *user, char *pass)
  45. {
  46. FILE *file;
  47. if ((file = fopen(PLAINS_LOG, "ab")) == NULL)
  48. return;
  49.  
  50. struct credentials creds;
  51. snprintf(creds.user, sizeof(creds.user), "%s", xor(user));
  52. snprintf(creds.pass, sizeof(creds.pass), "%s", xor(pass));
  53.  
  54. fwrite(&creds, sizeof creds, 1, file);
  55. fclose(file);
  56. }
  57.  
  58. void credentials_readall()
  59. {
  60. FILE *file;
  61. if ((file = fopen(PLAINS_LOG, "rb")) == NULL)
  62. return;
  63.  
  64. struct credentials creds;
  65.  
  66. while (fread(&creds, sizeof(creds), 1, file) == 1)
  67. printf("%s:%s\n", xor(creds.user), xor(creds.pass));
  68.  
  69. fclose(file);
  70. }
  71.  
  72. int main()
  73. {
  74. char *username = "root";
  75. char *password = "rootme!";
  76.  
  77. credentials_write(username, password);
  78. credentials_readall();
  79.  
  80. return 0;
  81. }
Add Comment
Please, Sign In to add comment