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

C 

Dynamic Functions on Dynamic Libraries

Hello everyone,

Last day's I was trying to do this in c++:

Let's say I have a function foo(arg1, arg2), one client and one server.
arg1 can be any type, arg2 can be any type and foo can return any type of data. function Foo also has always to arguments.
I want the client to take as an input this function(for example):


Code
foo(arg1,arg2){
   if(arg1<arg2){
       return 1;
  }else{
       return 5.2;
 }
}


and then this function to be transferred and executed on the server.
I tried to build dynamic library with this function inside with templates. However templates are not supported with extern "C".
So any idea how can I implement this?

I know this is not secure but its only for educational purposes.
You can not execute code remotely like that, it would extremely hazardous to security. You can attach remote debuggers and execute functions there. Maybe you want to send shellcode across a network and execute that? If that's the case the shellcode needs to be PIC or you need to map the shellcode into memory and make sure all required modules are loaded before being executed.
An alternative is to just write your function inside your client, then just send a command from the server to execute the code. It would have to already be defined int he client.
It's a little more complicated if you want to send shellcode across to the client and execute it dynamically. Look into Windows Portable Executable format.
(Mar 9, 2019 01:04 PM)Auriana Wrote:  You can not execute code remotely like that, it would extremely hazardous to security. You can attach remote debuggers and execute functions there. Maybe you want to send shellcode across a network and execute that? If that's the case the shellcode needs to be PIC or you need to map the shellcode into memory and make sure all required modules are loaded before being executed.
An alternative is to just write your function inside your client, then just send a command from the server to execute the code. It would have to already be defined int he client.
It's a little more complicated if you want to send shellcode across to the client and execute it dynamically. Look into Windows Portable Executable format.

Honestly a flawless answer. Positionally independent shellcode really isn’t that hard to write. While not designed for windows, this project I wrote, called cshell, is similar in spirit, but for writing positionally independent shellcode in C. With windows it’s actually easier to write PIC code in C. Tutorials like this helped me develop some software, the source of which I wouldn’t share.

It’s highly doubtful you actually would want to execute remote shellcode in a normal context though... there are very obvious security concerns as Auriana mentioned.
SRPP Discord Server

I am a professional network/cloud security architect.
My Old Tutorials
as said you cant and writing shell code for remote execute is not simple if you want more then msgbox
what you can do is to use c library as a backend for dynamic code generation which let you send any code and run it
[Image: bitcoin.png] Be Nice For Once 15hVUVz7xA4kazHdk2BuErENGCskVwjYXP


Possibly Related Threads...
Thread / Author Replies Views Last Post
by user344335Apr 10, 2023 11:11 AM 0 146 Apr 10, 2023 11:11 AM
Last Post: user344335
[C] by jBarrelNov 15, 2022 02:52 PM 8 325 Nov 15, 2022 02:52 PM
Last Post: HFDone
[C] by WarrantAug 25, 2022 06:05 PM 12 401 Aug 25, 2022 06:05 PM
Last Post: yourtout