SQL、微软 SQL

发布于 2024-10-07 11:51:53 字数 541 浏览 0 评论 0 原文

我试图对我的系统的登录单元进行压力测试。我的系统是这样设计的 -

如果用户输入 userid - abcd 和密码 pass,那么服务器将获取这些参数并准备一个 sql 命令并将其发送到 microsoft 数据库 -

select password from UserInformationTable where userid = 'abcd';

返回的值与给定的密码 pass 进行比较,然后结果是发送给客户端。

我使用以下方法成功侵入系统 -

用户输入用户 ID - >。这有效,我的完整 UserInformationTable 被删除。

有没有什么优雅的方法来处理这样的黑客问题?一种方法是检测用户 ID 中的“或”子字符串,但我觉得这不太优雅。有什么办法可以限制不。 microsoft sql 语句中的查询数量?

谢谢和问候, 拉兹

I was trying to stress test my system's login unit. My system is designed like this -

if the user enters userid - abcd and password pass then the server takes these parameters and prepares an sql command and fires it to the microsoft database-

select password from UserInformationTable where userid = 'abcd';

The returned value is compared with the given password pass and result is then sent to the client.

I successfully broken into the system using the following method -

user enters userid - <abcd1 or drop table UserInformationTable >. This worked and my complete UserInformationTable got dropped.

Is there any graceful way of handling such a hacking problem. One way is to detect 'or' substring in the userid, but I did not find this very graceful. Is there any way I can restrict the no. of queries in a statement in microsoft sql ?

Thanks and Regards,
Radz

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

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

发布评论

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

评论(3

错々过的事 2024-10-14 11:51:53

这就是著名的“Bobby Tables”漫画所说明的 SQL 注入问题。

这里 是有关如何修复 MS SQL 的一些信息。特别阅读@Rook的回答。

This is the SQL injection problem illustrated by the famous "Bobby Tables" cartoon.

Here is some info on how to fix it for MS SQL. Read especially @Rook's answer.

拿命拼未来 2024-10-14 11:51:53

你有两个问题。

  1. 正如其他用户所描述的,您受到 SQL 注入攻击。通过清理您的输入和/或使用参数化查询来解决该问题。

  2. 您不应存储或传输纯文本密码。为什么?请参阅 Slashdot。此问题的解决方案是使用单向加密创建密码哈希值以存储在数据库中。当用户尝试对其提供的密码使用相同的加密进行登录时,请搜索数据库以查看是否存在具有相同用户 ID 和密码哈希的行。

You have two problems.

  1. You are subject to SQL injection attack as described by other users. Solve that problem by sanitizing your input and/or using parameterized queries.

  2. You should neither store nor transmit plain text passwords. Why? See this story on Slashdot. The solution to this problem is to use one-way encryption to create a password hash to store in the database. When the user tries to log in use the same encryption on the password he or she provides, then search your database to see if a row exists with the same userid and password hash.

寄人书 2024-10-14 11:51:53

在 SQL 查询中使用参数。他们会自动阻止这种情况发生。 C# 中是这样的:

SqlCommand comm = new SqlCommand(conn);
comm.CommandText = "SELECT * FROM foo WHERE bar = @id";
comm.CommandType = CommandType.Text;

SqlParameter param = new SqlParameter("@id", DbType.Int64);
param.Value = 3; // The actual value that replaces @id

comm.Parameters.Add(param);

// ...

这不仅适用于 C#,而且基本上所有现代数据库系统和语言都支持参数化查询 <- google 一下。

其次,您的第一个查询可以更改为:

SELECT userid FROM users WHERE username = 'foo' AND password = 'bar'

然后计算返回的行数,如果为 0,则用户输入了错误的密码。

Use parameters in SQL queries. They automatically prevent this. Something like this in C#:

SqlCommand comm = new SqlCommand(conn);
comm.CommandText = "SELECT * FROM foo WHERE bar = @id";
comm.CommandType = CommandType.Text;

SqlParameter param = new SqlParameter("@id", DbType.Int64);
param.Value = 3; // The actual value that replaces @id

comm.Parameters.Add(param);

// ...

This not only applies to C#, but basically all modern DB systems and languages support parameterized queries <- google it.

And second, your first query can be changed to:

SELECT userid FROM users WHERE username = 'foo' AND password = 'bar'

Then just count how many rows you got returned, if it's 0, then the user entered the wrong password.

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