一,对sql注入的理解

sql注入使是一种常见的web漏洞,产生原理是网站没有对用户输入的内容进行过滤或者检查,使我们能够输入sql命令(sql:结构化查询语句),然后被后台拼接带到数据库里进行执行,这样我们就能够对数据库进行增删改查的操作了(重点在于服务端到数据库的过程)

1,产生的原理

网站把我们的输入当成了代码执行

2,简单的sql注入

想要做到sql注入首先网站要有sql注入点,然后再看我们拼接上去的代码能不能执行。

select * from user where 用户名='yonghuming' and 密码='mima' #原本的登陆验证
select * from user where 用户名='yonghuming''or 1=1 --' and 密码='mima' #注入后的

这就是一个简单的sql注入,直接跳过了密码验证。

3,可能的注入点

网站url,登录界面,搜索框,Cookie,请求头,文件名,UA头,referer等。

4,危害

sql注入的危害是很大的,他能够直接查看数据库里用户的重要敏感信息,盗取用户账号密码,修改数据库内容甚至控制服务器。

二,sql注入的类型

1,字符型注入

先闭合sql语句再进行注入

2,数字型注入

直接sql注入

三,一些常用的查询语句

1,查询数据库名

select schema_name from information_schema.schemata limit 1
select group_concat(schema_name) from information_schema.schemata

select schema_name from information_schema.schemata limit 1

作用:从系统表里查数据库名只返回1个

information_schema.schemata:MySQL系统表,存了所有数据库的信息

schema_name:这个表里存数据库名的字段

limit 1:限制只返回第1条记录

select group_concat(schema_name) from information_schema.schemata

作用:一次性查出所有数据库名

group_concat():把一列的所有值拼成一个字符串,进行分组

执行后会得到类似 information_schema,pikachu,mysql 这样的结果,不用一条一条查

2,查数据库里的表名

select table_name from information_schema.tables where table_schema=... limit 1
select group_concat(table_name) from information_schema.tables where table_schema='...'

 select table_name from information_schema.tables where table_schema=... limit 1

作用:在...数据库里查表名只返回1个

information_schema.tables:系统表,存了所有数据库里的所有表的信息

table_schema='...':过滤条件,只查...库下的表

table_name:这个表里存的字段

limit 1:同样是限制返回1条

注意:这里的数据库名,要加单引号 '...',不加会报错

select group_concat(table_name) from information_schema.tables where table_schema='...'

作用:一次性查出库下的所有表名

执行后会得到类似 users,admin,message 这样的结果

3,查指定表的字段名

select column_name from information_schema.columns where table_schema='pikachu' and table_name='users' limit 1
select group_concat(column_name) from information_schema.columns where table_schema='pikachu' and table_name='users'

select column_name from information_schema.columns where table_schema='...' and table_name=',,,' limit 1

作用:在...库的,,,表里查字段名只返回1个

information_schema.columns:系统表,存了所有表的所有字段的信息

table_schema='...':指定数据库

table_name=',,,':指定表名

column_name:这个表里存字段名的字段

limit 1:限制返回1条

select group_concat(column_name) from information_schema.columns where table_schema='...' and table_name=',,,'

作用:一次性查出表里的所有字段名

执行后会得到类似 id,username,password,email 这样的结果,快速找到存账号密码的字段

4,查表里的实际数据

select 字段 from 库.表 where ..=..

查询格式,在注入里的用法是:
select username,password from pikachu.users where id=1
意思是:从 pikachu 库的 users 表里,查询 id=1 的用户的 username 和 password 字段值

作用:拿到了库名、表名、字段名后,用这条语句直接读真实数据

Logo

openEuler 是由开放原子开源基金会孵化的全场景开源操作系统项目,面向数字基础设施四大核心场景(服务器、云计算、边缘计算、嵌入式),全面支持 ARM、x86、RISC-V、loongArch、PowerPC、SW-64 等多样性计算架构

更多推荐