Skip to content
WordPress

How to Use SQLMap for WordPress

· · 10 min read
How to Use SQLMap for WordPress

SQLMap is a penetration testing tool that automates finding and exploiting SQL injection vulnerabilities, and running it against a WordPress site you do not own or lack written authorization to test is illegal in most jurisdictions, full stop, regardless of intent. What follows is written for the legitimate use case: security professionals and site owners testing their own WordPress installations, or systems they have explicit written permission to assess, as part of a genuine security audit.

What SQL Injection Actually Is, and Why WordPress Specifically Cares

SQL injection happens when user-supplied input, a search box, a comment field, a URL parameter, gets passed into a database query without proper sanitization, letting an attacker manipulate the query itself rather than just supplying data for it. Done successfully, this can expose the entire WordPress database: user credentials, private post drafts, customer order data on a WooCommerce store, anything the database holds.

Modern WordPress core itself is well hardened against this class of vulnerability through its use of $wpdb’s prepared statement methods. The realistic risk on most sites lives in third-party plugins and themes, particularly older or poorly maintained ones, that build SQL queries through direct string concatenation rather than WordPress’s built-in sanitization functions. This is exactly why testing your specific site’s actual plugin and theme stack matters more than testing WordPress core in the abstract.

Setting Up a Safe Testing Environment

Never run SQLMap for the first time, or in learning mode, against a production site with real user data. Set up a local WordPress install in a VM (VirtualBox with Ubuntu is a common, well-documented combination) with a deliberately vulnerable plugin installed for practice, several security training resources maintain purpose-built vulnerable WordPress test environments specifically for this. Get comfortable with SQLMap’s output and behavior there before pointing it at anything you actually care about, even a site you own.

Installing SQLMap

SQLMap runs on Windows, macOS, and Linux, and is written in Python, so a working Python installation is a prerequisite.

On macOS or Linux, the fastest path is usually your package manager:

brew install sqlmap

Or, cross-platform, cloning directly from the project’s official repository, which also ensures you get the most current version rather than whatever your package manager last packaged:

git clone --depth 1 https://github.com/sqlmapproject/sqlmap.git sqlmap-dev
cd sqlmap-dev
python sqlmap.py --version

Windows users typically install Python first, then follow the same git clone approach, running sqlmap.py through Python directly rather than expecting a native Windows binary.

Identifying Where to Actually Point It

SQLMap needs a specific URL with a parameter to test, not just a domain. The classic vulnerable pattern is a URL with a query string parameter that gets used in a database lookup: search results pages, a post displayed by ID, a filtered archive view, a plugin’s custom AJAX endpoint that accepts an ID or search term.

Common candidate areas on a WordPress site worth checking include the native search function (?s=searchterm), any custom plugin-added search or filter functionality, comment submission endpoints, and any custom REST API routes a theme or plugin has registered that accept identifiers or search parameters.

Running a Basic Scan

Point SQLMap at a specific URL with a parameter to test:

python sqlmap.py -u "http://yoursite.local/?s=test" --batch

The `–batch` flag tells SQLMap to use default answers to its interactive prompts rather than pausing to ask you at each decision point, useful for a first quick pass, though for a thorough audit you generally want to review those prompts individually rather than accepting defaults blindly.

For form-based input rather than URL parameters, capture the POST request first (browser dev tools’ Network tab, or a proxy tool like Burp Suite, both work) and pass it to SQLMap with the `–data` flag:

python sqlmap.py -u "http://yoursite.local/wp-comments-post.php" --data="[email protected]" --batch

Testing Behind a Login

Many of the more interesting vulnerability surfaces on a WordPress site sit behind authentication, an admin-only search filter, a member-area feature. Provide session cookies so SQLMap tests as an authenticated user rather than only what an anonymous visitor can reach:

python sqlmap.py -u "http://yoursite.local/wp-admin/admin-ajax.php?action=my_plugin_search&term=test" --cookie="wordpress_logged_in_xxx=your_session_cookie" --batch

Grab the exact cookie value from your browser’s dev tools while logged in as the test account you want SQLMap to impersonate for this scan.

Reading and Interpreting the Results

A clean scan reporting no injectable parameters found is a genuinely useful, positive result, it does not mean SQLMap failed, it means that specific parameter was not vulnerable to the injection techniques SQLMap tested. It is not a guarantee the whole site is safe; it only speaks to the specific parameters and pages you actually pointed the scan at.

A positive finding shows the injectable parameter, the specific database management system detected (MySQL, in nearly all WordPress cases), and offers further enumeration options, dumping table names, column names, and eventually data, if you choose to go that far during an authorized test.

Fixing What You Find

If SQLMap confirms a vulnerable parameter, the fix lives in code, not in SQLMap itself, which is purely a detection and exploitation tool, not a remediation one.

Identify which plugin or theme owns the vulnerable code path, usually inferable from the URL or parameter name that triggered the finding. Check whether an updated version of that plugin has already patched the issue, since a meaningful share of injection vulnerabilities found by hobbyist or professional testers turn out to already be fixed in a version newer than what the site is running, an update is the fastest fix when available.

If no patched version exists, and you have development resources, the underlying code fix is switching from raw string-concatenated SQL to `$wpdb->prepare()` with properly parameterized placeholders, which is WordPress’s built-in, correct way to handle user input in database queries.

$wpdb->get_results(
    $wpdb->prepare(
        "SELECT * FROM {$wpdb->posts} WHERE post_title = %s",
        $user_input
    )
);

If neither an update nor a custom fix is immediately available, deactivating the vulnerable plugin until a fix ships is the responsible interim step, rather than leaving a confirmed, exploitable vulnerability live on a production site.

A web application firewall rule targeting the specific vulnerable parameter can serve as a temporary mitigation while a proper code fix is developed, buying time without fully removing the plugin’s functionality from the live site. This is a stopgap, not a substitute for the actual code fix, since a WAF rule protects against the specific attack pattern it was written for and can potentially be bypassed by a sufficiently determined attacker using a slightly different payload structure.

Beyond SQLMap: A Fuller Security Picture

SQL injection is one category of vulnerability among several, and SQLMap testing alone does not constitute a complete security audit. WPScan checks specifically for known, disclosed CVEs in your installed plugins, themes, and WordPress core, catching vulnerability classes SQLMap is not designed to detect at all, like cross-site scripting or broken access control.

A security plugin running continuously, Wordfence or Sucuri are the two most commonly deployed, provides ongoing monitoring and a web application firewall that can block exploitation attempts in real time, something a one-off manual SQLMap scan cannot replicate since it only represents a single point-in-time check.

Common Mistakes When Running SQLMap Against WordPress

Testing on live production without a backup. Even with `–batch` and read-only enumeration flags, unexpected interactions with a live database carry some risk. Back up before any testing session against a production or staging environment that matters.

Not acting on findings. A confirmed vulnerability sitting unaddressed in a report is worse than not testing at all in one specific sense: you now have documented knowledge of an exploitable weakness that, if that documentation itself leaks, gives an attacker a head start. Patch or deactivate the affected plugin promptly.

Assuming a clean scan means the site is fully secure. SQLMap tests for SQL injection specifically. It says nothing about weak passwords, outdated core or plugin versions vulnerable to other exploit types, misconfigured file permissions, or a dozen other categories of WordPress security risk that require different tools entirely.

Running aggressive scan levels against a shared hosting environment without checking your host’s acceptable use policy first. Some shared hosts explicitly prohibit penetration testing tools, even against your own site, because the traffic pattern can affect other tenants on the same physical server. Check your hosting agreement, or run the test against a local or dedicated environment instead.

Useful Flags Beyond the Basics

A handful of SQLMap flags come up repeatedly in real WordPress testing beyond the minimal examples above, and knowing them saves a lot of trial and error.

`–dbs` lists available databases once an injection point is confirmed, a first step before deciding what to enumerate further. `–tables -D databasename` lists tables within a specific database, letting you confirm whether WordPress’s standard table structure (wp_posts, wp_users, wp_options, and the rest) is what you would expect, or whether a plugin has introduced unexpected custom tables worth reviewing separately.

`–risk` and `–level`, both accepting a numeric scale, control how aggressive and exhaustive SQLMap’s testing is. Higher risk levels include tests more likely to affect data (not recommended on anything you cannot afford to lose without a very recent backup); higher levels test more injection points and techniques, at the cost of significantly longer scan time. Starting at the default risk and level, and only increasing deliberately if a lower setting found nothing but you have reason to suspect a vulnerability exists, is the sensible default posture.

`–technique` narrows which specific injection techniques SQLMap attempts (boolean-based blind, error-based, time-based blind, UNION-based, and others), useful for a faster, more targeted scan once you have a hypothesis about which technique is likely to apply, rather than testing every technique against every parameter by default.

Testing Custom REST API Endpoints

Modern WordPress plugins increasingly expose functionality through custom REST API routes rather than traditional admin-ajax.php calls, and these deserve specific attention since they are a newer pattern that not every plugin developer has hardened as thoroughly as older, more established code paths.

Identify custom routes by checking a site’s REST API index (yoursite.com/wp-json/) which lists registered namespaces, then testing parameters accepted by routes under any custom namespace (not the core `wp/v2` namespace, which is WordPress core’s own well-tested API) the same way you would test a traditional URL parameter or POST field.

python sqlmap.py -u "http://yoursite.local/wp-json/custom-plugin/v1/search?term=test" --batch

This is a genuinely underexplored attack surface on many WordPress sites specifically because REST API routes are relatively newer additions to the WordPress plugin ecosystem, and not every plugin author has applied the same input sanitization discipline to a REST route that they applied to older, more scrutinized admin-ajax.php handlers.

Documenting Findings for a Real Audit

If this testing is part of a formal security engagement rather than casual personal curiosity, document findings properly as you go rather than relying on SQLMap’s raw console output as your final record. For each confirmed finding, capture the exact URL and parameter tested, the specific SQLMap command and flags used to reproduce it, the plugin or theme responsible if identifiable, and a severity assessment based on what data or access the vulnerability actually exposes.

This matters for two practical reasons beyond generic best practice. First, a plugin developer receiving a vulnerability report needs enough detail to reproduce and fix the issue, a vague “SQLMap found something” report without exact reproduction steps is far less actionable and slower to get resolved. Second, if you are testing on behalf of a client rather than your own site, a clear audit trail is what actually constitutes deliverable work product, not the raw tool output itself.

Responsible Disclosure If You Find Something in a Plugin You Do Not Own

If SQLMap testing on your own site surfaces a vulnerability that traces back to a third-party plugin’s code, rather than custom code you wrote, the responsible path is reporting it to the plugin’s developer, not publishing the finding publicly before they have had a chance to patch it. Most plugin developers, and the WordPress.org plugin team for repository-hosted plugins, have a defined process for security disclosures, check the plugin’s readme or support page for a security contact before defaulting to a public support forum post, which would alert potential attackers before a fix ships.

Frequently Asked Questions

Is it legal to run SQLMap against my own WordPress site?
Yes, testing a site you own or have explicit written authorization to test is legal. Testing any site without that authorization is not, regardless of your intent or whether you plan to report findings responsibly.

Does SQLMap work against WordPress sites behind a firewall like Cloudflare?
A web application firewall can block or significantly slow SQLMap’s requests, which is one of its intended purposes. For an authorized internal security test, temporarily whitelisting your testing IP in the firewall, or testing against a staging environment without the firewall active, gives a clearer picture of the underlying application’s actual vulnerability, separate from whether the firewall happens to be catching this particular attack pattern.

How long does a thorough SQLMap scan take?
Highly variable, from seconds for a single simple parameter to hours for a comprehensive scan across many parameters with higher risk and level settings enabled. Start with a fast, basic scan to identify obvious issues before committing to a longer, more exhaustive run.

Can SQLMap damage my WordPress database?
In enumeration and detection mode, risk is low but not zero. More aggressive options, particularly anything involving data modification techniques, carry higher risk. Always test against a backed-up environment, and understand exactly what a given flag or technique does before running it against anything you cannot afford to lose.

Does a clean SQLMap scan mean I do not need a security plugin?
No. SQLMap addresses one specific vulnerability class at one point in time. A security plugin provides ongoing monitoring against a much broader range of threats, brute-force login attempts, malware scanning, firewall rules against known attack patterns, none of which SQLMap tests for or protects against. Treat SQLMap testing and a running security plugin as complementary, not substitutes for each other.

Why does SQLMap sometimes report a false positive on a WordPress site?
Certain caching layers, load balancers, or WAFs can introduce response timing variance that confuses SQLMap’s blind and time-based detection techniques specifically, since those rely on measuring response time differences to infer whether an injected condition affected the query. If a finding seems surprising given what you know about the code, manually verify it (attempt the same payload directly through a browser or a tool like curl) before treating it as confirmed, rather than trusting the automated finding alone.