Advertisement
Madmouse

encrypted code generator example

Jul 23rd, 2015
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.70 KB | None | 0 0
  1.  
  2.  
  3. //
  4. // A program that generates encrypted executable code and a key for use in C
  5. //  Written by: MadMouse
  6.  
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <unistd.h>
  10. #include <time.h>
  11.  
  12.  
  13. // a generic mix algorithm for seeding the random number generator
  14. long unsigned int mix(long unsigned int a, long unsigned int b, long unsigned int c)
  15. {
  16.     a=a-b;  a=a-c;  a=a^(c >> 13);
  17.     b=b-c;  b=b-a;  b=b^(a << 8);
  18.     c=c-a;  c=c-b;  c=c^(b >> 13);
  19.     a=a-b;  a=a-c;  a=a^(c >> 12);
  20.     b=b-c;  b=b-a;  b=b^(a << 16);
  21.     c=c-a;  c=c-b;  c=c^(b >> 5);
  22.     a=a-b;  a=a-c;  a=a^(c >> 3);
  23.     b=b-c;  b=b-a;  b=b^(a << 10);
  24.     c=c-a;  c=c-b;  c=c^(b >> 15);
  25.     return c;
  26. }
  27.  
  28. // a semi reasonable seeding function
  29. void seed_prng(void)
  30. {
  31.     unsigned int urandom;
  32.     FILE* urandomF = fopen("/dev/urandom", "r");
  33.     fread(&urandom, sizeof(int), 1, urandomF);
  34.     fclose(urandomF);
  35.     long unsigned int seed = mix(clock(), urandom, getpid());
  36.  
  37.     srand(seed);
  38.     return;
  39. }
  40.  
  41. int main(void)
  42. {
  43. const char evil[] = "INSERT CODE HERE";
  44.  
  45.  
  46.     int i;
  47.  
  48.     char key[sizeof(evil)];
  49.    
  50.     printf("\n// key data\nBYTE key[] = \"");   // print out a comment and start description of our data
  51.     for(i=0;i<sizeof(evil);i++)     // for the size of evil payload
  52.     {
  53.         seed_prng();            // get some randomness
  54.         key[i] = rand()%255;        // write a random byte to the key
  55.         printf("\\x%02x",0xFF&(key[i]));    // print it out
  56.     }
  57.    
  58.     printf("\";\n// encrypted code\nBYTE evil[] = \""); // same fluff as before
  59.     for(i=0;i<sizeof(evil);i++)
  60.     {
  61.         printf("\\x%02x",0xFF&(key[i]^evil[i])); // xor the curretn key byte with the current evil byte
  62.     }
  63.     printf("\";\n\nsize: %i\n\n",i);    // print out the size so that we can set up offsets later
  64.    
  65.     return 0;   // WOOOT, all done ;)
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement