- 浏览: 2270731 次
- 性别:
- 来自: 成都
文章分类
- 全部博客 (357)
- J2EE (49)
- JavaScript (40)
- Spring (19)
- Struts (5)
- CSS (8)
- Hibernate (16)
- Java (67)
- DWR (4)
- JSON (3)
- XFIRE (1)
- Tomcat (1)
- Ant (2)
- 设计模式 (2)
- 经典收藏 (2)
- JSP (10)
- Linux (0)
- WebLogic (11)
- myeclipse (13)
- Buffalo (4)
- 文件上传相关 (1)
- oracle (33)
- html (6)
- JSTL (3)
- SVN (2)
- GIT (1)
- 孙卫琴(Java网络编程精解) (1)
- DOM4J (2)
- Swing (1)
- AJAX (1)
- Eclipse (5)
- 日志组件 (3)
- PowerDesigner (1)
- Jquery (22)
- IT技术开发相关网址 (1)
- Nutz (1)
- 其它 (1)
- Velocity (3)
- WebService (1)
- MySql (2)
- Android (1)
- Maven (2)
- Quartz (11)
- Lucene (1)
- springsource (1)
- Junit (1)
- Activiti (0)
最新评论
-
yzlseu:
拼凑,没有营养
Activiti进阶—分配组任务 -
zhangsenhao:
非常赞!代码很清楚
SpringMVC3.0+MyIbatis3.0(分页示例) -
xiamw2000:
分页写得不对,应该是 : order by ${orderNa ...
SpringMVC3.0+MyIbatis3.0(分页示例) -
sheertewtw:
...
SpringMVC:上传与下载 -
kingtoon:
...
XSS之xssprotect
参考资料
1 跨网站脚本 http://zh.wikipedia.org/wiki/XSS
2 http://code.google.com/p/xssprotect/
一 跨网站脚本介绍
跨网站脚本(Cross-site scripting,通常简称为XSS或跨站脚本或跨站脚本攻击)是一种网站应用程序的安全漏洞攻击,是代码注入的一种。它允许恶意用户将代码注入到网页上,其他用户在观看网页时就会受到影响。这类攻击通常包含了HTML以及用户端脚本语言。
XSS攻击通常指的是通过利用网页开发时留下的漏洞,通过巧妙的方法注入恶意指令代码到网页,使用户加载并执行攻击者恶意制造的网页程序。这些恶意网页程序通常是JavaScript,但实际上也可以包括Java, VBScript, ActiveX, Flash 或者甚至是普通的HTML。攻击成功后,攻击者可能得到包括但不限于更高的权限(如执行一些操作)、私密网页内容、会话和cookie等各种内容。
二 常用的XSS攻击手段和目的
盗用 cookie ,获取敏感信息。
利用植入 Flash ,通过 crossdomain 权限设置进一步获取更高权限;或者利用Java等得到类似的操作。
利用 iframe、frame、XMLHttpRequest或上述Flash等方式,以(被攻击)用户的身份执行一些管理动作,或执行一些一般的如发微博、加好友、发私信等操作。
利用可被攻击的域受到其他域信任的特点,以受信任来源的身份请求一些平时不允许的操作,如进行不当的投票活动。
在访问量极大的一些页面上的XSS可以攻击一些小型网站,实现DDoS攻击的效果。
三 漏洞的防御和利用
避免XSS的方法之一主要是将用户所提供的内容进行过滤,许多语言都有提供对HTML的过滤:
PHP的htmlentities()或是htmlspecialchars()。
Python的cgi.escape()。
ASP的Server.HTMLEncode()。
ASP.NET的Server.HtmlEncode()或功能更强的Microsoft Anti-Cross Site Scripting Library
Java的xssprotect(Open Source Library)。
Node.js的node-validator。
四 xssprotect
在Eclipse中通过svn检出项目源地址:http://xssprotect.googlecode.com/svn/trunk/如下图
通用使用方式:http://code.google.com/p/xssprotect/wiki/HowTouse
在它的源代码中有二个类需要关注下:
BaseTestCase.java
XSSFilter.java
通过这个过滤就知道它要做什么了
上传包吧,方便
1 跨网站脚本 http://zh.wikipedia.org/wiki/XSS
2 http://code.google.com/p/xssprotect/
一 跨网站脚本介绍
跨网站脚本(Cross-site scripting,通常简称为XSS或跨站脚本或跨站脚本攻击)是一种网站应用程序的安全漏洞攻击,是代码注入的一种。它允许恶意用户将代码注入到网页上,其他用户在观看网页时就会受到影响。这类攻击通常包含了HTML以及用户端脚本语言。
XSS攻击通常指的是通过利用网页开发时留下的漏洞,通过巧妙的方法注入恶意指令代码到网页,使用户加载并执行攻击者恶意制造的网页程序。这些恶意网页程序通常是JavaScript,但实际上也可以包括Java, VBScript, ActiveX, Flash 或者甚至是普通的HTML。攻击成功后,攻击者可能得到包括但不限于更高的权限(如执行一些操作)、私密网页内容、会话和cookie等各种内容。
二 常用的XSS攻击手段和目的
盗用 cookie ,获取敏感信息。
利用植入 Flash ,通过 crossdomain 权限设置进一步获取更高权限;或者利用Java等得到类似的操作。
利用 iframe、frame、XMLHttpRequest或上述Flash等方式,以(被攻击)用户的身份执行一些管理动作,或执行一些一般的如发微博、加好友、发私信等操作。
利用可被攻击的域受到其他域信任的特点,以受信任来源的身份请求一些平时不允许的操作,如进行不当的投票活动。
在访问量极大的一些页面上的XSS可以攻击一些小型网站,实现DDoS攻击的效果。
三 漏洞的防御和利用
避免XSS的方法之一主要是将用户所提供的内容进行过滤,许多语言都有提供对HTML的过滤:
PHP的htmlentities()或是htmlspecialchars()。
Python的cgi.escape()。
ASP的Server.HTMLEncode()。
ASP.NET的Server.HtmlEncode()或功能更强的Microsoft Anti-Cross Site Scripting Library
Java的xssprotect(Open Source Library)。
Node.js的node-validator。
四 xssprotect
在Eclipse中通过svn检出项目源地址:http://xssprotect.googlecode.com/svn/trunk/如下图
通用使用方式:http://code.google.com/p/xssprotect/wiki/HowTouse
package com.xss.example; import java.io.IOException; import java.io.StringReader; import java.io.StringWriter; import com.blogspot.radialmind.html.HTMLParser; import com.blogspot.radialmind.html.HandlingException; import com.blogspot.radialmind.xss.XSSFilter; public class XSSTest { public static void main(String[] args) { String html = "<html><head> <title> New Document </title> " + "<script type='text/javascript'> alert('dddd'); </script> " + "</head> <body>" + "222 <iframe src='www.google.com'/> 1111" + "<embed ></embed>" + "<link>ddd</link>" + "</body></html>"; String v = protectAgainstXSS(html); System.out.println(v); } public static String protectAgainstXSS( String html ) { StringReader reader = new StringReader( html ); StringWriter writer = new StringWriter(); String text = null; try { // Parse incoming string from the "html" variable HTMLParser.process( reader, writer, new XSSFilter(), true ); // Return the parsed and cleaned up string text = writer.toString(); } catch (HandlingException e) { // Handle the error here in accordance with your coding policies... }finally{ try { writer.close(); reader.close(); } catch (IOException e) { e.printStackTrace(); } } return text; } }
在它的源代码中有二个类需要关注下:
BaseTestCase.java
public abstract class BaseTestCase extends TestCase { protected void testExecute( String html, String result ) { StringReader reader = new StringReader( html ); StringWriter writer = new StringWriter(); try { HTMLParser.process( reader, writer, new XSSFilter(), true ); String buffer = new String( writer.toString() ); System.out.println( buffer ); assertEquals( result, buffer ); } catch (HandlingException e) { e.printStackTrace(); fail( e.getMessage() ); } } }
XSSFilter.java
/** * Copyright 2008 Gerard Toonstra * * As an exception, this particular file * in the project is public domain to allow totally * free derivations of this code. * */ package com.blogspot.radialmind.xss; import java.util.HashSet; import java.util.Set; import com.blogspot.radialmind.html.IHTMLFilter; /** * Implementation of a relatively simple XSS filter. This implementation removes * dangerous tags and attributes from tags. It does not verify the validity of * URL's (that may contain links to JavaScript for example). It does not remove all * event handlers that may still contain XSS vulnerabilities. * * Embedded objects are removed because those may contain XSS vulnerabilities in * their own scripting language (ActionScript for Flash for example). * * Feel free to derive your own implementation from this file. * * @author gt * */ public class XSSFilter implements IHTMLFilter { private static final Set<String> FORBIDDEN_TAGS = new HashSet<String>(); // The tags to be removed. Case insensitive of course. static { FORBIDDEN_TAGS.add( "script" ); FORBIDDEN_TAGS.add( "embed" ); FORBIDDEN_TAGS.add( "object" ); FORBIDDEN_TAGS.add( "layer" ); FORBIDDEN_TAGS.add( "style" ); FORBIDDEN_TAGS.add( "meta" ); FORBIDDEN_TAGS.add( "iframe" ); FORBIDDEN_TAGS.add( "frame" ); FORBIDDEN_TAGS.add( "link" ); FORBIDDEN_TAGS.add( "import" ); FORBIDDEN_TAGS.add( "xml" ); } /** * This function is called to determine if an attribute should be filtered or not. * * @param tagName The name of the tag the attribute belongs to * @param attrName The name of the attribute to be filtered * @param attrValue The value of the attribute */ public boolean filterAttribute(String tagName, String attrName, String attrValue) { if ( attrName.toLowerCase().startsWith( "on" )) { return true; } return isScriptedAttributeValue( attrValue ); } /** * This method is called to determine if a tag should be filtered * * @param tagName The name of the tag that was parsed */ public boolean filterTag(String tagName) { if ( FORBIDDEN_TAGS.contains( tagName )) { return true; } return false; } /** * This method is called to modify attribute values, if required * * @param tagName The name of the tag the attribute belongs to * @param attrName The name of the attribute within the tag * @param attrValue The value of the attribute */ public String modifyAttributeValue(String tagName, String attrName, String attrValue) { return attrValue; } /** * This method is called to be able to modify the text of a node. * * @param tagName The name of the tag where the text is part of. * @param text The value of the text within the tagnode (within <tag>...</tag>) */ public String modifyNodeText(String tagName, String text) { return text; } /** * Private method that determines if an attribute value is scripted * (potentially loaded with an XSS attack vector). * * @param attrValue The value of the attribute * @return "true" if the attribute is scripted. "false" if not. */ private boolean isScriptedAttributeValue( String attrValue ) { attrValue = decode( attrValue ); attrValue = attrValue.trim().toLowerCase(); if ( attrValue.contains( "javascript:" )) { return true; } if ( attrValue.contains( "mocha:" )) { return true; } if ( attrValue.contains( "eval" )) { return true; } if ( attrValue.contains( "vbscript:" )) { return true; } if ( attrValue.contains( "livescript:" )) { return true; } if ( attrValue.contains( "expression(" )) { return true; } if ( attrValue.contains( "url(" )) { return true; } if ( attrValue.contains( "&{" )) { return true; } if ( attrValue.contains( "&#" )) { return true; } return false; } /** * Private method to remove control characters from the value * * @param value The value being modified * @return The value free from control characters */ private String decode( String value ) { value = value.replace("\u0000", "" ); value = value.replace("\u0001", "" ); value = value.replace("\u0002", "" ); value = value.replace("\u0003", "" ); value = value.replace("\u0004", "" ); value = value.replace("\u0005", "" ); value = value.replace("\u0006", "" ); value = value.replace("\u0007", "" ); value = value.replace("\u0008", "" ); value = value.replace("\u0009", "" ); value = value.replace("\n", "" ); value = value.replace("\u000B", "" ); value = value.replace("\u000C", "" ); value = value.replace("\r", "" ); value = value.replace("\u000E", "" ); value = value.replace("\u000F", "" ); value = value.replace("\u0010", "" ); value = value.replace("\u0011", "" ); value = value.replace("\u0012", "" ); value = value.replace("\u0013", "" ); value = value.replace("\u0014", "" ); value = value.replace("\u0015", "" ); value = value.replace("\u0016", "" ); value = value.replace("\u0017", "" ); value = value.replace("\u0018", "" ); value = value.replace("\u0019", "" ); value = value.replace("\u001A", "" ); value = value.replace("\u001B", "" ); value = value.replace("\u001C", "" ); value = value.replace("\u001D", "" ); value = value.replace("\u001E", "" ); value = value.replace("\u001F", "" ); return value; } }
通过这个过滤就知道它要做什么了
上传包吧,方便
发表评论
-
【转载】Eclipse Class Decompiler——Java反编译插件
2018-06-24 11:09 1311参见:jd-eclipse 的安装和使用(最新版的) h ... -
java json-lib & jQuery & jsonp
2016-06-30 11:31 771参考链接: 1、http://hanqunfeng.iteye ... -
Java多线程序源码
2016-06-24 15:04 9841、《Java多线程编程核心技术》源代码(高洪岩) 2、Jav ... -
Spring & Junit
2016-05-27 13:18 7121 测试基类(BaseJunit4Test) import ... -
随机分配算法(Intege)
2016-01-08 13:05 5135参考资料: http://blog.csdn.net/yaer ... -
myeclispe之图解weblogic81配置
2011-11-07 10:11 1553一 创建Weblogic81域(如下图) 注意事项:一般 ... -
Java之Thread(线程题)
2011-10-31 12:33 1941特别说明:java线程相关的参考了张孝祥老师的代码 参考资料 ... -
Java之ThreadLocal(Synchronized)
2011-10-31 10:10 2640参考资料 1 深入研究java.lang.ThreadLoca ... -
Java之synchronized,wait,notify结合运用示例
2011-10-26 11:54 5888场景一:要求二个线程各 ... -
Java之synchronized深入应用
2011-10-23 08:03 1904参考资料 1 java synchronized详解 http ... -
Java之Timer入门
2011-10-11 15:32 1647参考资料 1 java中timer用 ... -
Java之线程(匿名内部类)
2011-10-10 16:36 163571 Thread对象 Thread t = new Thr ... -
Java之线程(join)
2011-10-10 15:39 1420运用场景:多个线程之间 ... -
Java之线程(synchronized,wait(),notify(),notifyAll())
2011-10-10 15:03 3195参考资料 Java多线程入门大全(适用于有一定基础者) htt ... -
Java之线程(sleep,线程名)
2011-10-10 13:09 9673参考资料 1 Java线程:创建与启动 http://lava ... -
Java之线程入门
2011-10-10 11:11 1499参考资料 1 Java线程:概 ... -
java之表反向生成类
2011-09-23 16:41 3407环境:XP+JDK1.5+Oracle10g 注意事项 1 请 ... -
java之线程, NIO学习资料
2011-09-19 12:13 1089Concurrent In Java 6 第一部分 集合 ... -
Java之BigDecimal
2011-09-15 10:12 17941参考资料 1 java.math.BigDecimal的用法 ... -
Cannot forward a response that is already committed
2011-09-07 09:43 5534参考资料 1 Cannot forward a respons ...
相关推荐
防止XSS攻击xssProtect用到的jar包(antlr-3.0.1,antlr-runtime-3.0.1,xssProtect-0.1)
防止XSS攻击xssProtect用到的jar包(antlr-3.0.1,antlr-runtime-3.0.1,xssProtect-0.1)
防止XSS攻击的开源Java的三个jar包antlr-3.0.1.jar、antlr-runtime-3.0.1.jar、xssProtect-0.1.jar
javaweb用过滤器,用装饰设计模式对request重新包装后对前台传到后台参数进行过滤,xssprotect防止XSS攻击
xssProtect-0.1.jar 谷歌开源代码工具 、 用于XSS攻击
java过滤xss工具,xxsProtect. 根目录XSS/bin文件夹下有所有的jar包. 根目录XSS/com/start.java文件是例子. 过滤字符串中至少要有html显示标签.
谷歌开源代码工具 , 用于XSS攻击 包括测试用例及jar包 A Java library for filtering XSS attacks from user input fields
防止xss注入,有antlr-runtime和xssProtect两个jar包,及相关的filter过滤器。
包含xssProtect-0.1.jar等三个必需jar包,相关过滤器代码
工具:xss-html-filter-master的源码 书籍:XSS跨站脚本攻击剖析与防御(完整版) 所需jar: antlr-3.0.1.jar antlr-runtime-3.0.1.jar xssProtect-0.1.jar
java防止xss注入.rar 附案例及jar包
针对 XSS 攻击的解决方案,个人建议使用 xssProject 来解决这一问题。毕竟 xssProject 已经提供了很完善的过滤、处理方案,你可以通过研究他的代码来进行扩展,如果需要的话。 xssProject 所需的三个 jar 包。