| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 
 | function Invoke-SupplyChainScan {[CmdletBinding()]
 param(
 [Parameter(Mandatory=$true)]
 [string]$ScanPath,
 
 [ValidateSet('Critical','High','Medium','Low')]
 [string]$SeverityLevel = 'Critical'
 )
 
 $report = [PSCustomObject]@{
 Timestamp = Get-Date -Format 'yyyy-MM-dd HH:mm:ss'
 ScannedComponents = @()
 SecurityFindings = @()
 }
 
 
 Get-ChildItem $ScanPath -Recurse -Include *.dll,*.exe,*.psm1 | ForEach-Object {
 $fileHash = (Get-FileHash $_.FullName -Algorithm SHA256).Hash
 $signature = Get-AuthenticodeSignature $_.FullName
 
 $component = [PSCustomObject]@{
 FileName = $_.Name
 FilePath = $_.FullName
 SHA256 = $fileHash
 IsSigned = $signature.Status -eq 'Valid'
 Publisher = $signature.SignerCertificate.Subject
 }
 $report.ScannedComponents += $component
 
 if (-not $component.IsSigned) {
 $report.SecurityFindings += [PSCustomObject]@{
 Severity = 'High'
 Description = "未签名的组件: $($_.Name)"
 Recommendation = "要求供应商提供数字签名版本或验证组件来源"
 }
 }
 }
 
 
 $nugetPackages = Get-ChildItem $ScanPath -Recurse -Include packages.config
 $nugetPackages | ForEach-Object {
 [xml]$config = Get-Content $_.FullName
 $config.packages.package | ForEach-Object {
 $cveData = Invoke-RestMethod "https://api.cvecheck.org/v1/search?id=$($_.id)"
 if ($cveData.vulnerabilities | Where-Object { $_.severity -ge $SeverityLevel }) {
 $report.SecurityFindings += [PSCustomObject]@{
 Severity = $SeverityLevel
 Description = "存在漏洞的依赖包: $($_.id) v$($_.version)"
 Recommendation = "升级到最新安全版本 $($cveData.latestVersion)"
 }
 }
 }
 }
 
 $report | Export-Csv -Path "$ScanPath\SupplyChainReport_$(Get-Date -Format yyyyMMdd).csv" -NoTypeInformation
 return $report
 }
 
 |