安全性背后的代码 ASP.NET .CS

发布于 2024-11-25 03:15:34 字数 167 浏览 1 评论 0原文

我是 Web 编程新手,对 ASP.NET C# 中的代码隐藏有疑问。别人看到里面的东西有多安全?我问的原因是我链接该网站的程序要求我创建一个接受我的管理员凭据的对象(它在后台执行此操作数千次,否则我只会提示输入凭据)。它使用凭据动态创建事物。我 99.99% 确信将我的凭据硬编码到页面中是非常不安全的,但我想我会问。

I'm new to web programming and have a question about code behind in ASP.NET C#. How safe is it from someone seeing what's in it? The reason I ask is the program I'm linking this website to requires me to create an object that takes in my admin credentials (It does this in the background thousands of times or I would just prompt for creds). It uses the credentials to create things dynamically. I'm 99.99% sure this is highly unsafe to hard code my credentials into the page but I figured I would ask.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

稳稳的幸福 2024-12-02 03:15:34

文件背后的代码和原始 aspx 文件受到保护,不会被 Web 服务器检索,因此只要您控制对服务器的控制台和文件共享访问,就相对安全。

尽管如此,它并不被认为是真正安全的。您应该将站点的应用程序池设置为在特定帐户下运行,然后授予该帐户必要的权限。使用普通用户帐户提供服务被认为是不好的做法。每个服务都应该有自己的帐户,并具有尽可能少的权限。

The code behind files and raw aspx files are protected from being retrieved by the web server, so as long as you control console and file share access to the server you are relatively safe.

Still, it is not considered really safe. You should set up the application pool of the site to run under a specific account and then give that account the necessary rights. Having services using ordinary user accounts is considered bad practice. Each service should have its own account, with least possible rights.

酒与心事 2024-12-02 03:15:34

ASP.NET 页面在通过 HTTP 发送页面之前进行编译。这是安全的。但是,如果用户可以访问文件系统,那么您就会遇到另一个问题。

ASP.NET pages are compiled before sending the page over HTTP. This is secure. But if the user can access the file system, you have another problem on your hands.

风柔一江水 2024-12-02 03:15:34

您应该将凭据放入 web.config 中(或者您可以将它们移动到单独的文件中,例如 AppSettings.config 或 ConnectionStrings.config 等)。服务器永远不应该提供这些服务。

这可能会有所帮助:
http://msdn.microsoft.com/en- us/library/4c2kcht0(v=VS.100).aspx

这告诉您如何进一步加密这些内容,以便它们不存储纯文本密码等:
http://weblogs.asp.net/scottgu/archive/2006 /01/09/434893.aspx

You should put your credentials in your web.config (or you can move them into separate files like AppSettings.config or ConnectionStrings.config etc). The server will should never serve these.

This might be helpful:
http://msdn.microsoft.com/en-us/library/4c2kcht0(v=VS.100).aspx

This tells you how you can can go one step further and encrypt these so they do not store plain text password etc:
http://weblogs.asp.net/scottgu/archive/2006/01/09/434893.aspx

闻呓 2024-12-02 03:15:34

这是“安全”的。 IIS(默认情况下)不提供 .cs 文件。

另一种选择是预编译站点,然后将 .aspx 文件拖放到 Web 服务器上。

It is "safe". IIS (by default) does not serve up .cs files.

Another option is to precompile the site and then just drop the .aspx files on the web server.

命硬 2024-12-02 03:15:34

默认情况下,将敏感信息放入 ASP.NET 中的 .cs 文件中并不是一个有风险的过程,因为 ASP.NET 不允许从客户端访问 .cs 文件(如果您不明确更改它),但是,请确保如果存在服务器错误,自定义错误报告模式不会将代码行发送到客户端(这在调试时非常有用,而当您向公众发布它时风险极大),或者任何人都可能能够读取您的敏感信息异常情况时的信息扔在那些线附近。

Putting sensitive information into .cs files in ASP.NET is by default not a risky process as ASP.NET does not give access to .cs files from the client side (if you don't change it explictly), however, be sure that if there is a server error, custom errors reporting mode does not send the lines of the code to the client (which is extremely useful when debugging, and extremely risky when you release it to the public) or anyone may be able to read your sensitive information if an exception is thrown near those lines.

无人接听 2024-12-02 03:15:34

这里有不同级别的“安全”。

是的,IIS 配置为不提供 .cs 文件或 .config 文件。也就是说,有 攻击向量已被证明可以成功让 IIS 将这些文件传递到邪恶者手中。

首先,我不会将 .cs 文件部署到服务器。如果可能,将网站转换为 Web 应用程序并部署已编译的版本。当然,.net 代码可以反编译 (反编译)。 com/products/decompiling.aspx" rel="nofollow noreferrer">和此处);所以你还应该研究混淆。然而,即使混淆的代码可以被反编译,但通常更难读。 ;)

请注意,每个级别并不是真正“安全”。它只会让事情变得更加困难。

真正的答案是根本不将凭据存储在服务器上,并要求客户端通过加密传输提供它们。当然,您可以将它们缓存在内存中,但即使 事实证明,对于那些有物理访问权限的人来说是不安全的

归根结底,问问自己这些密钥的价值有多大,以及您可以投入多少金钱/时间来保护系统。通常在某处存在平衡。

There are various levels of "safe" here.

Yes, IIS is configured to not serve up .cs files or .config files. That said, there are attack vectors which have proven successful in getting IIS to deliver those files into the evil doers hands.

First off, I wouldn't deploy .cs files to the server. If possible convert the web site to a web application and deploy it compiled. Of course, .net code can be decompiled (and here); so you should also look into obfuscation. However even obfuscated code can be decompiled but it's generally harder to read. ;)

Note that each level isn't really "secure". It just makes it more difficult.

The real answer is to not store the credentials on the server at all and require them to be provided by the client over an encrypted transport. Certainly you could cache them in memory, but even that has proven insecure to those with physical access.

At the end of the day, ask yourself how valuable the keys are and how much money/time you can invest in securing the system. There's usually a balance somewhere.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文