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, ";", "") ´将分号过滤掉
´...
%>
其他字符不一一枚举,你可以写一个字符过滤的函数,过滤一些在你的网站当中
并不常用的有危险性的符号;也可以采用正则表达式来进行过滤;
相关文档:
数据类型
在 Microsoft SQL Server中,每个列、局部变量、表达式和参数都有一个相关的数据类型,这是指定对象可持有的数据类型(整型、字符、money 等等)的特性。SQL Server 提供系统数据类型集,定义了可与 SQL Server 一起使用的所有数据类型。下面列出系统提供的数据类型集。
可以定义用户定义的数据类型,其是系统提 ......
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace DAL
{
......
1.首先需要建立plan table,否则不能使用
建立方法:
$oracle\rdbms\admin下有个
utlxplan.sql
其内容为:
create table PLAN_TABLE (
statement_id varchar2(30),
timestamp date,
remarks varchar2(80),
operat ......
首先要添加
using System.Data;
using System.Data.SqlClient;
接下来:
SqlConnection conn = new SqlConnection("server=QLPC\\SQL2005;uid=sa;pwd=(你的密码);database=(你的数据表)"); &n ......