Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* binary log file example with simple XOR encryption
- * Thu May 5 00:30:19 PDT 2011 by epixoip
- */
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
- #include <stdlib.h>
- #define PLAINS_LOG "creds.log"
- char key[16]="y&^4d0xj_P^*b2Z8";
- struct credentials
- {
- char user[255];
- char pass[255];
- };
- char *xor(char *str)
- {
- int key_count = 0;
- char *temp, *ptr;
- int len, i;
- temp=str;
- for(len=0; *temp !='\0';temp++, len++);
- ptr=malloc(sizeof(char)*(len+1));
- for (i=0; i < len; i++)
- {
- ptr[i] = str[i] ^ key[key_count];
- key_count++;
- if (key_count == strlen(key))
- key_count = 0;
- }
- ptr[len]='\0';
- return ptr;
- }
- void credentials_write(char *user, char *pass)
- {
- FILE *file;
- if ((file = fopen(PLAINS_LOG, "ab")) == NULL)
- return;
- struct credentials creds;
- snprintf(creds.user, sizeof(creds.user), "%s", xor(user));
- snprintf(creds.pass, sizeof(creds.pass), "%s", xor(pass));
- fwrite(&creds, sizeof creds, 1, file);
- fclose(file);
- }
- void credentials_readall()
- {
- FILE *file;
- if ((file = fopen(PLAINS_LOG, "rb")) == NULL)
- return;
- struct credentials creds;
- while (fread(&creds, sizeof(creds), 1, file) == 1)
- printf("%s:%s\n", xor(creds.user), xor(creds.pass));
- fclose(file);
- }
- int main()
- {
- char *username = "root";
- char *password = "rootme!";
- credentials_write(username, password);
- credentials_readall();
- return 0;
- }
Add Comment
Please, Sign In to add comment