mysql ibatis like_用Ibatis中Like中SQL注入,被批

在项目中,运用Ibatis中Like写法,没有研究下,结果SQL语句存在SQL注入漏洞,整理下,下次谨记啊!

sql语句:

select *

from (select 1 from poll

title like '%$title$%'

0 and status & 1 <= 0 and status & 8 <= 0 ]]>

= #startTimeBegin# ]]>

limit 10000

) as t

请关注此写法的:

title like '%$title$%'

存在SQL注入漏洞。

下面是一段单元测试:

PollQuery query = new PollQuery();

query.setCurrentPage(1);

query.setPageSize(50);

query.setTitle("1231%' or '1%' = '1");//很简单的写法:(

List l = pollDAO.findPollList(query);

System.out.println(l.size())

测试结果(打印处的sql语句):

1. select * from poll where title like '%1231%' or '1%' = '1%'

尽管 title 没匹配对,但是or后面那句是恒等的。哎!

看来下面的写法只是简单的转义下:

title like '%$title$%'

如何解决:

在oracle下面改成:title like '%'||#title#||'%',这样肯定是可以的。

但是在mysql中,上述写法是不行,还是有上面的问题的:

select * from poll where title like '%'||?||'%' order by gmt_create desc limit ?, ?

还能查出结果来!哎!

得用:title CONCAT('%',#title#,'%')

select * from poll where title like CONCAT('%',?,'%') order by gmt_create desc limit ?, ?

呵呵,多次测试均没有发现问题!

分享到:

18e900b8666ce6f233d25ec02f95ee59.png

72dd548719f0ace4d5f9bca64e1d7715.png

2009-03-31 17:27

浏览 6054

评论

1 楼

sweat89

2012-12-01

it's helpful to me ,thk

966903dea4bcb507358d5dcce8b912e5.gif

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值