From 56fb00d16742c9bb5da83320c25b0a46e532cbf9 Mon Sep 17 00:00:00 2001 From: iserrano76 Date: Tue, 27 Feb 2024 09:32:03 +0100 Subject: [PATCH] Fix some failed tests --- Admin/Test-AMSI.ps1 | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Admin/Test-AMSI.ps1 b/Admin/Test-AMSI.ps1 index 091b1b910f..0ee219a739 100644 --- a/Admin/Test-AMSI.ps1 +++ b/Admin/Test-AMSI.ps1 @@ -197,8 +197,13 @@ begin { if ($IgnoreSSL -and ![System.Net.ServicePointManager]::ServerCertificateValidationCallback) { Enable-TrustAnyCertificateCallback } - $StringDate = (Get-Date -Format yyyyMMddhhmmss) - Invoke-WebRequest https://$Server/ecp/CSS-Test-$StringDate.js -Method POST -Headers @{ "Host" = "$Server" } -WebSession $CookieContainer + + $length = 10 + $characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.ToCharArray() + $randomString = -join ($characters | Get-Random -Count $length) + $UrlStem = "/ecp/Test-$randomString.js" + $urlRequest = "https://$Server$UrlStem" + Invoke-WebRequest -Uri $urlRequest -Method POST -Headers @{ "Host" = "$Server" } -WebSession $CookieContainer -DisableKeepAlive } catch [System.Net.WebException] { $Message = ($_.Exception.Message).ToString().Trim() $currentForegroundColor = $host.ui.RawUI.ForegroundColor @@ -224,10 +229,10 @@ begin { Write-Host "You can check your log files located in %ExchangeInstallPath%\Logging\HttpRequestFiltering\ in all server included in $Server endpoint" } $host.ui.RawUI.ForegroundColor = $currentForegroundColor - Write-Host "You should find a request for CSS-Test-$StringDate.js in the HttpRequestFiltering logs" + Write-Host "You should find a request for $UrlStem in the HttpRequestFiltering logs" if ($IsExchangeServer) { Write-Host "" - Write-Host "Looking for a request CSS-Test-$StringDate.js in the HttpRequestFiltering logs" + Write-Host "Looking for a request $UrlStem in the HttpRequestFiltering logs" $HttpRequestFilteringLogFolder = $null if ($ExchangePath) { @@ -246,7 +251,7 @@ begin { $file = Get-ChildItem $HttpRequestFilteringLogFolder -Filter "HttpRequestFiltering_*.log" | Sort-Object LastWriteTime -Descending | Select-Object -First 1 -Property * if ($file) { $found = $null - $found = $file | Get-Content | Select-String "/ecp/CSS-Test-$StringDate.js" + $found = $file | Get-Content | Select-String $UrlStem if ($found) { if ($found.Line -match "Detected") { Write-Host "We found the request Detected in HttpRequestFiltering logs: " -ForegroundColor Green