开发者

Can I allow my program to run scripts?

开发者 https://www.devze.com 2023-03-17 23:40 出处:网络
Some users are suggesting that my (C#) program should be able to run scripts after completing it\'s job. This would be done through a command line to be input in my configuration dialog.

Some users are suggesting that my (C#) program should be able to run scripts after completing it's job. This would be done through a command line to be input in my configuration dialog.

I'm no security expert, so I'm not sure if this acceptable in terms of security. Since the app runs with admin privileges (on Windows), wouldn't that be a huge security risk? Someone could just modify the config files of my application to point to a potentially dangerous script, couldn't they?

On the other hand, plenty of applications allow this, while requesting admin privileges, so I guess it must be ok, but I thought I'd better seek advice before opening wide security holes everywhere =)

Can I allow my application running with full privi开发者_Go百科leges to launch user-specified scripts?


You can restrict access to your config in different ways - from obfuscating the config file to using NTFS permissions to limit access of non-admin accounts to it.


C# certainly allows you to run a user script. System.Diagnostics.Process makes that real easy. The question of security here is another problem.

Running scripts when a process completes can be an incredibly useful and can make or break your target audience's opinion of your application. Understandably, you don't want your product to be turned against your own consumers through a malicious hack like you're thinking.

The root of this problem is that your options are (I'm assuming) text based and easily editable. Your best bet is to encrypt your config file to prevent outside changes to it. Note that this doesn't prevent people from using your app to change your options to allow a malicious script, but for somebody to do that, they need access to an instance of your application instead of simply file read/write access.

This does bring to question one more aspect you should watch for. Don't use the same key for every installation of your application. If you do that, then Bob could cause Alice to run a malicious script by copying Alice's config, using his instance of your app to decrypt it and make the change and then Bob can replace Alice's config with the new malicious config.

Here is another SO question for how to encrypt strings in C#.

0

精彩评论

暂无评论...
验证码 换一张
取 消