![]() |
|
[C#] Executing Shellcode In C# (No Imports Required) - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [C#] Executing Shellcode In C# (No Imports Required) (/showthread.php?tid=5614445) |
Executing Shellcode In C# (No Imports Required) - atom0s - May 3, 2017 Someone on Tuts4You made a request to make a way to invoke shellcode within C# without any imports to things such as VirtualAlloc / VirtualProtect etc. I came up with this method as all of C#'s built-in memory allocations via the Marshal class and similar all create with no execution access for protection purposes. This method makes use of a memory mapped file which can be created with any protections that you want instead. This can be done all via the .NET frameworks built-in classes and such with no imports via DllImport. This is a simple example of creating a function via shellcode to get the PEB of a process. (Cheers to evlncrn8 for adjusting the shellcode from my original post to be more optimized.) PHP Code I am aware of the various assembly projects made for C# such as FASM and AssemblyJitter etc. however these projects all require external imports which was the goal of this idea, to not need any. * - N3oNight - May 3, 2017 Short and simple piece of code but works well good release buddy * - gigajew - May 3, 2017 Didn't know you were on here atom0s. Nice post and also I like your Lua stuff from back in the day * - Cecilia - May 4, 2017 (May 3, 2017 07:17 PM)gigajew Wrote: Didn't know you were on here atom0s. Nice post and also I like your Lua stuff from back in the day Oh, hello there giga :) Yes, good to have a completely managed solution. * - HFDone - May 4, 2017 the thing is that its work just with unsafe code so you cant use it with vb net but theres a trick to get it in vb too and needed framework 4 * - atom0s - May 4, 2017 (May 3, 2017 07:17 PM)gigajew Wrote: Didn't know you were on here atom0s. Nice post and also I like your Lua stuff from back in the day I pop on from time to time, haven't posted much at all lately though. (May 4, 2017 08:23 AM)HFDone Wrote: the thing is that its work just with unsafe code so you cant use it with vb net I don't code in Vb.NET since it is basically trash. Plus the point of this was to be done in C# anyway. I suggest you move to a better language rather than sticking it out with Vb.NET if that is what you code in. * - HFDone - May 6, 2017 i code in many languages. i say it cuz its the net section and even with C# you need to use unsafe code option. as i said theres a trick that you can use it without unsafe code anyway its good to have option to do it without using apis. * - Ast0r - May 7, 2017 I actually didn't know that this was possible. Good release! * - 0xDEAD10CC - May 7, 2017 You are forgetting to release the acquired pointer within a CER region of your code. There's other issues with this if you tested on various operating systems, this is specific to x32 processes only; PEB isn't at fs:[0x30] in x64. edit: Code private delegate IntPtr GetPebDelegate();* - atom0s - May 7, 2017 (May 7, 2017 01:18 PM)0xDEAD10CC Wrote: You are forgetting to release the acquired pointer within a CER region of your code. There's other issues with this if you tested on various operating systems, this is specific to x32 processes only; PEB isn't at fs:[0x30] in x64. I'm aware of the 32bit limitation, the purpose of the example was just to demonstrate the abilities on how to do this. And was pointed out on my Tuts4You post but forgot to mention it here. Granted I'm sure people that understand how this works and would understand how to use it can put the brain cells together to figure that out themselves. As for full error checking and all that junk, that's up to the user to implement and more less anti-copy/pasta for the derps that land up erroring things. |