6

.NET SqlClient 安全漏洞 CVE-2022-41064 解讀

 1 year ago
source link: https://blog.darkthread.net/blog/cve-2022-41064/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

微軟在 11/8 公佈了 System.Data.SqlClient、Microsoft.Data.SqlClient 的安全漏洞,由於涵蓋大量 .NET 版本 (.NET Framework 到 .NET 6 都可能使用到),範圍不小,身為 .NET 開發人員,應該關注其影響及修補方式。

參考了以下文件,試著整理資訊如後。

漏洞來源及攻擊方式

漏洞發生原因是現有 SQL Client 程式庫有個 Bug,在高負載狀況下「非同步查詢(Asynchronously Executed Query)」有可能發生錯接查詢結果的狀況,亦即查詢 A 拿到查詢 B 的結果。
註:資訊有限,但 Asynchronously Executed Query 應指 ExecuteReaderAsync、ExecuteScalarAsync、ExecuteXmlReaderAsync 等非同步方法參考,同步式查詢(ExecuteReader()...)在一些狀態下也有可能受影響。(在 Github 找到相關單元測試,透過 ExecuteReader() 但不讀取內容就拋棄 Transaction Scope 方式重現)

攻擊成功條件:參考

  1. Exploiting this vulnerability requires an attacker to be within the SQL Connection Pool.
    攻擊者須位於同一 SQL Connection Pool 內 (換言之,在同一 Process 內執行)
  2. Successful exploitation of this vulnerability requires an attacker to exhaust all the threads in the thread pool.
    攻擊者需耗盡所有 Thread Pool 所有 Thread
  3. In this case, a successful attack could cause the attacker access queries from other users in the SQL Connection Pool.
    在此狀況下,攻擊者有機會存取到同 SQL Connetion Pool 其他使用者的查詢結果(撿到什麼內容屬隨機性質)

漏洞存在 Microsoft.Data.SqlClient 及 System.Data.SqlClient 眾多版本:

  • Microsoft.Data.SqlClient 1.1.3 (含)之前及 2.0.0 ~ 2.1.1
  • System.Data.SqlClient 4.8.4 (含)之前版本

而微軟也已釋出 1.1.4、2.1.2、4.8.5 修補漏洞

.NET Core / .NET 5/6 使用 dotnet add package Microsoft.Data.SqlClient --version 2.1.2dotnet add package Microsoft.Data.SqlClient --version 1.1.4dotnet add package System.Data.SqlClient --version 4.8.5 更新版本。

或直接修改 .csproj:(若專案先參照其他程式庫再間接參照 SqlClient,也需要加入 PackageReference 強制使用新版)

<Project Sdk="Microsoft.NET.Sdk.Web"> 

  <PropertyGroup> 
    <TargetFramework>net6.0</TargetFramework> 
    <Nullable>enable</Nullable> 
    <ImplicitUsings>enable</ImplicitUsings> 
  </PropertyGroup> 

  <ItemGroup> 
    <PackageReference Include="Microsoft.Data.SqlClient" Version="2.1.2" /> 
  </ItemGroup> 

</Project> 

.NET Framework 請安裝 November 2022 Security and Quality Rollup Updates for .NET Framework

以上是我的非專業解讀,歡迎大家指正補充。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK