Skip to content

Commit 66e6801

Browse files
authored
Merge pull request #112 from JayRHa/security/verify-downloaded-tools
Security: verify downloaded remediation tools
2 parents bce50dd + f7b95a4 commit 66e6801

2 files changed

Lines changed: 51 additions & 7 deletions

File tree

Profile-cleanup/remediation_remediate-old-profiles.ps1

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,28 @@ Version 1.0: Init
1212
Run as: System
1313
Context: 64 Bit
1414
#>
15+
16+
function Save-VerifiedDownload {
17+
param (
18+
[Parameter(Mandatory = $true)]
19+
[string]$Uri,
20+
21+
[Parameter(Mandatory = $true)]
22+
[string]$OutFile,
23+
24+
[Parameter(Mandatory = $true)]
25+
[string]$ExpectedSha256
26+
)
27+
28+
Invoke-WebRequest -Uri $Uri -OutFile $OutFile -UseBasicParsing -ErrorAction Stop
29+
$actualHash = (Get-FileHash -Path $OutFile -Algorithm SHA256).Hash.ToLowerInvariant()
30+
31+
if ($actualHash -ne $ExpectedSha256.ToLowerInvariant()) {
32+
Remove-Item -Path $OutFile -Force -ErrorAction SilentlyContinue
33+
throw "Hash validation failed for $OutFile. Expected $ExpectedSha256, got $actualHash."
34+
}
35+
}
36+
1537
$days = 30
1638
$profiles = (get-CimInstance win32_userprofile | Where-Object {$_.LastUseTime -lt $(Get-Date).Date.AddDays(-$days)})
1739
$profilecount = $profiles.Count
@@ -22,18 +44,18 @@ $tempdir = $env:TEMP
2244
##Comment out whichever version you don't want to use
2345

2446
##Download DelProf1
25-
Invoke-WebRequest -URI "https://github.com/andrew-s-taylor/public/raw/main/delprof/delprof.exe" -OutFile "$tempdir\delprof.exe"
47+
Save-VerifiedDownload -Uri "https://github.com/andrew-s-taylor/public/raw/main/delprof/delprof.exe" -OutFile "$tempdir\delprof.exe" -ExpectedSha256 "1da35d3bc379f57de9384fef2ce8f9a29cea9f5e8a6550a5023f29f39bf327ad"
2648
##Run DelProf1
2749
Start-Process -FilePath "$tempdir\delprof.exe" -ArgumentList /Q /D:$days
2850
Remove-Item "$tempdir\delprof.exe"
2951

3052
##Download DelProf2
31-
Invoke-WebRequest -URI "https://github.com/andrew-s-taylor/public/raw/main/delprof/DelProf2.exe" -OutFile "$tempdir\delprof2.exe"
53+
Save-VerifiedDownload -Uri "https://github.com/andrew-s-taylor/public/raw/main/delprof/DelProf2.exe" -OutFile "$tempdir\delprof2.exe" -ExpectedSha256 "b456e05c6825dea9f854e3ae37deb36e7f5f2d847fc2c7f053327559a9414ed6"
3254
##Run DelProf2
3355
Start-Process -FilePath "$tempdir\delprof2.exe" -ArgumentList /q /d:$days
3456
remove-item "$tempdir\delprof2.exe"
3557

3658
}
3759
else {
3860
write-host "No old profiles to remove" -ForegroundColor Green
39-
}
61+
}

Remove Teams Chat/remediation_remediate-teams-chat.ps1

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,27 @@ Run as: User
1313
Context: 64 Bit
1414
#>
1515

16+
function Save-VerifiedDownload {
17+
param (
18+
[Parameter(Mandatory = $true)]
19+
[string]$Uri,
20+
21+
[Parameter(Mandatory = $true)]
22+
[string]$OutFile,
23+
24+
[Parameter(Mandatory = $true)]
25+
[string]$ExpectedSha256
26+
)
27+
28+
Invoke-WebRequest -Uri $Uri -OutFile $OutFile -UseBasicParsing -ErrorAction Stop
29+
$actualHash = (Get-FileHash -Path $OutFile -Algorithm SHA256).Hash.ToLowerInvariant()
30+
31+
if ($actualHash -ne $ExpectedSha256.ToLowerInvariant()) {
32+
Remove-Item -Path $OutFile -Force -ErrorAction SilentlyContinue
33+
throw "Hash validation failed for $OutFile. Expected $ExpectedSha256, got $actualHash."
34+
}
35+
}
36+
1637
#Remove Teams Chat
1738
$MSTeams = "MicrosoftTeams"
1839

@@ -29,10 +50,11 @@ If ($null -ne $ProvisionedPackage)
2950
}
3051

3152
##Tweak reg permissions
32-
invoke-webrequest -uri "https://github.com/andrew-s-taylor/public/raw/main/De-Bloat/SetACL.exe" -outfile "C:\Windows\Temp\SetACL.exe"
33-
C:\Windows\Temp\SetACL.exe -on "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Communications" -ot reg -actn setowner -ownr "n:administrators"
34-
C:\Windows\Temp\SetACL.exe -on "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Communications" -ot reg -actn ace -ace "n:administrators;p:full"
35-
Remove-Item C:\Windows\Temp\SetACL.exe -recurse
53+
$setAclPath = "C:\Windows\Temp\SetACL.exe"
54+
Save-VerifiedDownload -Uri "https://github.com/andrew-s-taylor/public/raw/main/De-Bloat/SetACL.exe" -OutFile $setAclPath -ExpectedSha256 "4efc87b7e585fcbe4eaed656d3dbadaec88beca7f92ca7f0089583b428a6b221"
55+
& $setAclPath -on "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Communications" -ot reg -actn setowner -ownr "n:administrators"
56+
& $setAclPath -on "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Communications" -ot reg -actn ace -ace "n:administrators;p:full"
57+
Remove-Item -Path $setAclPath -Force
3658

3759

3860
##Stop it coming back

0 commit comments

Comments
 (0)