Madmouse

A program that generates encrypted executable code and a key

Jan 28th, 2015
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.92 KB | None | 0 0
  1.  
  2.  
  3. //
  4. // A program that generates encrypted executable code and a key for use in assembly
  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[] = "\xe8\x0c\x00\x00\x00\x68\x65\x6c\x6c\x6f\x20\x77\x6f\x72\x6c\x64\x0a\x5e\xb0\x5e\xb0\x01\x40\x88\xc7\xb2\x0c\x0f\x05\xb0\x3c\x48\x31\xff\x0f\x05";
  44.     char key[sizeof(evil)];
  45.    
  46.     int i;
  47.    
  48.     printf("\n\t; key data\n\tdb ");    // print out a comment and start description of our data
  49.     for(i=0;i<=sizeof(evil);i++)        // for the size of evil payload
  50.     {
  51.         seed_prng();            // get some randomness
  52.         key[i] = rand()%255;        // write a random byte to the key
  53.         printf("0x%02x",0xFF&(key[i])); // print it out
  54.         if(i!=sizeof(evil))printf(","); // maintain commas because DUH lol
  55.     }
  56.    
  57.     printf("\n\t; encrypted code:\n\tdb "); // same fluff as before
  58.     for(i=0;i<=sizeof(evil);i++)
  59.     {
  60.         printf("0x%02x",0xFF&(key[i]^evil[i])); // xor the curretn key byte with the current evil byte
  61.         if(i!=sizeof(evil))printf(","); // maintain fluff
  62.     }
  63.     printf("\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