PowerShell 技能连载 - 安全策略配置指南
PowerShell执行策略是脚本安全的第一道防线,通过灵活配置平衡功能与安全。
1 | # 查看当前执行策略 |
脚本签名验证
创建代码签名证书:
1
2
3
4
5
6
7$certParams = @{
Subject = 'CN=PowerShell Scripts'
Type = 'CodeSigning'
KeyUsage = 'DigitalSignature'
KeyLength = 2048
}
$cert = New-SelfSignedCertificate @certParams签名脚本文件:
1
2
3
4
5
6$signParams = @{
Certificate = $cert
FilePath = 'script.ps1'
TimestampServer = 'http://timestamp.digicert.com'
}
Set-AuthenticodeSignature @signParams
安全日志分析
1 | # 查询脚本块日志 |
最佳实践:
- 使用AllSigned策略生产环境
- 定期轮换签名证书
- 启用脚本块日志记录
- 结合AppLocker增强控制