这个正则表达式模式是否会捕获所有需要的SQL注入?

You*_*nes 2 regex firewall sql-injection

我们将防火墙规则(REGEX)更改为以下内容:

Name
 Type
 Context
 Severity
 Pattern

CS:select_into
 signature
 http-url
 critical
 .*\[select\]\s+.*\[into\].*

CS:select_from
 signature
 http-url
 critical
 .*\[select\]\s+.*\[from\].*

CS:insert_into
 signature
 http-url
 critical
 .*\[insert\]\s+.*\[into\].*

CS:drop_database
 signature
 http-url
 critical
 .*\[drop\]\s+.*\[database\].*

CS:drop_table
 signature
 http-url
 critical
 .*\[drop\]\s+.*\[table\].*

CS:delete_from
 signature
 http-url
 critical
 .*\[delete\]\s+.*\[from\].*

CS:drop_view
 signature
 http-url
 critical
 .*\[drop\]\s+.*\[view\].*

CS:exec
 signature
 http-url
 critical
 .*\[exec\].*(%28|\().*(%29|\)).*

CS:update_set
 signature
 http-url
 critical
 .*\[update\](%20|\+)(%20|\+|.)*\[set\].*
Run Code Online (Sandbox Code Playgroud)

这会阻止所有SQL注入尝试吗?例如,是否可以使用多个空格删除视图?

Adr*_*ith 21

黑名单是错误的方法.总会有一些你没有想过的东西,攻击者会想到这些东西.

你使用什么编程语言/数据库?它们都有将参数传递给SQL语句的方法.例如:

String userName = .... ; // from your GET or POST parameter
String sql = "SELECT id FROM user where user_name=?";
ResultSet rs = executeSql(sql, userName);
Run Code Online (Sandbox Code Playgroud)

请参见http://en.wikipedia.org/wiki/SQL_injection#Parameterized_statements

  • +1,如果你是防守,那么你不会黑名单 (2认同)