什么是SQL注入

用户输入的内容被浏览器当作SQL语句执行 关键点:输入的内容一定是SQL语句

数据库查询语法

select 列(属性)名 from 表明 where 条件

注入流程

1.判断是否有注入漏洞

and 1=1 --> 有查询结果
and 1=2 --> 无查询结果
==》网站存在注入漏洞
输入1=1时:select * from user where id=1 and 1=1
and的作用:条件1 and 条件2 (条件都成立,才算成立)

2.判断字段数

表格:行、列(字段)

使用order by语句(作用是排序)

eg:select * from user order by 1根据第一列进行排序

order by 1 --> 有查询结果-->第一列存在
order by 4 --> 无查询结果-->第四列不存在

3.判断回显点

回显点: 能够让数据库语句执行,并将结果输出在页面上

union:联合查询,能够同时执行两条SQL语句

同时执行两条SQL语句时查询的列数要一致

select 1,2,3 类似于占位

select占位

为了让网站返回合适的内容,有时需要让第一条语句报错,只执行第二条SQL语句

请输入图片描述

4.查询相关数据

用到的函数:

1.version() #函数,查询版本号
2.database() #函数,查询数据库

查表名

and 1=2 union select 1,2,table_name from information_schema.tables 
where table_schema=database() limit 0,1

limit m,n :从m+1行开始查询n条数据,包含第m+1行(类似于过滤输出)

table_name:是一个列名,存储网站管理员创建的表名

information_schema:是一个库名,这个库是mysql自带的

tables :十一个表名,存放在information_schema 库中

information_schema.tables :库.表 的结构

查列名

and 1=2 union select 1,2,column_name from information_schema.columns 
where table_schema=database() and table_name='users' limit 0,1

查数据

最后修改:2022 年 04 月 08 日
如果觉得我的文章对你有用,请随意赞赏