NickstaDB/BaRMIe

GitHub: NickstaDB/BaRMIe

BaRMIe 是一款用于枚举并攻击 Java RMI 服务的命令行工具,帮助安全人员快速发现并利用不安全的远程方法。

Stars: 743 | Forks: 100

# 巴尔米埃 BaRMIe 是一个用于枚举和攻击 Java RMI(远程方法调用)服务的工具。 RMI 服务经常在缺乏足够安全控制的情况下暴露危险功能,但由于缺乏有效的测试工具,RMI 服务在安全评估中往往被忽视。2008 年 Adam Boulton 在 AppSec USA([YouTube](https://www.youtube.com/watch?v=owN9EnoLsFY))上发表演讲并发布了一些 RMI 攻击工具,但这些工具很快就消失了;即使有这些工具,成功的零知识攻击仍然依赖于在网络上进行大规模的暴力破解(约 64 位/9×10¹⁸ 种可能性)。 BaRMIe 的目标是帮助安全专业人员识别、攻击并加固不安全的 RMI 服务。通过使用来自现有软件的部分 RMI 接口,BaRMIe 可以直接与这些服务交互,而无需先在网络上对 64 位进行暴力破解。 ### 免责声明 BaRMIe 的编写旨在帮助安全专业人员在拥有事先授权的系统上识别不安全的 RMI 服务。未经授权访问计算机系统是非法的,使用 BaRMIe 必须遵守所有相关法律。违规使用可能导致被起诉。BaRMIe 的开发者不承担任何责任,也不对因本程序造成的任何误用或损害负责。 ## 使用方法 使用 BaRMIe 非常简单。运行 BaRMIe 而不带参数可获取使用信息。 ``` $ java -jar BaRMIe.jar ▄▄▄▄ ▄▄▄ ██▀███ ███▄ ▄███▓ ██▓▓█████ ▓█████▄ ▒████▄ ▓██ ▒ ██▒▓██▒▀█▀ ██▒▓██▒▓█ ▀ ▒██▒ ▄██▒██ ▀█▄ ▓██ ░▄█ ▒▓██ ▓██░▒██▒▒███ ▒██░█▀ ░██▄▄▄▄██ ▒██▀▀█▄ ▒██ ▒██ ░██░▒▓█ ▄ ░▓█ ▀█▓ ▓█ ▓██▒░██▓ ▒██▒▒██▒ ░██▒░██░░▒████▒ ░▒▓███▀▒ ▒▒ ▓▒█░░ ▒▓ ░▒▓░░ ▒░ ░ ░░▓ ░░ ▒░ ░ ▒░▒ ░ ▒ ▒▒ ░ ░▒ ░ ▒░░ ░ ░ ▒ ░ ░ ░ ░ ░ ░ ░ ▒ ░░ ░ ░ ░ ▒ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ v1.0 Java RMI enumeration tool. Written by Nicky Bloor (@NickstaDB) Warning: BaRMIe was written to aid security professionals in identifying the insecure use of RMI services on systems which the user has prior permission to attack. BaRMIe must be used in accordance with all relevant laws. Failure to do so could lead to your prosecution. The developers assume no liability and are not responsible for any misuse or damage caused by this program. Usage: BaRMIe -enum [options] [host] [port] Enumerate RMI services on the given endpoint(s). Note: if -enum is not specified, this is the default mode. BaRMIe -attack [options] [host] [port] Enumerate and attack the given target(s). Options: --threads The number of threads to use for enumeration (default 10). --timeout The timeout for blocking socket operations (default 5,000ms). --targets A file containing targets to scan. The file should contain a single host or space-separated host and port pair per line. Alternatively, all nmap output formats are supported, BaRMIe will parse nmap output for port 1099, 'rmiregistry', or 'Java RMI' services to target. Note: [host] [port] not supported when --targets is used. Reliability: A +/- system is used to indicate attack reliability as follows: [+ ]: Indicates an application-specific attack [- ]: Indicates a JRE attack [ + ]: Attack insecure methods (such as 'writeFile' without auth) [ - ]: Attack Java deserialization (i.e. Object parameters) [ +]: Does not require non-default dependencies [ -]: Non-default dependencies are required ``` 枚举模式(-enum)提取通过 RMI 注册表服务暴露的对象详细信息,并列出影响该端点的已知攻击。 攻击模式(-attack)首先枚举给定的目标,然后提供一个菜单系统,用于对 RMI 服务发起已知攻击。 可以在命令行中指定单个目标。或者,BaRMIe 可以从简单的文本文件或 nmap 输出中提取目标。 ## 攻击类型 BaRMIe 能够对 RMI 服务执行三种类型的攻击。以下是每种攻击的简要说明。更多技术细节将在近期发布在 [https://nickbloor.co.uk/](https://nickbloor.co.uk/)。此外,我在 44CON 2017 上展示了我的研究成果,幻灯片可在此处获取:[BaRMIe - Poking Java's Back Door](https://www.slideshare.net/NickBloor3/nicky-bloor-barmie-poking-javas-back-door-44con-2017)。 ### 1. 攻击不安全方法 攻击不安全 RMI 服务的第一种也是最直接的方法是直接调用不安全的远程方法。危险功能常常通过 RMI 暴露,只需获取远程对象引用并调用危险方法即可触发。以下代码是一个示例: ``` //Get a reference to the remote RMI registry service Registry reg = LocateRegistry.getRegistry(targetHost, targetPort); //Get a reference to the target RMI object Foo bar = (Foo)reg.lookup(objectName); //Call the remote executeCommand() method bar.executeCommand(cmd); ``` ### 2. 通过对象类型参数进行反序列化 某些 RMI 服务并不暴露危险功能,或实现了诸如身份验证和会话管理的安全控制。如果 RMI 服务暴露了接受任意 Object 作为参数的方法,则该方法可用作反序列化攻击的入口点。以下是此类方法的一些示例: ``` public void setOption(String name, Object value); public void addAll(List values); ``` ### 3. 通过非法方法调用进行反序列化 由于使用了序列化以及服务器对方法参数的不安全处理,任何带有非原始类型参数的方法都可能成为反序列化攻击的入口点。BaRMIe 通过使用 TCP 代理在网络层面修改方法参数,从而触发非法方法调用。以下是易受攻击方法的一些示例: ``` public void setName(String name); public Long add(Integer i1, Integer i2); public void sum(int[] values); ``` 这些方法的参数可以在方法调用通过代理时替换为反序列化负载。之所以能够进行此类攻击,是因为 Java 在反序列化之前并不会尝试验证从网络接收的远程方法参数是否与实际参数类型兼容。
标签:CI/CD 集成, CodeQL, CWE, GHAS, GitHub Advanced Security, Java RMI, Java安全, JS文件枚举, MIT 许可证, QL语言, RMI安全, VS Code 插件, Web报告查看器, 代码安全, 域名枚举, 域名枚举, 域名枚举, 安全加固, 安全评估工具, 操作系统探测, 攻击工具, 服务枚举, 本地模型, 查询库, 漏洞枚举, 网络安全, 软件供应链安全, 远程方法调用, 防御绕过, 隐私保护