tags:

views:

27

answers:

2

Given that you have found a process that you wish to execute a function call to, is it possible to call a function and get a return value from that process. (possibly using reflection or something similar?)

For example, suppose the process I was interested in was always the 1st process returned (I know it won't be), I would like to do something like the following:

Process[] myProcesses = Process.GetProcesses();
int UserID = myProcesses[0].*GetUserID*();

Where GetUserID() is a public static function with that processes assembly.

All the code is managed code

+1  A: 

Kind of, however you can't do this in the way that you describe.

It is called inter-process communication, and requires that the process containing the method GetUserID() expose that method through some inter process communication mechanism - for example .Net remoting or WCF.

The way that you might then call that exposed method would also be very different depending on the way that method was exposed.

There is a basic tutorial here on how to achieve this using WCF:

Kragen
+2  A: 

Not without some form of interprocess communication. The "target" process would have to have some server or listener running (WCF, Named Pipes, socket, etc). You can send windows messages to another process, but even then, the other app would have to be listening for them and know how to execute some action based on them.

Even mechanisms that typically associated with attacks (such as stack overflows, sql injection, and others) typically require the application to be listening or acting as a server of some kind and the attack takes advantage of that listening system

Zippit