ColdFusion sql问题

时间:2018-09-06 13:57:24

标签: sql coldfusion include sql-injection

针对URL进行安全扫描,并收到以下报告:

该漏洞会影响

 /rolecall.cfm , bbb_id

这是rolecall.cfm代码:

<cfscript>
if (isDefined("url") and isDefined("url.bbb_id")) {
    if (url.dept_id eq -1)
        _include("sql", "getB");
    else
        _include("sql", "getBNow");
}

/*...*/
_include("sql", "getDPlaces");

/*Set up the model and go*/
model = {
    add    = 1,
    edit   = 0,
    remove = 0,
    places   = getDPlaces
};
</cfscript>

2 个答案:

答案 0 :(得分:4)

如果您使用的是IIS,则应read this article以查看如何将SQL注入保护直接添加到Web服务器。这将使攻击请求永远不会到达ColdFusion。

请谨慎对待他们建议您拒绝的字符串:

having

确保不要将电子邮件地址作为查询字符串参数的值传递,否则,您将拒绝合法请求。如果需要,可以允许select id_posizione as posizione, Count(distinct IDENTIFICATIVO_TRANSAZIONE) as count_transazioni from GP_TRANSAZIONI group by id_posizione having Count(distinct IDENTIFICATIVO_TRANSAZIONE)>1 order by id_posizione; 符号。

我也强烈建议您查看HackMyCF,它将向您显示许多其他安全问题(如果存在)。

答案 1 :(得分:3)

SQL Injection通过将恶意sql 命令填充到查询中不需要的地方来利用数据库。诱使查询执行与设计不同的操作,例如执行DROP或DELETE而不是SELECT。

  1. 使用像这样的原始客户端参数的查询很容易受到攻击:

    WHERE policy_funct_id = #url.dept_id#
    

    相反,始终将客户端提供的参数包装在cfqueryparam中。这样可以防止将它们作为命令执行。我不知道您的列数据类型,因此请根据需要修改cfsqltype。

    WHERE policy_funct_id = <cfqueryparam value="#url.dept_id#" cfsqltype="cf_sql_integer">
    
  2. 所有动态表名称都是另一个(潜在)漏洞,例如:

    -- potential sql-injection risk
    SELECT * FROM #db.root#
    

    如果用户提供了#db.root#,则存在sql-i风险。不幸的是,cfqueryparam cannot be used on table names。这些必须手动(并仔细)验证。


与SQL注入无关的其他建议:

  • 所有嵌套的(select * from...)语句都会降低可读性。而是使用单级JOIN。

  • 使用JOIN时,最好为所有列指定源表(或表别名)。这样可以避免歧义,并提高您自己和其他任何检查代码的人员的可读性。无需猜测哪些列来自哪个表。

示例

-- psuedo example
 SELECT  root.ColumnA
    , root.ColumnB
    , dept.ColumnC
    , subcat.ColumnC
    , etc... 
 FROM #db.root# root 
       INNER JOIN #db.content# content ON root.policy_root_id = content.content_id
       INNER JOIN #db.dept# AS dept ON ON content.dept_id = dept.policy_funct_id
       INNER JOIN #db.subcat# subcat ON subcat.dept_id = dept.policy_funct_id
 WHERE dept.policy_funct_id = <cfqueryparam value="#url.dept_id#" cfsqltype="cf_sql_integer">
 AND   content.is_newest = 1