Created
August 21, 2018 15:20
-
-
Save 0xbadjuju/2fadf943be3504069ab7d97e1af2727f to your computer and use it in GitHub Desktop.
Verify Apache Server-Status is Accessible
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add-type @" | |
using System.Net; | |
using System.Security.Cryptography.X509Certificates; | |
public class TrustAllCertsPolicy : ICertificatePolicy { | |
public bool CheckValidationResult( | |
ServicePoint srvPoint, X509Certificate certificate, | |
WebRequest request, int certificateProblem) { | |
return true; | |
} | |
} | |
"@ | |
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy | |
function Check-ServerStatus | |
{ | |
[CmdletBinding()] | |
Param( | |
[Parameter(Mandatory = $true, | |
HelpMessage = 'Input file.')] | |
[string]$file | |
) | |
$lines = Get-Content $file | |
foreach ($line in $lines) | |
{ | |
$uri = "http://$line/server-status" | |
if ($line.Contains("443")) | |
{ | |
$uri = "https://$line/server-status" | |
} | |
try | |
{ | |
$request = Invoke-WebRequest -Uri $uri | |
} | |
catch | |
{ | |
Write-Host -ForegroundColor Red "$line - Connect" | |
Out-File -Append "${file}_connect.txt" -InputObject $line | |
} | |
$title = $($request.ParsedHtml.getElementsByTagName('title')).innertext; | |
if([System.String]::IsNullOrEmpty($title)) | |
{ | |
Write-Host -ForegroundColor Red "$line - False Positive" | |
Out-File -Append "${file}_falsepositive.txt" -InputObject "$line`tFalse Positive" | |
} | |
elseif ($title -like "Apache Status") | |
{ | |
Write-Host -ForegroundColor Green "$line - Verified $title" | |
Out-File -Append "${file}_verified.txt" -InputObject "$line`tVerified`t$title" | |
} | |
else | |
{ | |
Write-Host -ForegroundColor Yellow "$line - False Positive $title" | |
Out-File -Append "${file}_falsepositive.txt" -InputObject "$line`tFalse Positive`t$title" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment