赞
踩
最近阿里云发了漏洞短信,需要在已有的老项目中修复shiro远程命令执行漏洞,并修复了2套Java项目,不同项目修复方式有所不同,特写此篇博客,以作备忘,欢迎大家留言讨论。
漏洞名称:
远程命令执行,利用漏洞能够获取系统权限,查看、篡改系统数据,构成信息泄露和运行安全风险
针对远程命令执行漏洞,升级Shiro至最新版本,并且重新生成一个新的秘钥替换ciperKey,保证唯一且不要泄密;
shiro需要升级到1.7.1
shiro1.7.1的spring相关jar要求在4.0版本以上
spring4.0以上版本要求jdk1.8.0以上
原有版本是1.3.1升级至最新版本1.7.1,坐标如下。
<dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-core</artifactId> <!--<version>1.3.1</version>--> <version>1.7.1</version> </dependency> <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-spring</artifactId> <!--<version>1.3.1</version>--> <version>1.7.1</version> </dependency> <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-ehcache</artifactId> <!--<version>1.3.1</version>--> <version>1.7.1</version> </dependency> <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-web</artifactId> <!--<version>1.3.1</version>--> <version>1.7.1</version> </dependency> <dependency> <groupId>org.owasp.encoder</groupId> <artifactId>encoder</artifactId> <version>1.2.2</version> </dependency> <dependency> <groupId>net.sf.ehcache</groupId> <artifactId>ehcache</artifactId> <version>2.10.3</version> </dependency>
修改默认秘钥为随机秘钥并修改shiro配置
@Bean(name="rememberMeManager") public RememberMeManager rememberMeManager() { CookieRememberMeManager cookieRememberMeManager = new CookieRememberMeManager(); cookieRememberMeManager.setCookie(rememberMeCookie()); cookieRememberMeManager.setCipherKey(Base64.decode(generateNewKey())); return cookieRememberMeManager; } @Bean(name="rememberMeCookie") public Cookie rememberMeCookie() { SimpleCookie cookie = new SimpleCookie("rememberMe"); cookie.setMaxAge(1209600); return cookie; } //随机秘钥生成 public static byte[] generateNewKey() { KeyGenerator kg; try { kg = KeyGenerator.getInstance("AES"); } catch (NoSuchAlgorithmException var5) { String msg = "Unable to acquire AES algorithm. This is required to function."; throw new IllegalStateException(msg, var5); } kg.init(128); SecretKey key = kg.generateKey(); byte[] encoded = key.getEncoded(); return encoded; }
默认为kPH+bIxk5D2deZiIxcaaaA==,成功
【现象】 java.lang.UnsupportedClassVersionError: org/apache/shiro/crypto/AbstractSymmetricCipherService : Unsupported major.minor version 52.0 at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:800) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:449) at java.net.URLClassLoader.access$100(URLClassLoader.java:71) at java.net.URLClassLoader$1.run(URLClassLoader.java:361) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:358) 【解决方法】JDK更换为JDK1.8
详细描述如下:
当改变了jdk版本时,在编译java时,会遇到Unsupported major.minor version错误。
jdk版本和stanford parser对应关系
JDK版本和Java编译器内部的版本号
J2SE 8 = 52,
J2SE 7 = 51,
J2SE 6.0 = 50,
J2SE 5.0 = 49,
JDK 1.4 = 48,
JDK 1.3 = 47,
JDK 1.2 = 46,
JDK 1.1 = 45
【解决方法】
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
修改为:
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
【现象】
java.lang.NoClassDefFoundError: org/owasp/encoder/Encode
org.apache.shiro.web.filter.PathMatchingFilter.pathsMatch(PathMatchingFilter.java:134)
org.apache.shiro.web.filter.PathMatchingFilter.preHandle(PathMatchingFilter.java:186)
org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:131)
org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:4
【解决方法】
添加 encoder-1.2.2.jar
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。