Repository navigation
[Bug] Windows 受限令牌沙箱内 CIM/WMI 整体不可用:Get-CimInstance 及全部 CIM 派生命令(Get-NetTCPConnection / Get-NetIPAddress / Get-NetAdapter / Get-Volume)均返回"拒绝访问"(0x80041003),Get-PSDrive 静默报 0 #9272
Replies: 2 comments 2 replies
|
Thanks for the careful write-up — the environment table and the affected/unaffected split make this easy to reason about. Your priority ordering is right, and I want to reinforce the part you put first: for an agent caller the silent wrong value is worse than the explicit denial. Three source-level observations that affect where a mitigation can live. 1. The denial does not arrive on the error channel. A confined PowerShell command runs through the shell tool, whose renderer states its contract explicitly: "Non-zero exits are reported, not errored — the model decides how to react; only infrastructure failures (spawn errors, aborts) surface as Two consequences. A caller that branches on the tool's error channel never sees it — the text is just output it has to read. And a mitigation that inspects only the failure path misses the common case; it has to read the settled value's 2. Which layer denies the WMI namespace is not settled, and I would not price the "cheap fix" before it is. The Windows backend creates the confined token as 3. On ask #1, the substitute table is the right artifact. Your verified pairs are the ones I would keep:
One gap worth pinning while the report is fresh: addresses and adapters ( On the silent-value half, I would state it as a rule rather than an aside, because it is the half that produces confident wrong actions: inside the sandbox, a CIM-backed command's empty or zero result is not evidence. Disclosure. I am preparing exactly that corroboration as a diagnosis advisory in the Windows-sandbox advisor plugin ( |
|
A plugin now ships this boundary as a diagnosis, so a session hits the explanation at the moment the refusal happens.
What it hands over:
Two things it is careful about. The mechanism is documented upstream, and the advisory says so and quotes it — what the plugin adds is the just-in-time attribution plus the substitutes and the silent-shape rules the documentation does not carry, not a discovery. And it is recognition-only: it grants nothing, elevates nothing and changes no mode. On the two requests in the report: (1) is partly answered here for the agent consumer, while the user-facing README wording stays a maintainer-owned change; (2) read-only |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
前注:自动化过程中发现本问题,我觉得需要发一个report。本人并非专业程序员,可能操作有误,请见谅。本文如有问题,请大家指正。
English abstract:Inside the restricted-token sandbox on Windows, all CIM/WMI access fails with Access denied (
0x80041003):Get-CimInstancefor any class, and every CIM-backed cmdlet (Get-NetTCPConnection,Get-NetIPAddress,Get-NetAdapter,Get-Volume) reports the same error. Those commands behave correctly — they do raise an error. The real trap is silent wrong values:Get-PSDrivereports0for every drive's Used/Free (its usage figures come from a WMI query) while[System.IO.DriveInfo]returns the correct free space at the same moment; likewise the common idiom-ErrorAction SilentlyContinueturns any CIM failure into an empty result, so a caller can conclude "nothing is listening" when the query never ran. Native alternatives are unaffected:netstat -ano,Get-Process,Get-Service,[System.IO.DriveInfo],Get-Counter, and direct registry reads. Request: (1) document the CIM/WMI limitation together with the native substitutes (most valuable for agent/automation authors), (2) ideally allow read-onlyroot/cimv2queries.环境
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe)admin=False)workspace-write(read-only使用同一受限令牌,预计同样复现,未单独验证)现象
沙箱内 CIM/WMI 完全不可访问:
Get-CimInstance查询任何 WMI 类都返回拒绝访问(HRESULT0x80041003,WBEM_E_ACCESS_DENIED);所有基于 CIM 的内建命令(CDXML 型,如 NetTCPIP / NetAdapter / Storage 模块)报同一个错误。受影响 / 不受影响(全部为本机实测)
Get-CimInstance Win32_OperatingSystemGet-CimInstance Win32_LogicalDiskGet-CimInstance Win32_ComputerSystemGet-NetTCPConnection -State ListenGet-NetIPAddressGet-NetAdapterGet-VolumeGet-PSDrive -PSProvider FileSystemnetstat -anoGet-ProcessGet-Service[System.IO.DriveInfo]::new('F').AvailableFreeSpaceGet-Counter '\Memory\Available MBytes'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion最小复现(原始输出见附件日志)
补充例证:内建命令直接给出"静默的错误值"(这一例不需要调用方任何写法问题)
为什么值得修(对 Agent / 自动化尤其)
-ErrorAction SilentlyContinue在诊断脚本里几乎是条件反射(避免一行失败刷屏),一旦加上,"CIM 不可用"就变成了"没有监听端口"这类看似正常但完全错误的结论。Get-NetTCPConnection的空结果判定"两个本地语音服务都没启动",而netstat显示它们一直正常监听;Get-PSDrive也曾报出"磁盘剩余 0 GB"。所以本条不是要求改
Get-NetTCPConnection的行为(它没错),而是希望把该限制显式文档化——让调用方知道"CIM/WMI 在沙箱内不可用",从而改用下表的原生替代。期望行为(按优先级)
0x80041003)",并附上表"原生替代写法"。对 Agent 集成方价值最大。root/cimv2的只读查询,代价最小、收益最大(端口 / 磁盘 / 内存这类只读诊断即可恢复)。-ErrorAction SilentlyContinue下会静默变空、Get-PSDrive会静默报 0"这两个陷阱(属通用 PowerShell 语义,单独说明即可)。相关(既有报告:受限令牌裁剪权限的三个侧面)
附:我这边是怎么绕过去的
服务状态判断全部换成"原生 API + HTTP 健康检查":
netstat -ano(解析 LISTENING 行)/health(比看端口更可靠)Get-Process/Get-Service[System.IO.DriveInfo]Get-Counter这样在沙箱内外结论一致、且不会出现"静默错误值"。
issue草稿-GetNetTCPConnection.md
issue日志-CIM-WMI.txt
All reactions