跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

windows-host-enrollment-smoke.ps1

62 行 · 5.3 KB历史下载
1#requires -Version 5.1
2[CmdletBinding()]
3param([Parameter(Mandatory)][string]$ManagerExecutable)
4$ErrorActionPreference='Stop';$ProgressPreference='SilentlyContinue'
5$identity=[Security.Principal.WindowsIdentity]::GetCurrent()
6if(([Security.Principal.WindowsPrincipal]::new($identity)).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)){throw 'Run this same-user protocol/DPAPI smoke as the ordinary host user.'}
7. (Join-Path $PSScriptRoot 'windows-host-enrollment.ps1')
8$root=Join-Path $env:TEMP ('cage-host-enrollment-'+[guid]::NewGuid().ToString('N'))
9$profile=Join-Path $root 'profile';$state=Join-Path $profile 'state';$id=[guid]::NewGuid();$vm=[guid]::NewGuid()
10$instance=Join-Path $state ('windows-'+$id.ToString('N'));$pair=Join-Path $instance 'cage-workbench/pair'
11$null=New-Item -ItemType Directory -Path $pair -Force
12$choice=@{version=1;system='windows-11';media=(Join-Path $root 'fixture.iso');sha256=('0'*64);editor_terms=$true;id=$id.ToString('D')}
13[IO.File]::WriteAllText((Join-Path $profile 'guest-install.json'),($choice|ConvertTo-Json))
14[IO.File]::WriteAllText((Join-Path $profile 'windows-install-vm.txt'),$vm.ToString('D'))
15$pipe='Cage.Enroll.'+[guid]::NewGuid().ToString('N');$worker=$null;$sender=$null;$context=$null
16try {
17 $workerArguments=@('user-enrollment','--vm-id',$vm.ToString('D'),'--host-sid',$identity.User.Value,'--profile',('"'+$profile+'"'),'--state',('"'+$state+'"'),'--installation-id',$id.ToString('D'),'--pipe',$pipe,'--parent-pid',[string]$PID)
18 $worker=Start-Process -FilePath $ManagerExecutable -ArgumentList $workerArguments -NoNewWindow -PassThru
19 $context=@{Pipe=$pipe;VMID=$vm.ToString('D');HostSID=$identity.User.Value;WorkerPID=[uint32]$worker.Id;WorkerStarted=[Cage.HostEnrollment.Native]::Started([uint32]$worker.Id);WorkerExe=[IO.Path]::GetFullPath($ManagerExecutable);OwnerPID=[uint32]$PID;OwnerStarted=[Cage.HostEnrollment.Native]::Started([uint32]$PID)}
20 Wait-CageHostEnrollment $context $worker
21 $ctxPath=Join-Path $root 'context.json';[IO.File]::WriteAllText($ctxPath,($context|ConvertTo-Json))
22 $module=Join-Path $PSScriptRoot 'windows-host-enrollment.ps1'
23 $senderPath=Join-Path $root 'sender.ps1';$result=Join-Path $root 'result.json'
24 $script=@'
25param($ContextPath,$Module,$Pair,$Result)
26$ErrorActionPreference='Stop'
27. $Module
28$ctx=Get-Content -LiteralPath $ContextPath -Raw|ConvertFrom-Json
29Start-Sleep -Milliseconds 500
30$sid='S-1-5-21-111-222-333-1001';$key=[byte[]](1..32)
31try {
32 Send-CageHostEnrollmentKey $ctx 'gui' $sid $key
33 $path=Join-Path $Pair 'pairing.dpapi';$before=(Get-FileHash -LiteralPath $path -Algorithm SHA256).Hash
34 Send-CageHostEnrollmentKey $ctx 'gui' $sid $key
35 $same=(Get-FileHash -LiteralPath $path -Algorithm SHA256).Hash -ceq $before
36 $different=$false;try{Send-CageHostEnrollmentKey $ctx 'gui' $sid ([byte[]](2..33))}catch{$different=$true}
37 $wrongSID=$false;try{Send-CageHostEnrollmentKey $ctx 'packet' 'S-1-5-21-111-222-333-1002' $key}catch{$wrongSID=$true}
38 [IO.File]::WriteAllText($Result,(@{sameCipher=$same;changedKeyRejected=$different;guestChangedRejected=$wrongSID;cipherPreserved=((Get-FileHash -LiteralPath $path).Hash -ceq $before)}|ConvertTo-Json))
39}finally{[Array]::Clear($key,0,$key.Length)}
40'@
41 [IO.File]::WriteAllText($senderPath,$script)
42 $system=Join-Path ([Environment]::GetFolderPath('System')) 'WindowsPowerShell/v1.0/powershell.exe'
43 $sender=Start-Process -FilePath $system -ArgumentList @('-NoLogo','-NoProfile','-NonInteractive','-ExecutionPolicy','Bypass','-File',('"'+$senderPath+'"'),'-ContextPath',('"'+$ctxPath+'"'),'-Module',('"'+$module+'"'),'-Pair',('"'+$pair+'"'),'-Result',('"'+$result+'"')) -NoNewWindow -PassThru
44 # This fixture deliberately uses a same-user PowerShell child. It proves
45 # kernel handle/PID binding and CurrentUser DPAPI, not alternate-admin UAC.
46 Set-CageHostEnrollmentAdmin $context $sender
47 if(!$sender.WaitForExit(30000) -or $sender.ExitCode -ne 0){throw 'The native fixture sender did not complete.'}
48 $passed=Get-Content -LiteralPath $result -Raw|ConvertFrom-Json
49 if(!$passed.sameCipher -or !$passed.changedKeyRejected -or !$passed.guestChangedRejected -or !$passed.cipherPreserved){throw 'Native enrollment mutation guards failed.'}
50 Add-Type -AssemblyName System.Security
51 $entropy=[Security.Cryptography.SHA256]::Create().ComputeHash([Text.Encoding]::UTF8.GetBytes('Cage.HyperV.v1:'+$vm.ToString('D')+':S-1-5-21-111-222-333-1001'))
52 $raw=[Security.Cryptography.ProtectedData]::Unprotect([IO.File]::ReadAllBytes((Join-Path $pair 'pairing.dpapi')),$entropy,'CurrentUser')
53 try{if(($raw -join ',') -cne (([byte[]](1..32)) -join ',')){throw 'Original user DPAPI interoperability failed.'}}finally{[Array]::Clear($raw,0,$raw.Length)}
54 if(Test-Path -LiteralPath (Join-Path $profile 'windows-guest.json')){throw 'A fixture without actual VM/GUI proof published a final profile.'}
55 Write-Output 'Native same-user enrollment/DPAPI protocol smoke passed; alternate-admin UAC and actual VM enrollment remain separate.'
56}finally {
57 if($context){try{Stop-CageHostEnrollment $context}catch{}}
58 if($sender){if(!$sender.HasExited){$sender.Kill();$sender.WaitForExit()};$sender.Dispose()}
59 if($worker){if(!$worker.WaitForExit(5000)){$worker.Kill();$worker.WaitForExit()};$worker.Dispose()}
60 # Keep this script's own result directory for evidence. No VM, account,
61 # service, guest data or user configuration was created or replaced.
62}