← 返回
安全合规 中文

Windows

Windows-specific patterns, security practices, and operational traps that cause silent failures.
"你好!有什么我可以帮助你的吗?无论是学习、工作还是生活中的问题,都可以随时告诉我 😊"
ivangdavila
安全合规 clawhub v1.0.0 1 版本 100000 Key: 无需
★ 2
Stars
📥 2,435
下载
💾 74
安装
1
版本
#latest

概述

Credential Management

  • Never hardcode passwords in scripts — use Windows Credential Manager:

```powershell

# Store

cmdkey /generic:"MyService" /user:"admin" /pass:"secret"

# Retrieve in script

$cred = Get-StoredCredential -Target "MyService"

```

  • For scripts, use Get-Credential and export securely:

```powershell

$cred | Export-Clixml -Path "cred.xml" # Encrypted to current user/machine

$cred = Import-Clixml -Path "cred.xml"

```

Silent Failures

  • Windows Defender silently quarantines downloaded scripts/executables — check quarantine if script disappears
  • Group Policy overrides local settings silently — gpresult /r to see what's actually applied
  • Antivirus real-time scanning blocks file operations intermittently — add exclusions for build/automation folders
  • PowerShell -ErrorAction SilentlyContinue hides problems — use Stop and handle explicitly

Symbolic Links

  • Creating symlinks requires admin OR SeCreateSymbolicLinkPrivilege — regular users fail silently
  • Enable Developer Mode for symlinks without admin: Settings → For Developers → Developer Mode
  • mklink is CMD-only, PowerShell uses New-Item -ItemType SymbolicLink

Script Signing

  • Unsigned scripts fail on restricted machines with confusing errors — sign for production:

```powershell

$cert = Get-ChildItem Cert:\CurrentUser\My -CodeSigningCert

Set-AuthenticodeSignature -FilePath script.ps1 -Certificate $cert

```

  • AllSigned policy requires ALL scripts signed including profile.ps1

Operational Safety

  • Always -WhatIf first on destructive operations — Remove-Item -Recurse -WhatIf
  • Start-Transcript for audit trail — forgotten until incident investigation
  • NTFS permissions: icacls for CLI, but inheritance rules are non-obvious — test changes on copy first

WinRM Remoting

  • Enable correctly: Enable-PSRemoting -Force isn't enough on workgroups
  • Workgroup machines need TrustedHosts: Set-Item WSMan:\localhost\Client\TrustedHosts -Value "server1,server2"
  • HTTPS remoting needs certificate setup — HTTP sends credentials readable on network

Event Logging

  • Scripts should log to Windows Event Log for centralized monitoring:

```powershell

New-EventLog -LogName Application -Source "MyScript" -ErrorAction SilentlyContinue

Write-EventLog -LogName Application -Source "MyScript" -EventId 1000 -Message "Started"

```

  • Custom event sources require admin to create — create during install, not runtime

File Locking

  • Windows locks files aggressively — test file access before operations:

```powershell

try { [IO.File]::OpenWrite($path).Close(); $true } catch { $false }

```

  • Scheduled tasks writing to same file as user → conflicts. Use unique temp files and atomic rename

Temp File Hygiene

  • $env:TEMP fills silently — scripts should cleanup with try/finally:

```powershell

$tmp = New-TemporaryFile

try { ... } finally { Remove-Item $tmp -Force }

```

  • Orphaned temp files accumulate across reboots — unlike Linux /tmp

Service Account Gotchas

  • Services run in different user context — $env:USERPROFILE points to system profile, not user's
  • Network access from SYSTEM account uses machine credentials — may fail where user succeeds
  • Mapped drives don't exist for services — use UNC paths \\server\share

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-03-28 22:08 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

ai-intelligence

Self-Improving + Proactive Agent

ivangdavila
自我反思+自我批评+自我学习+自组织记忆。智能体评估自身工作、发现错误并持续改进。
★ 1,354 📥 317,991
security-compliance

Skill Vetter

spclaudehome
AI智能体技能安全预审工具。安装ClawdHub、GitHub等来源技能前,检查风险信号、权限范围及可疑模式。
★ 1,213 📥 266,390
productivity

Word / DOCX

ivangdavila
创建、检查和编辑 Microsoft Word 文档及 DOCX 文件,支持样式、编号、修订记录、表格、分节符及兼容性检查等功能。
★ 438 📥 147,440