易截截图软件、单文件、免安装、纯绿色、仅160KB

SQL注入攻击防范技巧


SQL注入攻击防范技巧
一般的SQL注入攻击都是通过构建一条复杂的sql语句,
通过网页漏洞来执行sql语句,达到攻击数据库的目的。
如通过文章ID来查询某一篇文章的网页,
通常采用的sql语句为:
sql="select top 1 * from articles where articId="&request("id")
那么可以简单地构建一条攻击语句:
传入id变量的值为:1; select getDate(); --
从而构建了一条新的sql语句:
select top 1 * from articles where articId=1;
select getDate(); --
虽然这条语句并不能对数据库产生任何负面影响,
但是其它的攻击语句也是这样通过添加语句分隔符;和注释符号--来组成的。
我们的防范技巧,对所有可以提交传入的变量进行处理:
1、int类型的数据,如上例中的id,则使用以下方法处理:
   <%
 on error resume next
 id = CInt(request("id"))
   %>
2、字符串类型的数据,则进行常见的标点符号过滤处理:
   <%
 str = request("str")
 str = replace(str, "´", "") ´将单引号字符过滤掉
 str = replace(str, ";", "") ´将分号过滤掉
 ´...
   %>
   其他字符不一一枚举,你可以写一个字符过滤的函数,过滤一些在你的网站当中
   并不常用的有危险性的符号;也可以采用正则表达式来进行过滤;


相关文档:

SQL语句PART8

PairWise subquery:
e.g.:
select * from wf_docsort where (ndocsortid,nmoduleinfoid)  in (select ndocsortid, nmoduleinfoid from wf_docsort where instr(cname,'文')>0)
the above sql is the same function as:
select * from wf_docsort where ndocsortid = (select ndocsortid from wf_docsort where ......

SQL语句PART9

Group functions
SELECT [column,] group_function(column) ... from table [WHERE condition] [GROUP BY group_by_expression] [ORDER BY column];
e.g.:
SELECT department_id, job_id, SUM(salary), COUNT(employee_id) from employees GROUP BY department_id, job_id ;
SELECT [column,] group_function(column).. ......

动态SQL基本语法

 1 :普通SQL语句可以用exec执行
Select * from tableName
exec('select * from tableName')
exec sp_executesql N'select * from tableName' -- 请注意字符串前一定要加N
2:字段名,表名,数据库名之类作为变量时,必须用动态SQL
declare @fname varchar(20)
set @fname = 'FiledName'
Select @fname fr ......

sql 经典一

1.建表
create table temp(rq varchar(10),shengfu nchar(1))
2.插入数据
insert into temp values('2005-05-09','胜')
insert into temp values('2005-05-09','胜')
insert into temp values('2005-05-09','负')
insert into temp values('2005-05-09','负')
insert into temp values('2005-05-10','胜')
insert i ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号