JBoss安全之jmx-console控制台未授权访问漏洞

   

      近期工作用到了jmx-console,顺便整理下Jboss的Jmx-console密码访问相关的知识与配置。

       MBean就是一种规范的JavaBean,通过集成和实现一套标准的Bean接口,这种叫MBean,Mbean注册到MBeanServer中。之后将被MBeanServer中注册过的Adapter(比如渲染为HTML的HtmlAdapter)渲染为直观的页面将MBean的属性和方法展示给用户。

       MBean  ->  MBeanServer -> HtmlAdapter

       以上这套架构有一个专业的名词描述:JMX,全称为Java Management Extensions,JMX是一个为应用程序、设备、系统等植入管理功能的框架,JBoss提供了其JMX的管理平台jmx-console, 通过jmx-console可以很直观了解JBoss的运行情况,例如线程池信息,线程栈信息,内存信息等. 例如:

内存情况

线程栈:

       JBoss不仅提供了线程内存的信息,还有一些MBean会对Jboss系统产生影响,默认情况下, JBoss启动后可以通过访问 http://localhost:8080/jmx-console 浏览jboss的部署管理的一些信息以及一些自定义的JMX服务,不需要输入用户名和密码,那么有心人知道服务器的IP和端口后就可以访问Jboss的Jmx-console通过Mbean攻击服务器,影响服务器运行甚至宕机。

为解决上述问题,需要对Jmx-console增加用户名密码验证,通过身份识别的方式保证Jboss 安全 。

1.启用密码管理

修改jboss-4.2.3.GA\\server\default\deploy\jmx-console.war\WEB-INF\jboss-web.xml,不再注释security-domain节点

<jboss-web>
   <!-- Uncomment the security-domain to enable security. You will
      need to edit the htmladaptor login configuration to setup the
      login modules used to authentication users.
	     -->
      <security-domain>java:/jaas/jmx-console</security-domain>
</jboss-web>

修改jboss-4.2.3.GA\\server\default\deploy\jmx-console.war\WEB-INF\web.xml,不再注释security-constraint节点,从配置中我们可以看到需要的角色是JBossAdmin

   <!-- A security constraint that restricts access to the HTML JMX console
   to users with the role JBossAdmin. Edit the roles to what you want and
   uncomment the WEB-INF/jboss-web.xml/security-domain element to enable
   secured access to the HTML JMX console.
      -->
   <security-constraint>
     <web-resource-collection>
       <web-resource-name>HtmlAdaptor</web-resource-name>
       <description>An example security config that only allows users with the
         role JBossAdmin to access the HTML JMX console web application
       </description>
       <url-pattern>/*</url-pattern>
       <http-method>GET</http-method>
       <http-method>POST</http-method>
     </web-resource-collection>
     <auth-constraint>
       <role-name>JBossAdmin</role-name>
     </auth-constraint>
   </security-constraint>

 2.设置密码

修改jboss-4.2.3.GA\server\default\conf\login-config.xml文件 ,通过下面的配置我们可以知道,登录用户和角色在下面的两个文件中设置

 <!-- A template configuration for the jmx-console web application. This
      defaults to the UsersRolesLoginModule the same as other and should be
      changed to a stronger authentication mechanism as required.
    -->
    <application-policy name = "jmx-console">
       <authentication>
          <login-module code="org.jboss.security.auth.spi.UsersRolesLoginModule"
             flag = "required">
           <module-option name="usersProperties">props/jmx-console-users.properties</module-option>
           <module-option name="rolesProperties">props/jmx-console-roles.properties</module-option>
          </login-module>
       </authentication>
    </application-policy>

修改jboss-4.2.3.GA\server\default\conf\props\jmx-console-roles.properties设置用户角色,系统默认设置了 admin的角色,可以根据自己需要设置角色,这里必须要设置JBossAdmin

# A sample roles.properties file for use with the UsersRolesLoginModule
admin=JBossAdmin,HttpInvoker
user=JBossAdmin,HttpInvoker

修改jboss-4.2.3.GA\server\default\conf\props\jmx-console-users.properties设置用户密码,该文件定义的格式为:用户名=角色,多个角色以“,”隔开 ,系统默认定义了用户名和密码都是 admin的用户, 可以通过修改添加新用户,例如添加一个用户user,登录密码为123456,

# A sample users.properties file for use with the UsersRolesLoginModule
admin=admin
user=123456

3.验证修改结果

再次访问http://localhost:8080/jmx-console ,发现此时已经不能直接访问, 输入用户user密码123456后才可以访问成功

   

上一篇:实现JBOSS 数据源配置以及密码加密

Guess you like

Origin blog.csdn.net/Beijing_L/article/details/121096519