Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // A program that generates encrypted executable code and a key for use in C
- // Written by: MadMouse
- #include <stdio.h>
- #include <string.h>
- #include <unistd.h>
- #include <time.h>
- // a generic mix algorithm for seeding the random number generator
- long unsigned int mix(long unsigned int a, long unsigned int b, long unsigned int c)
- {
- a=a-b; a=a-c; a=a^(c >> 13);
- b=b-c; b=b-a; b=b^(a << 8);
- c=c-a; c=c-b; c=c^(b >> 13);
- a=a-b; a=a-c; a=a^(c >> 12);
- b=b-c; b=b-a; b=b^(a << 16);
- c=c-a; c=c-b; c=c^(b >> 5);
- a=a-b; a=a-c; a=a^(c >> 3);
- b=b-c; b=b-a; b=b^(a << 10);
- c=c-a; c=c-b; c=c^(b >> 15);
- return c;
- }
- // a semi reasonable seeding function
- void seed_prng(void)
- {
- unsigned int urandom;
- FILE* urandomF = fopen("/dev/urandom", "r");
- fread(&urandom, sizeof(int), 1, urandomF);
- fclose(urandomF);
- long unsigned int seed = mix(clock(), urandom, getpid());
- srand(seed);
- return;
- }
- int main(void)
- {
- const char evil[] = "INSERT CODE HERE";
- int i;
- char key[sizeof(evil)];
- printf("\n// key data\nBYTE key[] = \""); // print out a comment and start description of our data
- for(i=0;i<sizeof(evil);i++) // for the size of evil payload
- {
- seed_prng(); // get some randomness
- key[i] = rand()%255; // write a random byte to the key
- printf("\\x%02x",0xFF&(key[i])); // print it out
- }
- printf("\";\n// encrypted code\nBYTE evil[] = \""); // same fluff as before
- for(i=0;i<sizeof(evil);i++)
- {
- printf("\\x%02x",0xFF&(key[i]^evil[i])); // xor the curretn key byte with the current evil byte
- }
- printf("\";\n\nsize: %i\n\n",i); // print out the size so that we can set up offsets later
- return 0; // WOOOT, all done ;)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement