I am toying around with the idea of building an online C# interpreter, a bit like Codepad. Now there are obvious security issues:
My knowledge of C# isn't exactly insignificant, but I'm sure there are a lot that know much more about it, plus the stuff I didn't think about. What would you be careful about?
A few precisions, I plan on running this on a small Linux VPS using Mono.
C Language online compiler Write, Run & Share C Language code online using OneCompiler's C online compiler for free. It's one of the robust, feature-rich online compilers for C language, running the latest C version which is C18. Getting started with the OneCompiler's C editor is really simple and pretty fast.
Use Mono's Compiler as service capability. It can be compiled to a Silverlight compatible DLL (client profile), and has been already, which you can checkout. That should address some of your concerns about IO.
Reflection comes to mind, since you could go from GetType() to Assembly
to just about anything you want.
Actually user code can do anything. it would be hard to tackle special cases. In my opinion the best way to go is:
a) create sandbox appdomain with execution permission only. This ensures a lot of things like inability to mess with file system or make calls to native libraries.
b) create new process and start your appdomain in it.
Then monitor process tightly for memory and cpu consumption. If anything goes wrong - kill it. Note that it's the process you can kill, not appdomain. With appdomain you can try to unload it, but if malicious code running in finally clause then it wouldn't work.
There are still some (known to me) issues with this:
So all in all there is a risk anyway. i was toying around with this idea too and here is the current result: rundotnet
Check out this link, and you will be able to learn somethings on online C# interpreters, try out some things and read the output exceptions to see how they made it.
http://rextester.com/NWDF62346
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With