Exetools  

Go Back   Exetools > General > Source Code

Notices

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #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)
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On


Similar Threads
Thread Thread Starter Forum Replies Last Post
IDA can't properly deal with RUST strings WhoCares General Discussion 3 07-08-2021 10:46
How to deal with threads ? bcl25 General Discussion 4 03-29-2003 06:22


All times are GMT +8. The time now is 15:22.


Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX, chessgod101
( 1998 - 2024 )