使用Azure Registry Container for Microsoft Defender進行專案資安修補,以CVE-2024-0057為例

使用Azure Registry Container for Microsoft Defender進行專案資安修補,以CVE-2024-0057為例

我們映像檔(images)是儲存在ACR(Azure Registry Container),在ACR有提供 Microsoft Defender 能提供我們映像檔(images)的安全性報告。

ACR Microsoft Defender 01

我們進入高風險頁面,可以看到滿滿的 CVE 清單。點開 CVE-2024-0057 詳細資訊與參考資料與有風險的映像檔(images)清單,從映像檔(images)我們就能反推出是那些專案有問題。

ACR Microsoft Defender 02
Additional information

Weakness details
CWE-IDCWE-20, CWE-269, CWE-295
Other details
Package type
Language
Vendor
nuget.packaging
Package name
nuget.packaging
Installed version
6.6.1.0, 5.11.0.0
Fixed version
6.6.2, 5.11.6
CVSS vector
CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N/E:F/RL:O/RC:C

Other references
https://nvd.nist.gov/vuln/detail/CVE-2024-0057
https://exchange.xforce.ibmcloud.com/vulnerabilities/276205
https://portal.msrc.microsoft.com/en-US/security-guidance/advisory/CVE-2024-0057
https://linux.oracle.com/security/oval/com.oracle.elsa-all.xml.bz2
https://access.redhat.com/security/data/oval/v2/RHEL9/rhel-9-including-unpatched.oval.xml.bz2

我們用額外資訊來說明接來下的動作。我們瞭解到,這是我們專案裡使用到一個舊版的 nuget.packaging,由它提供的資訊,只需要套件升級就能解決此 CVE-2024-0057 的問題。

nuget.packaging 套件升級

原以為故事是打開專案,點擊 NuGet 升級就結束,結果是這樣,也不是這樣。因此有這篇文章出現。

開啟 Manage NuGet Packages 之後,你在 Updates 的清單裡會發現,找不到 nuget.packaging 的套件資訊(這句不準,請往下看)。就算開啟 .csproj 專案檔也一樣。追了一陣子,發現這個 nuget.packaging 套件的設定被寫在 <projectname>.deps.json

進入 Pod 查詢,找到問題點。但要怎麼修正它呢?

# cat <projectname>.deps.json | grep 'nuget'
      "path": "nuget.common/6.6.1",
      "hashPath": "nuget.common.6.6.1.nupkg.sha512"
      "path": "nuget.configuration/6.6.1",
      "hashPath": "nuget.configuration.6.6.1.nupkg.sha512"
      "path": "nuget.dependencyresolver.core/6.6.1",
      "hashPath": "nuget.dependencyresolver.core.6.6.1.nupkg.sha512"
      "path": "nuget.frameworks/6.6.1",
      "hashPath": "nuget.frameworks.6.6.1.nupkg.sha512"
      "path": "nuget.librarymodel/6.6.1",
      "hashPath": "nuget.librarymodel.6.6.1.nupkg.sha512"
      "path": "nuget.packaging/6.6.1",
      "hashPath": "nuget.packaging.6.6.1.nupkg.sha512"
      "path": "nuget.projectmodel/6.6.1",
      "hashPath": "nuget.projectmodel.6.6.1.nupkg.sha512"
      "path": "nuget.protocol/6.6.1",
      "hashPath": "nuget.protocol.6.6.1.nupkg.sha512"
      "path": "nuget.versioning/6.6.1",
      "hashPath": "nuget.versioning.6.6.1.nupkg.sha512"

這是建置(Build)動態產生的設定檔,我翻遍了專案檔,沒有任何設定 .deps.json 套件版本的地方,因此轉頭往 CI 與 CI Server 去查。原以為是安裝 dotnet SDK 舊了,因此採用到舊版的 nuget.packaging (我一直被 nuget 這個字誤導),因此將 CI Server 的 dotnet SDK 升級至最新版。升級建置之後,還是一樣用舊版 nuget.packaging

就在無計可施時,隨意亂拉的情況下,看到了關鍵字:

VisualStudio Transitive Packages

瞭解過後,這是 Visual Studio 17.3 就提供的功能 Transitive Dependencies,它能幫忙你分析相依套件。也就是從 NetFramework 升級到 dotnet 後,有大量的套件解偶(decoupling),但也造成一個主套件需要參考大量的子套件。

讓我們把滑鼠移過去,主要套件就出現了:

VisualStudio TransitivePackages Nuget.Packaging

雖然方便,但那個清單實在有夠長,其實 Visual Studio 有貼心想到:

VisualStudio Nuget ShowOnlyVulnerable

也就是說,現在新版的 Visual Studio 的 NuGet 會很貼心幫你顯示風險的套件(多一個黃色三角驚嘆號),你應該時時注意並升級有風險的套件。

將主套件升級重新建置與部署後,重新查詢專案 Pod,nuget.packaging 套件終於被升級了。

# cat <projectname>.deps.json | grep 'nuget'
      "path": "nuget.common/6.9.1",
      "hashPath": "nuget.common.6.9.1.nupkg.sha512"
      "path": "nuget.configuration/6.9.1",
      "hashPath": "nuget.configuration.6.9.1.nupkg.sha512"
      "path": "nuget.dependencyresolver.core/6.9.1",
      "hashPath": "nuget.dependencyresolver.core.6.9.1.nupkg.sha512"
      "path": "nuget.frameworks/6.9.1",
      "hashPath": "nuget.frameworks.6.9.1.nupkg.sha512"
      "path": "nuget.librarymodel/6.9.1",
      "hashPath": "nuget.librarymodel.6.9.1.nupkg.sha512"
      "path": "nuget.packaging/6.9.1",
      "hashPath": "nuget.packaging.6.9.1.nupkg.sha512"
      "path": "nuget.projectmodel/6.9.1",
      "hashPath": "nuget.projectmodel.6.9.1.nupkg.sha512"
      "path": "nuget.protocol/6.9.1",
      "hashPath": "nuget.protocol.6.9.1.nupkg.sha512"
      "path": "nuget.versioning/6.9.1",
      "hashPath": "nuget.versioning.6.9.1.nupkg.sha512"

這裡查 Pod 比較快是因為 Azure 的掃瞄不是即時的,會有時間差,因此我直接看跑起來的容器最快最準。

相較於其他資安議題,單純升級套件就能幫專案資安加分,何樂而不為。以後把消滅黃色三角驚嘆號也當成開發流程的一環,絕是是值得推廣的好習慣。

沒有留言:

張貼留言

感謝您的留言,如果我的文章你喜歡或對你有幫助,按個「讚」或「分享」它,我會很高興的。