Skip to main content
Glama

send_input_to_command

Send user input to an active interactive command session in Kali Linux MCP Server for penetration testing, enabling input injection during operations like SQL injection or command execution.

Instructions

(自行判断是AI输入还是用户手动输入)向正在运行的交互式命令发送用户输入。

Input Schema

NameRequiredDescriptionDefault
end_lineNo是否在输入后添加换行符。默认为true。
inputYes发送给命令的输入文本。
session_idYes交互式会话ID。

Input Schema (JSON Schema)

{ "properties": { "end_line": { "description": "是否在输入后添加换行符。默认为true。", "type": "boolean" }, "input": { "description": "发送给命令的输入文本。", "type": "string" }, "session_id": { "description": "交互式会话ID。", "type": "string" } }, "required": [ "session_id", "input" ], "type": "object" }

Implementation Reference

  • The main handler logic for the 'send_input_to_command' tool. It retrieves the interactive session by ID, writes the provided input (with optional newline), waits for the command to process and return to input prompt via event listener or timeout, extracts new output, and returns it along with status.
    case "send_input_to_command": { const sessionId = String(request.params.arguments?.session_id); const input = String(request.params.arguments?.input); const endLine = request.params.arguments?.end_line !== false; // 默认为true if (!sessionId || input === undefined) { throw new McpError(ErrorCode.InvalidParams, "会话ID和输入是必需的"); } const session = activeSessions.get(sessionId); if (!session) { throw new McpError(ErrorCode.InvalidParams, `找不到会话ID: ${sessionId}`); } try { log.info(`向会话 ${sessionId} 发送输入: ${input}`); // 检查当前命令是否包含msf且输入为exit if ((global as any).currentInteractiveCommand.includes('msf') && input.trim() === 'exit') { log.info(`检测到用户退出msfconsole命令`); (global as any).currentInteractiveCommand = 'exit'; } // 记录输入前的输出长度 const beforeLength = session.stdout.length; // 发送输入,根据需要添加换行符 session.write(endLine ? `${input}\n` : input); // 等待命令执行完成并出现输入提示 const maxWaitTime = 3000000; // 较长等待时间(50分钟) // 使用Promise等待输入状态变为true await new Promise<void>((resolve, reject) => { // 如果已经是等待输入状态,立即解析 if (session.isWaitingForInput) { resolve(); return; } // 等待"waiting-for-input"事件 const waitHandler = () => { clearTimeout(timeoutId); resolve(); }; // 设置超时 const timeoutId = setTimeout(() => { session.removeListener('waiting-for-input', waitHandler); log.info(`等待输入提示超时,已等待${maxWaitTime}毫秒`); // 即使超时,也返回当前状态 resolve(); }, maxWaitTime); // 添加事件监听器 session.once('waiting-for-input', waitHandler); // 添加错误处理 session.once('error', (err) => { clearTimeout(timeoutId); session.removeListener('waiting-for-input', waitHandler); reject(err); }); // 添加关闭处理 session.once('close', () => { clearTimeout(timeoutId); session.removeListener('waiting-for-input', waitHandler); resolve(); // 会话已关闭,直接返回 }); }); // 获取新输出,从上次输出的位置开始 if (!(session as any).lastOutputPosition) { (session as any).lastOutputPosition = beforeLength; } const newOutput = session.stdout.substring((session as any).lastOutputPosition); // 更新上次输出位置 (session as any).lastOutputPosition = session.stdout.length; log.info(`命令执行完成,等待输入状态: ${session.isWaitingForInput}, 新输出长度: ${newOutput.length}`); return { content: [{ type: "text", text: JSON.stringify({ status: "success", new_output: stripAnsiCodes(newOutput), waiting_for_input: session.isWaitingForInput }) }] }; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); log.error(`向会话发送输入失败: ${errorMessage}`); throw new McpError( ErrorCode.InternalError, `无法发送输入到会话: ${errorMessage}` ); } }
  • src/index.ts:104-125 (registration)
    Tool registration entry returned by listTools, including name, description, and input schema definition.
    { name: "send_input_to_command", description: "(自行判断是AI输入还是用户手动输入)向正在运行的交互式命令发送用户输入。", inputSchema: { type: "object", properties: { session_id: { type: "string", description: "交互式会话ID。" }, input: { type: "string", description: "发送给命令的输入文本。" }, end_line: { type: "boolean", description: "是否在输入后添加换行符。默认为true。" } }, required: ["session_id", "input"] } },
  • Input schema definition for the send_input_to_command tool, specifying session_id, input, and optional end_line parameters.
    inputSchema: { type: "object", properties: { session_id: { type: "string", description: "交互式会话ID。" }, input: { type: "string", description: "发送给命令的输入文本。" }, end_line: { type: "boolean", description: "是否在输入后添加换行符。默认为true。" } }, required: ["session_id", "input"]

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/sfz009900/kalilinuxmcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server