简体   繁体   English

如何Snoop证明你的wpf应用程序?

[英]How to Snoop proof your wpf application?

Snoop allows you to look inside the application and change element properties. Snoop允许您查看应用程序内部并更改元素属性。 Its a great asset for developers, but can be a security issue in some cases, like when we have users who like to look in places where they shouldn't be looking. 它对开发人员来说是一笔巨大的财富,但在某些情况下可能会出现安全问题,例如我们的用户喜欢寻找他们不应该寻找的地方。 Is there a way to do something to block applications like Snoop from "snooping" your application? 有没有办法阻止像Snoop这样的应用程序“窥探”您的应用程序?

And if there is no way to block it, what do you recommend to do to minimize security risks? 如果没有办法阻止它,你建议做什么来降低安全风险?

Snoop is a utility that allows you browse visual tree of a wpf application and view and change properties. Snoop是一个实用程序,允许您浏览wpf应用程序的可视树并查看和更改属性。 Its very useful when you are trying to debug something and have no idea what is going on. 当您尝试调试某些内容并且不知道发生了什么时,它非常有用。 You can find more here . 你可以在这里找到更多。

Thank you. 谢谢。

There actually is a way to detect whether your application is being "snooped" by the snoop program. 实际上有一种方法可以检测您的应用程序是否被snoop程序“窥探”。 The solution I will give is not a silver bullet, and if someone really wants to snoop your application, they'd have to modify the snoop source code (it's an open source project). 我将给出的解决方案不是银弹,如果有人真的想要窥探您的应用程序,他们必须修改snoop源代码(这是一个开源项目)。

What snoop actually does is it injects an assembly into your application, and the injected assembly recursively examines your applications visual tree starting at the root. snoop实际上做的是将一个程序集注入到您的应用程序中,并且注入的程序集以递归方式从根开始检查您的应用程序可视树。 In other words, snoop actually runs inside your application. 换句话说,snoop实际上是你的应用程序中运行的。 That being said, the solution is to raise an event when the snoop assembly is injected into your application. 话虽如此,解决方案是在将窥探组件注入您的应用程序时引发事件。

First, you need to subscribe to the assembly-loaded event somewhere in your application (preferably the begginging): 首先,您需要在应用程序的某个位置订阅程序集加载的事件(最好是求助):

AppDomain.CurrentDomain.AssemblyLoad += new AssemblyLoadEventHandler(CurrentDomain_AssemblyLoad);

Then, you would implement the handler somewhat like this: 然后,您将像这样实现处理程序:

        void CurrentDomain_AssemblyLoad(object sender, AssemblyLoadEventArgs args)
    {
        if (args.LoadedAssembly.FullName.StartsWith("ManagedInjector"))
            MessageBox.Show("hey you, stop snooping");//and shut down your application.
    }

You would probably need to enhance this solution for real silver-bullet solution, but at least this solution will definitely stop the current latest version of snoop being run as is (without the code modified). 您可能需要为真正的银弹解决方案增强此解决方案,但至少此解决方案肯定会停止当前运行的最新版本的snoop(不修改代码)。 The better solution would be to check that no external assemblies are being injected into your application. 更好的解决方案是检查没有外部程序集注入您的应用程序。

However, Kent is still right in the fact that a utility like Snoop should not cause any security vulnerabilities since security should not be implemented at the UI level. 但是,Kent仍然是正确的,因为像Snoop这样的实用程序不应该导致任何安全漏洞,因为安全性不应该在UI级别实现。 But at least this shows you how to prevent people from "snooping" your application. 但至少这会向您展示如何防止人们“窥探”您的应用程序。

By implementing security properly. 通过正确实施安全性。 If your "security" can be thwarted with a tool like Snoop, then you're doing it wrong. 如果使用像Snoop这样的工具可以阻止你的“安全性”,那么你做错了。

Suppose there's a command that only certain users can execute. 假设有一个只有某些用户才能执行的命令。 It sounds like the only place you're enforcing this is at the UI level (by disabling the corresponding button, for example). 听起来这是您执行此操作的唯一地方是在UI级别(例如,通过禁用相应的按钮)。 That being the case, you're right - I could easily use Snoop to enable the button and execute the command. 既然如此,你是对的 - 我可以轻松使用Snoop来启用按钮并执行命令。 But you should be enforcing the security constraints on your server, or perhaps in your command execution logic if you have no server. 但是,如果没有服务器,则应该在服务器上强制执行安全约束,或者在命令执行逻辑中执行安全约束。 Basically, security should be implemented as close to the thing you're trying to protect as possible. 基本上,安全性应该尽可能接近你想要保护的东西。 Security at the UI level is merely for convenience of the user. UI级别的安全性仅仅是为了方便用户。

Great responses for a very good question, 对一个非常好的问题的好评,

I want to add an example of the password that should never be saved in your datacontext, as snoop check also the datacontext of the UI, so if you use the right control PasswordBox you will find that you can't bind the password property, that means even if you snoop the application you can't get the password as it is not saved in any property 我想添加一个永远不会保存在datacontext中的密码示例,因为snoop检查UI的datacontext,所以如果使用正确的控件PasswordBox,你会发现你无法绑定密码属性,即使您窥探应用程序也意味着您无法获取密码,因为它不会保存在任何属性中

But we found many people who try to create a work around (helpers, behaviors, usercontrol ...) to bind the password, but they forget that snoop can get it like that 但我们发现很多人试图创建一个解决方案(帮助者,行为,用户控制......)来绑定密码,但是他们忘记了窥探可以让它像那样

So your server should never trust your client , every time it should check the right privilege (as we can sniff the client request using Fiddler for exp then rebuild a custome request to by pass client application security) 因此,每次应该检查正确的权限时,您的服务器永远不应该信任您的客户端(因为我们可以使用Fiddler为exp嗅探客户端请求,然后通过传递客户端应用程序安全性来重建客户请求)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM