View Single Post
  #1  
Old 10-17-2015, 01:50
Insid3Code's Avatar
Insid3Code Insid3Code is offline
Family
 
Join Date: May 2013
Location: Algeria
Posts: 84
Rept. Given: 47
Rept. Rcvd 60 Times in 30 Posts
Thanks Given: 24
Thanks Rcvd at 108 Times in 56 Posts
Insid3Code Reputation: 60
[C/C++] Memory patcher to deal with (ASLR)

Memory patcher (loader) to deal with Address Space Layout Randomization (ASLR)

PHP Code:
#include <windows.h>
#include <stdio.h>

#ifdef _WIN64
#define CAPTION "atomos - memory patcher for chimera #01 (64-bit)"
#define EXENAME "target64.exe"
#else
#define CAPTION "atomos - memory patcher for chimera #01 (32-bit)"
#define EXENAME "target32.exe"
#endif

int iWinMain() {
    
PROCESS_INFORMATION lpProcessInfo = {0};
    
CONTEXT lpContext = {0};
    
STARTUPINFO lpStartupInfo = {0};

    
printf("%s\nFilename: %s\n\n"CAPTIONEXENAME);

    if(
CreateProcessA(EXENAME,
                      
NULL,
                      
NULL,
                      
NULL,
                      
0,
                      
CREATE_SUSPENDED,
                      
NULL,
                      
NULL,
                      &
lpStartupInfo,
                      &
lpProcessInfo))    {

        
lpContext.ContextFlags CONTEXT_FULL;
        
GetThreadContext(lpProcessInfo.hThread, &lpContext);

#ifdef _WIN64
        
ULONG_PTRpeb = (ULONG_PTR*)lpContext.Rdx;
#else
        
ULONG_PTRpeb = (ULONG_PTR*)lpContext.Ebx;
#endif
        
ULONG_PTR ImageBaseAddress NULL;

        
ReadProcessMemory(lpProcessInfo.hProcess,
                          &
peb[2],
                          (
LPVOID)&ImageBaseAddress,
                          
sizeof(ULONG_PTR),
                          
NULL);
                  
        
printf("[-] ImageBase Address     = 0x%p\n"ImageBaseAddress);

#ifdef _WIN64
        
printf("[-] EntryPoint Address    = 0x%p\n"lpContext.Rcx);
        
printf("[-] Process (PEB Address) = 0x%p\n"lpContext.Rdx);

#else
        
printf("[-] EntryPoint Address    = 0x%p\n"lpContext.Eax);
        
printf("[-] Process (PEB Address) = 0x%p\n"lpContext.Ebx);
#endif



#ifdef _WIN64
        
ULONG_PTR uTargetAddress lpContext.Rcx 0x7E;
        const 
char newByte 0x75;
#else
        
ULONG_PTR uTargetAddress lpContext.Eax 0x64;
        const 
char newByte 0x74;
#endif
        
WriteProcessMemory(lpProcessInfo.hProcess,
                           (
LPVOID)uTargetAddress,
                           &
newByte,
                           
1,
                           
NULL);

        
ResumeThread(lpProcessInfo.hThread);
        
WaitForSingleObject(lpProcessInfo.hThreadINFINITE);
    }

    return 
0;

Attached file contains (source and binary (32bit/64bit) for testing purposes)
Attached Files
File Type: rar loader.rar (6.9 KB, 29 views)
__________________
Computer Forensics
Reply With Quote
The Following 6 Users Say Thank You to Insid3Code For This Useful Post:
b30wulf (10-17-2015), CryptXor (10-17-2015), giv (10-21-2015), niculaita (10-20-2015), Sn!per X (11-27-2015), Storm Shadow (10-17-2015)