Skip to main content
Glama

security.test_sqli

Test web applications for SQL injection vulnerabilities by analyzing target URLs and parameters to identify security weaknesses.

Instructions

Test for SQL injection vulnerabilities

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesTarget URL
paramNoParameter name to testid

Implementation Reference

  • The handler function that implements the 'security.test_sqli' tool. It first checks for sqlmap and uses it if available, otherwise falls back to manual SQLi payload testing with error and time-based detection. Saves findings and test results to database.
    async ({ url, param = 'id' }: any): Promise<ToolResult> => {
      try {
        // Try sqlmap first if available
        const sqlmapExists = await runCommand('which', ['sqlmap']).then(() => true).catch(() => false);
        
        if (sqlmapExists) {
          try {
            const result = await runCommand('sqlmap', [
              '-u', url,
              '-p', param,
              '--batch',
              '--risk=1',
              '--level=1',
              '--timeout=10',
            ], 60000);
            
            const vulnerable = result.stdout.includes('is vulnerable') || result.stdout.includes('injection');
            
            if (vulnerable) {
              await saveFinding({
                target: url,
                type: 'SQL Injection',
                severity: 'critical',
                description: `SQL injection vulnerability detected in parameter: ${param}`,
                payload: `sqlmap -u ${url} -p ${param}`,
                response: result.stdout.substring(0, 1000),
                timestamp: new Date(),
                score: 10,
              });
            }
            
            return formatToolResult(true, {
              tool: 'sqlmap',
              vulnerable,
              output: result.stdout,
            });
          } catch (e) {
            // Fall through to manual testing
          }
        }
    
        // Manual testing fallback
        const payloads = [
          "' OR '1'='1",
          "' AND SLEEP(5)-- ",
          "1' UNION SELECT NULL--",
          "admin'--",
        ];
    
        const results: SecurityTestResult[] = [];
        const startTime = Date.now();
    
        for (const payload of payloads) {
          try {
            const testStart = Date.now();
            const response = await axios.get(url, {
              params: { [param]: payload },
              timeout: 20000,
              validateStatus: () => true,
            });
            const testDuration = Date.now() - testStart;
    
            const body = typeof response.data === 'string' ? response.data : JSON.stringify(response.data);
            const errorIndicators = [
              'sql syntax',
              'mysql',
              'postgresql',
              'ora-',
              'sqlite',
              'database error',
            ];
            const hasError = errorIndicators.some((indicator) =>
              body.toLowerCase().includes(indicator)
            );
            const isTimeBased = payload.includes('SLEEP') && testDuration > 4000;
    
            const result: SecurityTestResult = {
              payload,
              response: {
                status: response.status,
                duration: testDuration,
                hasError,
                isTimeBased,
              },
            };
    
            if (hasError || isTimeBased) {
              result.vulnerability = 'SQL Injection';
              result.severity = 'critical';
              
              await saveFinding({
                target: url,
                type: 'SQL Injection',
                severity: 'critical',
                description: `Potential SQL injection - error indicators or time-based delay detected`,
                payload,
                response: body.substring(0, 1000),
                timestamp: new Date(),
                score: 10,
              });
            }
    
            results.push(result);
          } catch (error: any) {
            results.push({
              payload,
              error: error.message,
            });
          }
        }
    
        const sqliScore = results.some((r: any) => r.vulnerable) ? 9 : 4;
        await saveTestResult(url, 'sqli_test', true, { results }, undefined, sqliScore, param, JSON.stringify(results));
    
        return formatToolResult(true, {
          results,
          summary: {
            totalTests: payloads.length,
            potentialVulns: results.filter((r) => r.vulnerability).length,
          },
        });
      } catch (error: any) {
        await saveTestResult(url, 'sqli_test', false, null, error.message, 0, param, undefined);
        return formatToolResult(false, null, error.message);
      }
    }
  • The input schema definition for the 'security.test_sqli' tool, specifying required 'url' and optional 'param'.
    {
      description: 'Test for SQL injection vulnerabilities',
      inputSchema: {
        type: 'object',
        properties: {
          url: { type: 'string', description: 'Target URL' },
          param: { type: 'string', description: 'Parameter name to test', default: 'id' },
        },
        required: ['url'],
      },
    },
  • The registration of the 'security.test_sqli' tool using server.tool() within registerSecurityTools.
      'security.test_sqli',
      {
        description: 'Test for SQL injection vulnerabilities',
        inputSchema: {
          type: 'object',
          properties: {
            url: { type: 'string', description: 'Target URL' },
            param: { type: 'string', description: 'Parameter name to test', default: 'id' },
          },
          required: ['url'],
        },
      },
      async ({ url, param = 'id' }: any): Promise<ToolResult> => {
        try {
          // Try sqlmap first if available
          const sqlmapExists = await runCommand('which', ['sqlmap']).then(() => true).catch(() => false);
          
          if (sqlmapExists) {
            try {
              const result = await runCommand('sqlmap', [
                '-u', url,
                '-p', param,
                '--batch',
                '--risk=1',
                '--level=1',
                '--timeout=10',
              ], 60000);
              
              const vulnerable = result.stdout.includes('is vulnerable') || result.stdout.includes('injection');
              
              if (vulnerable) {
                await saveFinding({
                  target: url,
                  type: 'SQL Injection',
                  severity: 'critical',
                  description: `SQL injection vulnerability detected in parameter: ${param}`,
                  payload: `sqlmap -u ${url} -p ${param}`,
                  response: result.stdout.substring(0, 1000),
                  timestamp: new Date(),
                  score: 10,
                });
              }
              
              return formatToolResult(true, {
                tool: 'sqlmap',
                vulnerable,
                output: result.stdout,
              });
            } catch (e) {
              // Fall through to manual testing
            }
          }
    
          // Manual testing fallback
          const payloads = [
            "' OR '1'='1",
            "' AND SLEEP(5)-- ",
            "1' UNION SELECT NULL--",
            "admin'--",
          ];
    
          const results: SecurityTestResult[] = [];
          const startTime = Date.now();
    
          for (const payload of payloads) {
            try {
              const testStart = Date.now();
              const response = await axios.get(url, {
                params: { [param]: payload },
                timeout: 20000,
                validateStatus: () => true,
              });
              const testDuration = Date.now() - testStart;
    
              const body = typeof response.data === 'string' ? response.data : JSON.stringify(response.data);
              const errorIndicators = [
                'sql syntax',
                'mysql',
                'postgresql',
                'ora-',
                'sqlite',
                'database error',
              ];
              const hasError = errorIndicators.some((indicator) =>
                body.toLowerCase().includes(indicator)
              );
              const isTimeBased = payload.includes('SLEEP') && testDuration > 4000;
    
              const result: SecurityTestResult = {
                payload,
                response: {
                  status: response.status,
                  duration: testDuration,
                  hasError,
                  isTimeBased,
                },
              };
    
              if (hasError || isTimeBased) {
                result.vulnerability = 'SQL Injection';
                result.severity = 'critical';
                
                await saveFinding({
                  target: url,
                  type: 'SQL Injection',
                  severity: 'critical',
                  description: `Potential SQL injection - error indicators or time-based delay detected`,
                  payload,
                  response: body.substring(0, 1000),
                  timestamp: new Date(),
                  score: 10,
                });
              }
    
              results.push(result);
            } catch (error: any) {
              results.push({
                payload,
                error: error.message,
              });
            }
          }
    
          const sqliScore = results.some((r: any) => r.vulnerable) ? 9 : 4;
          await saveTestResult(url, 'sqli_test', true, { results }, undefined, sqliScore, param, JSON.stringify(results));
    
          return formatToolResult(true, {
            results,
            summary: {
              totalTests: payloads.length,
              potentialVulns: results.filter((r) => r.vulnerability).length,
            },
          });
        } catch (error: any) {
          await saveTestResult(url, 'sqli_test', false, null, error.message, 0, param, undefined);
          return formatToolResult(false, null, error.message);
        }
      }
    );
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool tests for SQL injection vulnerabilities but doesn't describe how it behaves—e.g., whether it performs automated scans, sends payloads, requires authentication, has rate limits, or what output to expect. This leaves critical behavioral traits unspecified for a security testing tool.

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

Conciseness5/5

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

The description is a single, efficient sentence with zero wasted words. It's front-loaded with the core purpose, making it easy to scan and understand quickly. Every word earns its place by directly stating the tool's function.

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 security testing (which involves mutation and potential side effects), no annotations, and no output schema, the description is incomplete. It lacks details on behavior, safety considerations (e.g., whether testing is passive or active), and expected results, making it inadequate for informed tool selection in a security 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?

The input schema has 100% description coverage, with clear documentation for both parameters ('url' and 'param'). The description adds no additional meaning beyond what the schema provides, such as explaining parameter interactions or testing methodologies. Since schema coverage is high, the baseline score of 3 is appropriate, as the description doesn't compensate but also doesn't detract.

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 'Test for SQL injection vulnerabilities' clearly states the tool's purpose with a specific verb ('Test') and target ('SQL injection vulnerabilities'), which is better than a tautology. However, it doesn't distinguish this tool from sibling security testing tools like security.test_auth_bypass or security.test_xss, leaving the scope vague regarding what exactly gets tested (e.g., automated scanning vs manual probing).

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. It doesn't mention prerequisites (e.g., needing a target URL), exclusions (e.g., not for non-web targets), or comparisons to sibling tools like security.test_xss for different vulnerability types. Without such context, users must infer usage from the tool name alone.

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/telmon95/VulneraMCP'

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