Skip to main content
Glama
sfz009900

Kali Linux MCP Server

by sfz009900

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

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

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"]
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but lacks critical behavioral details. It doesn't disclose whether this is a read/write operation, potential side effects (e.g., command execution), error conditions, or response format. The mention of 'running interactive command' implies state dependency but doesn't elaborate on session management or failure modes.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is brief but includes a parenthetical note that adds complexity without clear value. It's front-loaded with the core action but could be more streamlined by removing the ambiguous parenthetical, which doesn't earn its place in a concise tool description.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations, no output schema, and interaction with running commands (implying statefulness), the description is incomplete. It doesn't cover return values, error handling, or how it integrates with sibling tools for command lifecycle management, leaving significant gaps for an AI agent to use it effectively in context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so parameters are well-documented in the schema. The description adds no additional parameter semantics beyond implying 'input' is sent to a command and 'session_id' identifies an interactive session. This meets the baseline for high schema coverage but doesn't enhance understanding of parameter usage or constraints.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('send user input') and target ('to a running interactive command'), which is specific and actionable. However, it doesn't explicitly differentiate from sibling tools like 'execute_command' or 'get_command_output', and the parenthetical '(自行判断是AI输入还是用户手动输入)' adds some ambiguity about the source determination.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'execute_command' for non-interactive commands or 'close_interactive_command' to end sessions. It mentions 'running interactive command' but doesn't specify prerequisites or contrast with sibling tools, leaving usage context unclear.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

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