jeudi 28 janvier 2016

Dynamically load assembly from local file and run with restricted privileges

What I need to do is : Read a local C# text file, execute a method from that. This is what I'm doing.

  1. Read all text from the file
  2. Compile into a local x.dll with CSharpCodeProvider
  3. Load the dll with Assembly.LoadFrom()
  4. Then execute the method with GetType().GetMethod().Invoke()

It works fine. Now, I want to run this code securely, i.e. restrict this code from accessing the file system, network etc. Basically, I need to run this with minimal privileges.

I tried the code from Restrict plugin access to file system and network via appdomain (answer by @Babar), but still not working as expected. The code in the text file is still able to access file system.

What I'm missing here? Any other way to make it work?





Aucun commentaire:

Enregistrer un commentaire