【问题标题】:Anti Sql injection Library C# Asp.NET反 Sql 注入库 C# Asp.NET
【发布时间】:2012-04-11 00:51:39
【问题描述】:

谁能为 Asp.NET 1.1 推荐这样的库?

谢谢。

【问题讨论】:

标签: sql-injection


【解决方案1】:

有很多选择,但老实说,最好的工具是教育。知道如何自己预防。如果使用得当,内置在普通框架类库中的工具是完全足够的。

对每个数据库调用简单地使用参数化查询和/或存储过程是最好的预防措施。

不过,话虽如此,我们确实使用 Microsoft 模式和实践库提供的 Microsoft.Practices.EnterpriseLibrary.Data 类。我们使用的那些有点过时,但仍然可以很好地完成工作。它们提供了一些注入保护并简化了数据访问。但它们不是完成这项工作的唯一工具,也不一定是最好的工具。

有关当前模式和实践库的更多最新信息,请访问here

【讨论】:

  • 项目已经编写的问题,并且将所有内容更改为参数化查询是真正的痛苦,所以我想也许有一些库将位于基本页面并会过滤请求......
  • 不。对不起。我知道有这样的 CSRF 工具,但不像你为 SQL 注入所描述的那样。对不起。鉴于 SQL 注入缺陷的普遍性和潜在损害(取决于您的 RDBMS),重新编写数据访问逻辑可能是值得的。无论如何,任何事情都需要使用不受信任的输入重写任何查询。
【解决方案2】:

Link to Anti-Injection SQL

    <?PHP
        FUNCTION anti_injection( $user, $pass ) {
               // We'll first get rid of any special characters using a simple regex statement.
               // After that, we'll get rid of any SQL command words using a string replacment.
                $banlist = ARRAY (
                        "insert", "select", "update", "delete", "distinct", "having", "truncate", "replace",
                        "handler", "like", " as ", "or ", "procedure", "limit", "order by", "group by", "asc", "desc"
                );
                // ---------------------------------------------
                IF ( EREGI ( "[a-zA-Z0-9]+", $user ) ) {
                        $user = TRIM ( STR_REPLACE ( $banlist, '', STRTOLOWER ( $user ) ) );
                } ELSE {
                        $user = NULL;
                }
                // ---------------------------------------------
                // Now to make sure the given password is an alphanumerical string
                // devoid of any special characters. strtolower() is being used
                // because unfortunately, str_ireplace() only works with PHP5.
                IF ( EREGI ( "[a-zA-Z0-9]+", $pass ) ) {
                        $pass = TRIM ( STR_REPLACE ( $banlist, '', STRTOLOWER ( $pass ) ) );
                } ELSE {
                        $pass = NULL;
                }
                // ---------------------------------------------
                // Now to make an array so we can dump these variables into the SQL query.
                // If either user or pass is NULL (because of inclusion of illegal characters),
                // the whole script will stop dead in its tracks.
                $array = ARRAY ( 'user' => $user, 'pass' => $pass );
                // ---------------------------------------------
                IF ( IN_ARRAY ( NULL, $array ) ) {
                        DIE ( 'Invalid use of login and/or password. Please use a normal method.' );
                } ELSE {
                        RETURN $array;
                }
        }


      [1]: http://psoug.org/snippet/PHP-Anti-SQL-Injection-Function_18.htm


  [1]: http://psoug.org/snippet/PHP-Anti-SQL-Injection-Function_18.htm

【讨论】:

    猜你喜欢
    • 2016-08-04
    • 2011-04-30
    • 2013-02-28
    • 1970-01-01
    • 2016-10-05
    • 2011-03-08
    • 2014-04-12
    • 2021-05-27
    • 2020-08-21
    相关资源
    最近更新 更多