先新建MYDB.MDF,表MyUser:

一、程序安全-SQL注入漏洞

 

测试页面:

一、程序安全-SQL注入漏洞

一、利用报错获取信息

操作:按姓名精确查询,在输入框输入:小卫' and 1=db_name()/0 and '1'='1
执行语句:select * from MyUser where UName='小卫' and 1=db_name()/0 and '1'='1
结果:得到数据库名“MYDB.MDF”

一、程序安全-SQL注入漏洞

 

操作:按姓名精确查询,在输入框输入:小卫' and 1=(select top 1 name from sys.tables)/0 and '1'='1
执行语句:select * from MyUser where UName='小卫' and 1=(select top 1 name from sys.tables)/0 and '1'='1
结果:得到表名“MyUser”

 

一、程序安全-SQL注入漏洞

 

修复建议:把接收参数的一个单引号变成两个单引号
执行语句:
select * from MyUser where UName='小卫'' and 1=db_name()/0 and ''1''=''1'
select * from MyUser where UName='小卫'' and 1=(select top 1 name from sys.tables)/0 and ''1''=''1'
结果:无报错信息

 

二、数字型注入
操作:按编号精确搜索,在输入框输入:2;delete from MyUser--
执行语句:select * from MyUser where UID=2;delete from MyUser--
结果:MyUser 表数据被删除
修复建议:过滤关键字 select、drop、delete 等

三、模糊查询

目的:搜索出姓名带“%”的客户
操作:按姓名模糊查询,在输入框输入:%
执行语句:select * from MyUser where UName like '%%%'
结果:全部的客户都被搜索出来了

修复建议:加中括号转义百分号:[%]
执行语句:select * from MyUser where UName like '%[%]%'
结果:只有姓名带“%”的客户被搜索出来

四、字符型注入

操作:按姓名模糊查询,在输入框输入:小程' or '1'='1
执行语句:select * from MyUser where '小程' or '1'='1'
结果:'1'='1 处可注入
修复建议:把接收参数的一个单引号变成两个单引号

五、order by 型注入
操作:排序规则选择“按年龄降序”,把 value="UAge DESC" 改为 value="UAge DESC,case when 1=1 then UID else UAge END"
执行语句:select * from MyUser order by UAge DESC;delete from MyUser
结果:1=1 处可注入
修复建议:采用数组映射的方式,如1代表按年龄降序,2代表按年龄升序

 

相关文章:

  • 2021-10-12
  • 2021-06-26
  • 2022-02-28
  • 2022-12-23
  • 2021-10-04
  • 2022-01-08
  • 2021-05-31
猜你喜欢
  • 2021-10-04
  • 2021-12-22
  • 2021-06-27
  • 2021-07-25
  • 2022-12-23
  • 2022-01-22
相关资源
相似解决方案