|
[原创]J2EE_WEB安全测试系列文章
没人顶、自己顶 |
|
[原创]J2EE_WEB安全测试系列文章
接上章继续,后续章节有空再慢慢补,最近工作有点变动,有点抽不出时间整理,这些都是之前工作中断断续续整理的一些内容 三、文件I/O类漏洞测试 3.1、下载类漏洞 3.1.1、漏洞产生原因分析 文件下载功能设计不当,可能导致目录穿越漏洞(php中称为文件包含),可以通过构造filename、filepath等下载文件名路径下载任意文件,导致敏感信息泄露。 漏洞代码示例: 3.1.2、安全测试方法 一般存在类似漏洞,都会类似存在一些共性,现在文件名+参数,例如,filename=?或filepath=?或file=?或path=? 一般测试,可在正常文件名前加%0a/../,观测是否可正常下载,如果下载正常,很可能存在问题,更多测试payload网上很多,下面例举部分: 1、 download?filename=../../../../../../../etc/passwd; 2、 download?filename=../../../../boot.ini; 3、 download?filename=/../..//../..//../../etc/passwd%00.jpg; 4、 download?filename=/../..//../../etc/passwd%3f.html 5、 java语言中会把"%c0%ae"解析为"\uC0AE",最后转义为ASCCII字符的"."(点)。 3.1.3、修复建议 对客户端下载文件名uri进行检查,可参考以下代码: String filename = request.getParameter("filename"); 获取的filename参赛可能为../../或/../../总之有.. if(filename.indexOf("..")>=0){ PrintWriter pw=response.getWriter(); pw.print("下载文件非法.."); } else{ 业务…. } 3.2、文件上传漏洞 ν 漏洞概述 上传漏洞,根据其意主要是由于文件上传过程中安全设计有问题,导致可以非法上传恶意脚本文件,根据漏洞利用方式又可以细分为客户端检测漏洞、服务端MIME类检测漏洞、服务端文件扩展名检测漏洞、服务端文件内容检测漏洞、服务端文件路径检测漏洞、及web容器解析(IIS、apache、nginx)漏洞等,可参考下述链接: http://www.owasp.org.cn/OWASP_Training/Upload_Attack_Framework.pdf 本节以客户端检测、文件扩展名检测进行举例说明: 3.2.1、客户端上传检测漏洞 υ 漏洞产生原因 客户端上传文件至Web服务器过程采用客户端javascript 、ajax进行文件合法性检测检测,漏洞代码参考: Javascript检查文件扩展名 function fileFormatCheck(s) { var i = s.lastIndexOf(".");//获取文件名.字符串位置 if(i < 0) { alert("<%translate("Certificate file error"); %>."); return false; } var var1 = s.substring(i+1) ;//获取文件名. 后面后缀 if(var1 == "jpg" || var1 == "gif" || var1 == "jpeg") { return true; } else { alert("<%translate("Certificate file error"); %>."); return false; } } υ 安全测试方法 1、借助firebug、浏览器自带开发者工具、鼠标定位到提交按钮,查看上传动作,定位到代码段,如果有类似onsubmit、onclick等响应函数,则可能采用本地检测; 2、采用本地安全检测有个明显特点,选择待上传文件后,如果文件不合法,则在点提交动作前,提前触发; 3、将.jsp文件上传前改为.jpg等合法文件,并借助burpsuite工具拦截修改上传报文。 υ 修复建议 见本章节文件上传漏洞修复方案。 3.2.2、服务端文件扩展名检测漏洞 υ 漏洞产生原因 服务端对上传文件扩展名检测机制存在设计问题,如使用黑名单机制文件扩展名类型有遗漏、或匹配扩展名代码有缺陷。 漏洞代码示例: υ 安全测试方法 更多参考:http://www.owasp.org.cn/OWASP_Training/Upload_Attack_Framework.pdf 3.2.3、其他参考pdf介绍 补充一点,在servlet 3.0之前,javaweb上传文件比较麻烦,往往需要借助第三方sdk,如apache commons-fileuplaod-1.2.1.jar、commons-io-1.4.jar,往往在实现时,程序员容易忽视上传安全机制。 HashMap<String, String> extMap = new HashMap<String, String>(); extMap.put("image", "gif,jpg,jpeg,png,bmp"); extMap.put("flash", "swf,flv"); extMap.put("media", "swf,flv,mp3,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb"); extMap.put("file", "doc,docx,xls,xlsx,ppt,htm,html,txt,zip,rar,gz,bz2"); // 检查扩展名 String fileExt = fileName.substring( fileName.lastIndexOf(".") + 1).toLowerCase(); if (!Arrays.<String> asList(extMap.get(dirName).split(",")) .contains(fileExt)) { out.println(getError("上传文件扩展名是不允许的扩展名。\n只允许" + extMap.get(dirName) + "格式。")); return; } |
|
[原创]J2EE_WEB安全测试系列文章
接上个章节讲 2.1、会话固定漏洞(失效的会话管理) 2.1.1、漏洞产生原因 该漏洞主要是因为Web应用程序没有正确的执行会话管理,例如用户登陆前的会话Cookie和登录后的是一样的,另外一个例子是当用户点击退出的时候,Session不会失效。 漏洞代码示例: <%@page import="java.sql.*"%> <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title> </title> </head> <body> <% String user = request.getParameter("user"); String pass = request.getParameter("pass"); Class.forName("com.mysql.jdbc.Driver"); Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb", "root" , ""); PreparedStatement ps=(PreparedStatement) con.prepareStatement("select * from users where username=? and password=? limit 0,1"); ps.setString(1,user); ps.setString(2,pass); ResultSet rs=ps.executeQuery(); if(rs.next()) { session.setAttribute("useracc", rs.getString("user")); out.println("Login success"); } else { out.println("Login failed"); } %> </body> 2.1.2、安全测试方法 漏洞测试比较简单,可借助Firefox、Burpsuite等工具在观察登录前、登录后、退出状态下cookie、jsessionid是否有异同,如果不变,则存在问题。 2.1.3、修复建议 一般来说,解决固定会话是相当容易的。最基本的建议就是:一旦用户登录成功以后,马上invalidate用户的会话。具体的步骤如下: ➊ 用户输入用户名和密码。 ➋ 系统对用户进行验证通过。 ➌ 已有的会话信息如果仍然需要,则转移到一个临时变量中去(请参考➌)。 ➍ invalidate 当前的会话(请参考➍)。 ➎ 创建一个新的会话(请参考➎)。 ➏ 把临时变量中保存的会话信息恢复到新创建的会话中去(请参考➏)。 ➐ 用户使用这个新的会话登录到系统中并进行操作。 修复代码参考: <% String user = request.getParameter("user"); String pass = request.getParameter("pass"); Class.forName("com.mysql.jdbc.Driver"); Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/userdb", "root" , ""); PreparedStatement ps=(PreparedStatement) con.prepareStatement("select * from users where username=? and password=? limit 0,1"); ps.setString(1,user); ps.setString(2,pass); ResultSet rs=ps.executeQuery(); if(rs.next()) { session.invalidate(); request.getSession(true); session.setAttribute("useracc", rs.getString("user")); out.println("Login success"); } else { out.println("Login failed"); } %> 以上修复后的代码中,用户在登录的时候,首先会让之前的session失效,然后又获取新的seesion。 2.2、越权漏洞 2.2.1、漏洞产生原因 如果一个Web应用程序不严格检查用户是否被授权访问(鉴权),就有可能产生越权类安全问题。例如帐号A在登录的状态下,遍历访问资源ID就可以查看其它人的相关信息。 漏洞代码示例: <%@page import="java.util.Enumeration"%> <%@ page import="java.sql.*" %> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Account Balance</title> </head> <body> <% int flag = 0; Enumeration e = session.getAttributeNames(); while (e.hasMoreElements()) { String name = (String) e.nextElement(); String value = session.getAttribute(name).toString(); if(name.equals("useracc") && !(value.isEmpty())) { flag = 1; break; } } if(flag == 1) { String accno = request.getParameter("accno"); Class.forName("com.mysql.jdbc.Driver"); Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/mydb", "root", ""); PreparedStatement ps = (PreparedStatement) con.prepareStatement("select * from account_balance where accno=? limit 0,1"); ps.setString(1,accno); ResultSet rs = ps.executeQuery(); if(rs.next()) { String s = rs.getString("balance"); out.println("<h1>Welcome to your account</h1>"); out.println("<br>Account Number: "+session.getAttribute("useracc")); out.println("<br>Your current balance is: "+s); } else { out.println("Error: Contact administrator."); } } else { response.sendRedirect("login.jsp"); } %> </body> </html> 2.2.2、安全测试方法 抓包修改用于区分用户标识的account_id、memberid字段,查看是否可以越权查看其他人信息。 2.2.3、修复建议 判断了用户的Session,在为True的情况下才能够查看返回的信息,因此当用户遍历accno的值来尝试获取返回结果时,会提示无权访问。 <% int flag = 0; Enumeration e = session.getAttributeNames(); while (e.hasMoreElements()) { String name = (String) e.nextElement(); String value = session.getAttribute(name).toString(); if(name.equals("useracc") && !(value.isEmpty())) { flag = 1; break; } } if(flag == 1) { String sess_accno = session.getAttribute("useracc").toString(); String accno = request.getParameter("accno"); //数据库查询时,先判断查询的账户信息是否和现登录态用户一致 if(sess_accno.equals(accno)) { Class.forName("com.mysql.jdbc.Driver"); Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/mydb", "root", ""); PreparedStatement ps = (PreparedStatement) con.prepareStatement("select * from account_balance where accno=? limit 0,1"); ps.setString(1,accno); /* This line will be better ps.setString(1,sess_accno); */ ResultSet rs = ps.executeQuery(); if(rs.next()) { String s = rs.getString("balance"); out.println("<h1>Welcome to your account</h1>"); out.println("<br>Account Number: "+session.getAttribute("useracc")); out.println("<br>Your current balance is: "+s); } else { out.println("Error: Contact administrator."); } } else { out.println("Unauthorized Access Detected"); } } else { response.sendRedirect("login.jsp"); } %> |
|
[求助]关于验证码的爆破工具
用pkav的就挺好啊http://zone.wooyun.org/content/19188?&from=androidqq |
|
网站经常被黑,麻烦各位提些防范建议,感激不尽!
1、利用破解版APPSCAN、或者Acunetix Web Vulnerability Scanner 8针对web应用层漏洞进行安全扫描,找出可能存在的漏洞,像SQL注入、上传漏洞,表单绕过等,做下加固措施; 2、如果技术较弱,开发商不愿意改,那么网上搜下软件版的web应用防火墙,预算够的话,买台web应用防火墙好了 |
操作理由
RANk
{{ user_info.golds == '' ? 0 : user_info.golds }}
雪币
{{ experience }}
课程经验
{{ score }}
学习收益
{{study_duration_fmt}}
学习时长
基本信息
荣誉称号:
{{ honorary_title }}
能力排名:
No.{{ rank_num }}
等 级:
LV{{ rank_lv-100 }}
活跃值:
在线值:
浏览人数:{{ visits }}
最近活跃:{{ last_active_time }}
注册时间:{{ user_info.create_date_jsonfmt }}
勋章
兑换勋章
证书
证书查询 >
能力值