Skip to main content
Glama

command_execution

Execute PowerShell commands on compromised systems using NTLM or password authentication for Active Directory penetration testing.

Instructions

execute powershell commands if we have pwned the user, possible to use ntlm or password for authentication

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
ipsYes
usernameYes
passwordYes
commandYes
ntlmNo
kerberosNo

Implementation Reference

  • The handler function for the 'command_execution' tool. It uses netexec smb with the '-x' flag to execute the provided PowerShell command on the target IPs using the specified authentication method (NTLM, Kerberos, or password). The @mcp.tool decorator registers the tool with MCP.
    @mcp.tool(name="command_execution",description="execute powershell commands if we have pwned the user, possible to use ntlm or password for authentication")
    def command_execution(ips:List[str],username:str,password:str,command:str,ntlm:bool=False,kerberos:bool=False):
        if (ntlm):
            return run_command(["netexec","smb"]+ips+["-u",username,"-H",password,"-x",command])
        elif(kerberos):
            return run_command(["netexec","smb"]+ips+["-u",username,"-p",password,'-k',"-x",command])
    
        else:
            return run_command(["netexec","smb"]+ips+["-u",username,"-p",password,"-x",command])
  • Helper function used by command_execution (and other tools) to execute subprocess commands safely with timeout, logging, and error handling.
    def run_command(command: List[str], timeout: int = 150,communicate:bool=False) -> Dict[str, Union[str, int, bool]]:
        try:
            logger.info(f"communicate :{communicate}")
            logger.info(f"Running command: {' '.join(command)}")
            if communicate:
                # Use Popen for interactive communication
                process = subprocess.Popen(
                    command,
                    stdout=subprocess.PIPE,
                    stderr=subprocess.PIPE,
                    stdin=subprocess.PIPE,
                    text=True
                )
                stdout, stderr = process.communicate(input="y\n", timeout=timeout)
                returncode = process.returncode
            else:
                # Use run for non-interactive commands
                result = subprocess.run(
                    command,
                    stdout=subprocess.PIPE,
                    stderr=subprocess.PIPE,
                    text=True,
                    check=True,
                    timeout=timeout
                )
                stdout = result.stdout
                stderr = result.stderr
                returncode = result.returncode
    
            logger.info(f"Command completed with return code {returncode}")
            return {
                "success": True,
                "stdout": stdout,
                "stderr": stderr,
                "returncode": returncode
            }
            
        except subprocess.CalledProcessError as e:
            logger.error(f"Command failed with return code {e.returncode}: {e.stderr}")
            return {
                "success": False,
                "stdout": e.stdout,
                "stderr": e.stderr,
                "returncode": e.returncode,
                "error": f"Command failed with return code {e.returncode}"
            }
        except subprocess.TimeoutExpired as e:
            logger.error(f"Command timed out after {timeout} seconds")
            return {
                "success": False,
                "error": f"Command timed out after {timeout} seconds"
            }
        except Exception as e:
            logger.error(f"Error running command: {str(e)}")
            return {
                "success": False,
                "error": str(e)
            }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions authentication methods (NTLM or password) and the prerequisite of having 'pwned the user', but fails to detail critical traits such as security implications, potential destructive effects, rate limits, or expected output format. This leaves significant gaps for a tool involving command execution and authentication.

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 a single sentence that is somewhat front-loaded with the core action, but it includes ambiguous phrasing like 'pwned the user' and mixes authentication details without clear structure. While concise, it could be more precise and organized to better guide the agent.

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 the complexity of a command execution tool with authentication parameters, no annotations, no output schema, and 0% schema coverage, the description is incomplete. It lacks details on prerequisites, behavioral risks, parameter interactions, and expected results, making it insufficient for safe and effective use by an AI agent.

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

Parameters2/5

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

Schema description coverage is 0%, so the description must compensate for all 6 parameters. It only vaguely references 'ntlm or password for authentication', which partially relates to the 'ntlm', 'password', and possibly 'kerberos' parameters, but ignores 'ips', 'username', and 'command'. This adds minimal meaning beyond the schema, failing to adequately explain parameter roles or usage.

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

Purpose3/5

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

The description states the tool executes PowerShell commands and mentions authentication methods (NTLM or password), which provides a basic purpose. However, it doesn't specify what 'pwned the user' means operationally or distinguish this tool from other command execution or authentication-related siblings like 'bruteforce_rid_users' or 'password_spray', making it vague in context.

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 implies usage when 'we have pwned the user' and mentions authentication options, but it lacks explicit guidance on when to use this tool versus alternatives like 'bruteforce_rid_users' for authentication or other execution tools. No exclusions or clear context for selection are provided, leaving the agent with minimal direction.

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

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/YoussefSahnoun/PentestMCP'

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