Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to sandbox and run C++ or C# code that's entered in a textfield in a browser?

Tags:

c++

c#

I'm diving into web development after ten years of desktop development and I'm experimenting with some testing concepts. I was wondering if it's possible to sandbox and run C++ code that's entered in a textfield in a browser? By that, I mean run the C++ or C# code on the backend webserver and return an analysis of the code. Just to be clear, I don't mean run C++ or C# code that's intended to generate any kind of markup, but simply to blackbox test the C++ or C# block of code that's entered.

  1. How would you invoke the compiler, depending on the web server you're using?
  2. How could you sandbox the code to prevent malicious behavior? If we're considering only one of the C variants, what about blacklisting/whitelisting specific functions and libraries to prevent malicious behavior? Or would that blacklist be too long and too limiting to allow any fair amount of code to run?

These are some fairly high-level questions that I'm asking just because I'm having a hard time finding some direction, but I'm going to continue researching them right now. Thanks so much in advance for your help!

like image 445
BeachRunnerFred Avatar asked Nov 15 '10 17:11

BeachRunnerFred


2 Answers

You might find the codepad about page interesting.

like image 133
jkerian Avatar answered Sep 20 '22 11:09

jkerian


# 1 is easy with C#. The Reflection capabilities of .NET allow you to compile and run code "on the fly." And here's a link to another good looking tutorial.

# 2 is a little more difficult but I suppose a basic sand boxing technique might involve executing a dynamic process under a limited, and therefore sand boxed account. Programmatically you could analyze the dynamicly built assembly's dependencies and not allow it to run if it used APIs in certain namespaces such as System.IO. This is non-trivial to say the least though.

C++ doesn't have reflection capabilities and so 3rd party libraries would be your best bet.

like image 37
Paul Sasik Avatar answered Sep 21 '22 11:09

Paul Sasik