SQL注入

什么是SQL注入

SQL注入:利用现有应用程序,将(恶意)的SQL命令注入到后台数据库执行一些恶意的
作。
造成SQL注入的原因是因为程序没有有效过滤用户的输入,使攻击者成功的向服务器提交恶意的SQL查询代码,程序在接收后错误的将攻击者的输入作为查询语句的一部分执行,导致原始的查询逻辑被改变,额外的执行了攻击者精心构造的恶意代码

SQL注入防攻击手段

不要使用拼接SQL语句方式、最好使用预编译方式,在mybatis编写sql语句的时候,最好使用#传参数方式,不要使用$传参数,因为$传参数方式,可能会受到sql语句攻击。

演示案例:
http://127.0.0.1:8080/login?userName=‘cc’&password=‘123’
http://127.0.0.1:8080/login?userName=‘cc’&password=‘123’ or 1=1

@RestController
public class LoginController {
	@Autowired
	private UserMapper userMapper;

	@RequestMapping("/login")
	public String login(UserEntity userEntity) {
		System.out.println("账号密码信息:userEntity:" + userEntity.toString());
		UserEntity login = userMapper.login(userEntity);
		return login == null ? "登陆失败!" : "登陆成功!";
	}

}

public interface UserMapper {

	@Select(" SELECT  * FROM user_info where userName=${userName} and password=${password}")
	public UserEntity login(UserEntity userEntity);

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值