Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > C/C++
You last visited: Today at 20:50

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



How does manual mapping work + example

Discussion on How does manual mapping work + example within the C/C++ forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Sep 2016
Posts: 25
Received Thanks: 25
Smile How does manual mapping work + example

Even though the concept of manually mapping a file into memory is nothing new, I see (too) many people not understanding it:
  • Their injectors are 95% copy-pasted from blackbone/xenos
  • Hardly anyone who did not bother with those annoying anti-cheats like XTrap, XignCode, doesn't even know that manual mapping exists or why to use it

Also, while lurking the S4 League section, I notice ppl don't have a clue about this topic either.

(which maybe has emerged because of the perpetual existence of a public full-bypass
and because of the incompetence of the developers forgetting to implement the serverside alive-check lolz)


Concept

What manual mapping really is, is just emulating the behavior of LoadLibraryA/W and/or the windows pe loader.
As you may know, LoadLibrary is just a "wrapper", exposing many internal loader APIs.
This means anti-cheats can hook LoadLibrary itself or one of the elementary functions called inside of it and, thus,
find out that something's gonna get injected and what is gonna get injected and take appropriate action.

Now, to know what to emulate, you need to know what LoadLibrary is really doing.
After a quick look at MSDN, you may notice that it says "The specified module may cause other modules to be loaded".
This recursive approach needs to be taken into account later, e.g. if your DLL needs other dependencies to work in the target process.

So, it roughly explains that LoadLibrary "loads" the module, specified by an absolute or relative path, into the calling process.
What loading practically means:
  1. Use the path to open a handle to the library file (DLL)
  2. Using the handle, read the contents of the file into the injector's process' address space
  3. Optionally check if the image is really a DLL file by considering the characteristics field in the PE header
  4. Allocate space for the image and the shellcode which will call the entrypoint and resolve some stuff (in-depth later)
  5. Copy the whole image into the allocated space
  6. Copy the shellcode into the other code-cave and execute it

Since some of the loader's internal APIs were not called, another advantage is that the image is not registered in the PEB's module lists.
The reason that you need to additionally use shellcode is that you could theoretically just create a remote thread with
the start address of your dll entry point but you may only supply one argument.

The shellcode takes care of resolving the imports or more precisely the import address table entries. Your image uses a particular table
in memory which contains pointers to APIs like from NTDLL or KERNEL. There is no guarantee that those are loaded at the same place everytime.
As well, those entries are RVAs instead of VAs in case your image is not loaded at default imagebase.
That's why you will have to manually rebuild the IAT which is pretty easy:
  1. Easy way: Load dependency with LoadLibraryA (hopefully anti-cheat doesn't detect LoadLibrary when loading windows dlls)
    and then parse its export table with GetProcAddress. (hopefully ac doesn't detect GetProcAddress :P)
  2. Not soo easy way: This is a little bit costlier but still easy. Recursively call your mapping code again, applying the conquer and divide principle, for every dependency + emulate GetProcAddress (it's just parsing the dependency's export table)

Moreover you will have to resolve the relocation table. Relocations are just locations in code that use absolute virtual addresses.
In this case you need to add the difference between the assumed imagebase and the real imagebase to each entry.
This difference is always relative to the assumed imagebase, hence it can also be negative, causing a subtraction.
(That is because the relocations are also relative to the assumed imagebase and not to the real imagebase)

At the end of the shellcode it will call the entry point of the valid, mapped module.


Code examples (snippets)

Open & read file on disk


Check if valid DLL image

Copy file contents to image

Fix relocations
vaynz is offline  
Thanks
7 Users
Old 11/03/2016, 20:00   #2
dotCom
 
Devsome's Avatar
 
elite*gold: 12400
The Black Market: 104/0/0
Join Date: Mar 2009
Posts: 15,881
Received Thanks: 4,386
@ you can send him a private message instead of asking in the thread. @ Good tutorial
Devsome is offline  
Thanks
1 User
Old 11/06/2016, 04:31   #3
 
Master674b's Avatar
 
elite*gold: 0
Join Date: Dec 2012
Posts: 255
Received Thanks: 110
You forgot that there is a lot more stuff to consider if you want to do this right. You need to apply the proper protection flags to each region, the PEB has to be locked if you want to link in the new module, then there is delayed imports, tls callbacks, SEH, security cookie, the list goes on...

Stick to a proper implementation instead of making your own.

You forgot that there is a lot more stuff to consider if you want to do this right. You need to apply the proper protection flags to each region, the PEB has to be locked if you want to link in the new module, then there is delayed imports, tls callbacks, SEH, security cookie, the list goes on...

Stick to a proper implementation instead of making your own.
Master674b is offline  
Old 11/15/2016, 11:11   #4
 
CSGOCheats's Avatar
 
elite*gold: 0
Join Date: Oct 2016
Posts: 35
Received Thanks: 1
Great post! Simple to the point and nothing extra. Although some Anti-Cheats do detect load library.

Edit: My bad kinda skimmed it didn't realize you warned about that already :P
CSGOCheats is offline  
Reply


Similar Threads Similar Threads
manual mapping possible with autoit?
06/13/2016 - AutoIt - 0 Replies
hey guys, i wonder if manual mapping is possible with autoit ? i only found ways to inject a dll with loadlibaryA would be great if you guys can help me out ;)
[Buying] Kernel Mode Manual Mapping Injector
02/25/2015 - DayZ Trading - 14 Replies
hey guys iam looking to buy a kernel mode manual mapping injector undetected add me on skype tekniq_swagg1 willing to pay good money :) also if my skype name dont work just drop yours
[Mapping Umfrage] Eure Mapping vorschlage hier rein.
06/13/2011 - Flyff Private Server - 5 Replies
Hallo Leute. Nachdem ich die PvP Erfolgreich erledigt habe will ich mich zu einen neuen Projekt des Mappings zu wenden. Gibt mir euere Vorschläge : - Soll ich eine neue welt erstellen bzw Mappen ( was für eine Map solls sein + beschreibung ein bisschen ) - Soll ich eine Offi Map wie Flaris verändern ? ( Beispiele + beschreibung ) Eure vorschläge könnt ihr jetzt hier rein schreiben.



All times are GMT +2. The time now is 20:50.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.