Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

MenaRunPE, Injects all type of .NET exe's (x86 -> x64, x64 -> x86 and so on)

My injector, which support all type of .NET Injections:
http://www19.zippyshare.com/v/54392072/file.html
It only works with .NET exe's, as I don't set the thread context, this is the .NET section anyways so fck Native exe's :D

I'm not gonna give out the source, but I want to explain myself in thise thread how you can do it yourself.
I will referer to this source-code from AeonHack: https://hackforums.net/showthread.php?tid=4420101
As it can easy be modified to support more than just x86 -> x86 injections and is very easy to follow, but leave in mind his offsets is in decimal and not hex, mostly PE Header analyzing tools shows offsets in Hex.

Remember to read this: http://msdn.microsoft.com/en-us/gg463119.aspx
If you are interrested in a more detailed description of how the PE Header actually is constructed.

So lets start, what is the difference in a 64bit and 32bit PE when we want to do a RunPE Injection?

1: First is the CONTEXT structure we use to get the Thread's Context to receive the PEBAddress is different, there is (CONTEXT and CONTEXT_AMD64, both structures can be found in the winnt header file, the CONTEXT_AMD64 is quite hard to convert though.
And we use GetThreadContext when injector is 32bit and target is 32bit or injector is 64bit and target is 64bit, and we then use Wow64GetThreadContext when injector is 64bit and target is 32bit.
As I've seen some talkning nonsense about using Wow64GetThreadContext when 64bit -> 64bit because they don't know what Wow64 is all about, I thought it was worth mentioning the right API usage here.

2: When we get the PEB Address to find BaseAddress of our Target process.
PHP Code

<?php 
If Not ReadProcessMemory(PI.ProcessHandle, Ebx + 8, BaseAddress, 4, ReadWrite) Then Throw New Exception() 
On a 32bit process the pointer address to BaseAddress will be: Ebx + 8
(Ebx is PEBAddress)
on a 64bit process the offset to BaseAddress is 10 and not 8. Keep that in mind when you later on has to overwrite the old BaseAddress of the PE and when you read with rpm as shown above code.

3: The PEBAddress on 64bit is of course 64bit sized (Int64), there for make sure to correct RPM and WPM API's to not look like this in AeonHacks source:
PHP Code

<?php 
<DllImport("kernel32.dll", EntryPoint:="ReadProcessMemory"), SuppressUnmanagedCodeSecurity> _
    
Private Shared Function ReadProcessMemory( _
    ByVal process 
As IntPtr, _
    ByVal baseAddress 
As Integer, _
    ByRef buffer 
As Integer, _
    ByVal bufferSize 
As Integer, _
    ByRef bytesRead 
As Integer) As Boolean
    End 
Function

    <
DllImport("kernel32.dll", EntryPoint:="WriteProcessMemory"), SuppressUnmanagedCodeSecurity> _
    
Private Shared Function WriteProcessMemory( _
    ByVal process 
As IntPtr, _
    ByVal baseAddress 
As Integer, _
    ByVal buffer 
As Byte(), _
    ByVal bufferSize 
As Integer, _
    ByRef bytesWritten 
As Integer) As Boolean
    End 
Function 
As you clearly see these API's is wrong when checking:
http://msdn.microsoft.com/en-us/library/...s.85).aspx
http://msdn.microsoft.com/en-us/library/...s.85).aspx

LPVOID =IntPtr
LPCVOID = IntPtr
SIZE_T = Uinteger

4: The ImageBase value in the PE Header is stored 4 bytes ahead from the 32bit offset when the file is 64bit, which means the 64bit offset is 34 and not 30, starting of the PE Header's BaseAddress

5: We actually don't have do so much else now, but here's some good tips:
Use IsWow64Process function when determining if the target is a 32bit process.
When you want to inject a payload of 32bit into a 64bit process, you'll have to rewrite the flags offset in the .NET header to 1 instead of 3, which lets the 32bit payload go into 64bit, by removing the "32bit required" flag.

Example:
PHP Code

<?php 
If PayloadIs64 = False Then
      
If dwNetDirFlags = &H3 Then 'To make sure we dont rewrite flags on a Payload which is already AnyCPU Compiled, it will only slow us down'
      
Buffer.SetByte(payload, dwPEHeaderAddress + &H398, &H1) 'Replaces the .NET Header Flag on a 32bit compiled payload, to make it possible doing 32bit -> 64bit injection, without modifying the physcial target exe on the drive.'
      
End If
End If 

Read the wMachine value in the PE Header to know wether the Payload is 64bit or not.

I heared many saying: Injecting 64bit to 32bit is impossible, well yes. But not in .NET because the code first is compiled into wether 32bit or 64bit with the JIT Compiler on runtime, so we can manipulate it into 32bit or 64bit like we want before the exe is executed, so awesome when injecting malware or using injections for legit purposes.

This tutorial is not quite detailed, but anyone who knows what a pointer is and the different datatypes and have read the PE Header documentation should be able to follow up.
I just don't want to let c&p'ers come here and steal shit :)
0_0 nice tut man can't wait to look into this!
Very nice, detailed explanation, learn a lot from this (y)
Boop.. beep.. beep...
(Sep 6, 2014 01:44 AM)TR.Gen Wrote:  Very nice, detailed explanation, learn a lot from this (y)
Thank you, even I think many is in the boat of: WHAT THE HELL IS HE TALKING ABOUT :P
(Sep 5, 2014 06:22 AM)Menalix Wrote:  It only works with .NET exe's, as I don't set the thread context, this is the .NET section anyways so fck Native exe's :D
If it only works for .net why even bother using API's if you could just use the .Net Framework to handle the stuff :P
Shouldn't be so different from loading plugins
Assembly.Load anyone ? 🤣
(Sep 6, 2014 10:02 AM)DragonHunter Wrote:  If it only works for .net why even bother using API's if you could just use the .Net Framework to handle the stuff :P
Shouldn't be so different from loading plugins
Assembly.Load anyone ? 🤣

You are right, but loading in another appdomain would be better ;)
[Image: jfhDhRz.gif]
(Sep 6, 2014 10:03 AM)frontenhack Wrote:  You are right, but loading in another appdomain would be better ;)

yes so u can just unload it when u finish
😁 menalix i knew somthing like this will come
Convert to pdf the microsoft pe docx https://mega.co.nz/#fm/HoFWgZDA
Since when can you inject x86 code into a x64 environment?
(Sep 6, 2014 10:02 AM)DragonHunter Wrote:  If it only works for .net why even bother using API's if you could just use the .Net Framework to handle the stuff :P
Shouldn't be so different from loading plugins
Assembly.Load anyone ? 🤣
Well because it was only to make an example on how this works, and if someone tryed to reverse it, it would be kinda useless to their crypter.
My example uses NtGetProcessInformation instead of GetThreadContext, as I don't want to share CONTEXT_AMD64 it's a really baddy converting.
And that the cool about a RunPE is injecting other exe's and not loading into your own app domain.


(Sep 6, 2014 02:49 PM)intrinsic Wrote:  Since when can you inject x86 code into a x64 environment?
Has always been possible in .NET
Because .NET files is compiled at runtime, so the code is first run into 64bit or 32bit at runtime, and it's pretty obvious seen with the AnyCPU compile option.
Did you think .NET could be compiled into both on the same time? And why does no native languages have that option.
(Sep 7, 2014 03:35 AM)Menalix Wrote:  Well because it was only to make an example on how this works, and if someone tryed to reverse it, it would be kinda useless to their crypter.
My example uses NtGetProcessInformation instead of GetThreadContext, as I don't want to share CONTEXT_AMD64 it's a really baddy converting.
And that the cool about a RunPE is injecting other exe's and not loading into your own app domain.


Has always been possible in .NET
Because .NET files is compiled at runtime, so the code is first run into 64bit or 32bit at runtime, and it's pretty obvious seen with the AnyCPU compile option.
Did you think .NET could be compiled into both on the same time? And why does no native languages have that option.

It's not possible with both assemblies being compiled as x64 and x86.

.NET assemblies that are compiled with constant architectures have constant registers and datatypes.

Good try though, really.
If this is only for .NET why not just use Assembly.Load?

Also there is no such thing as "NtGetProcessInformation"
NtQueryInformationProcess is what you're looking for. All you're doing is changing the imagebase.
https://hackforums.net/showthread.php?tid=4424517
I'm stupid enough to understand this tut, it allows inject or read teh source code inside?
(Sep 7, 2014 11:46 AM)intrinsic Wrote:  It's not possible with both assemblies being compiled as x64 and x86.

.NET assemblies that are compiled with constant architectures have constant registers and datatypes.

Good try though, really.
If this is only for .NET why not just use Assembly.Load?

Also there is no such thing as "NtGetProcessInformation"
NtQueryInformationProcess is what you're looking for. All you're doing is changing the imagebase.
https://hackforums.net/showthread.php?tid=4424517

Try my Injector yourself, and you'll be prooven wrong, there's a reason I uploaded it.
If you're to lazy look on my old video: https://www.youtube.com/watch?v=k2pLF56gXXw

Cause Assembly.Load only works for the calling application.

Yea I misspelled the API, good find (y)
Nope that's not the only thing I do, pretty much AeonHacks RunPE states everything I do and any other public RunPE.
Anyone that suggested to use Assembly.Load instead, hasn't taken obfuscated applications into account.
https://github.com/Washi1337

"I'll tell you this UDP joke, and I don't care if you will get it or not."
(Sep 7, 2014 11:59 AM)Menalix Wrote:  Try my Injector yourself, and you'll be prooven wrong, there's a reason I uploaded it.
If you're to lazy look on my old video: https://www.youtube.com/watch?v=k2pLF56gXXw

Cause Assembly.Load only works for the calling application.

Yea I misspelled the API, good find (y)
Nope that's not the only thing I do, pretty much AeonHacks RunPE states everything I do and any other public RunPE.

First of all, do you know what a codecave is?
Secondly, you don't even know the name of the API you're using. It's not a 'misspell'.

You can't inject x86->x64 without performing heavens gate.


(Sep 7, 2014 12:32 PM)Washi Wrote:  Anyone that suggested to use Assembly.Load instead, hasn't taken obfuscated applications into account.

Yeah because people are going to encrypt their already obfuscated file.
A packed executable should work just fine as long as there is nothing being dropped or relocated.
(Sep 7, 2014 12:57 PM)intrinsic Wrote:  First of all, do you know what a codecave is?
Secondly, you don't even know the name of the API you're using. It's not a 'misspell'.

You can't inject x86->x64 without performing heavens gate.



Yeah because people are going to encrypt their already obfuscated file.
A packed executable should work just fine as long as there is nothing being dropped or relocated.

Yes i know what code cave is..... Which has nothing to do with this, with a RunPE we simply don't let the exe load finish, and overwrites it's data with ours, simply put.

It was a misspell idiot, I was answering from my iPhone when I was with my GF answering, and wrote "Get" instead of "Query", get over it dude, how the hell would even make my injector work if I declared a wrong API name.

Just try my injector if you don't believe me, how can it be so hard?


Possibly Related Threads...
Thread / Author Replies Views Last Post
by HackersApr 14, 2024 12:50 PM 14 675 Apr 14, 2024 12:50 PM
Last Post: Hackers
[C] by maryousJul 24, 2022 03:35 PM 0 161 Jul 24, 2022 03:35 PM
Last Post: maryous
[C#] by gigajewJul 18, 2021 11:17 AM 26 2,920 Jul 18, 2021 11:17 AM
Last Post: gigajew