T06 · System Persistence
Warning
- Location
- SKILL.md:340
- Finding
- Residual Scheduled Task and Executable Upgrade Script<![CDATA[ ## Vulnerability Details **File Location**: `SKILL.md`, lines 340-369 **Vulnerability Type**: Persistent scheduled execution artifacts **Risk Level**: Medium ### Complete Code Snippet ```powershell # C:\Users\n3186\.openclaw\upgrade-once.ps1 param([string]$Version) $ErrorActionPreference = 'Continue' $log = "$env:USERPROFILE\.openclaw\logs\upgrade-once.log" "$(Get-Date -Format o) 开始升级到 $Version" | Out-File $log -Append # 等 gateway 完全停止(最多 120s) $deadline = (Get-Date).AddSeconds(120) while ((Get-Date) -lt $deadline) { $p = Get-CimInstance Win32_Process -Filter "name='node.exe'" | Where-Object { $_.CommandLine -like '*openclaw*index.js*gateway*' } if (-not $p) { break } Start-Sleep -Seconds 3 } # 安装目标版本(gateway 已停,无 DLL 锁定) npm install -g "openclaw@$Version" *>> $log # 重启 gateway 任务 schtasks /run /tn "OpenClaw Gateway" >> $log 2>&1 "$(Get-Date -Format o) 完成" | Out-File $log -Append ``` ```powershell $st = (Get-Date).AddMinutes(2).ToString('HH:mm') schtasks /create /tn "OpenClaw Upgrade Once" ` /tr "powershell -NoProfile -ExecutionPolicy Bypass -File C:\Users\n3186\.openclaw\upgrade-once.ps1 -Version $target" ` /sc ONCE /st $st /f ``` ### Technical Analysis The Skill instructs the agent to write an executable PowerShell script and register a Windows scheduled task using `ExecutionPolicy Bypass`. The task is scheduled once, so its original purpose is consistent with completing an upgrade after the gateway process stops. However, the procedure does not delete either the task definition or the script after execution. A one-time task does not run periodically by itself, but it remains a cross-session execution artifact that can be manually invoked again. The retained task continues to reference a mutable script. Consequently, a user or process able to modify that script could cause different code to execute when the task is rerun. The `/f` option also overwrites an existing task with the same name without separately confirming ownership. ...[truncated 919 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Delete the scheduled task and upgrade script immediately after completion, including failure paths. - Put cleanup in a `finally` block or a separately guaranteed cleanup action: ```powershell try { # Perform the upgrade. } finally { schtasks /delete /tn "OpenClaw Upgrade Once" /f Remove-Item -LiteralPath $PSCommandPath -Force } ``` - Store the temporary script in a directory whose ACL permits writes only by the intended account and administrators. - Avoid `ExecutionPolicy Bypass` when a signed script or a narrower execution policy can be used. - Generate a unique task name per upgrade and verify that an existing task is owned by the expected workflow before replacing it. - Record and check the script hash before execution. - Configure the task with only the privileges required to replace the OpenClaw package and restart the gateway. ]]>
