Pastebin
API
tools
faq
paste
Login
Sign up
Please fix the following errors:
New Paste
Syntax Highlighting
#This is a combination of the two scripts credited below, I simply integrated some reporting logic. #Credits: #Boe Prox - https://mcpmag.com/articles/2014/11/04/expiring-certs-in-powershell.aspx #This guy - https://iamoffthebus.wordpress.com/2014/02/04/powershell-to-get-remote-websites-ssl-certificate-expiration/ #Check to see if existing results file exists, if so, delete. $checkrep = Test-Path ".\sslresults.txt" If ($checkrep -like "True") { Remove-Item ".\sslresults.txt" } New-Item ".\sslresults.txt" -type file #Script variables to determine expiration threshold, the number of milliseconds before moving onto the next URL, and the input file $minimumCertAgeDays = 60 $timeoutMilliseconds = 10000 $urls = Get-Content .\sslurl.txt #Primary script function [Net.ServicePointManager]::ServerCertificateValidationCallback = {$true} foreach ($url in $urls) { Write-Host Checking $url -f Red $req = [Net.HttpWebRequest]::Create($url) $req.Timeout = $timeoutMilliseconds try {$req.GetResponse() |Out-Null} catch { Write-Host Exception while checking URL $url`: $_ -f Red} [datetime]$expiration = $req.ServicePoint.Certificate.GetExpirationDateString() [int]$certExpiresIn = ($expiration - $(get-date)).Days $certName = $req.ServicePoint.Certificate.GetName() $certPublicKeyString = $req.ServicePoint.Certificate.GetPublicKeyString() $certSerialNumber = $req.ServicePoint.Certificate.GetSerialNumberString() $certThumbprint = $req.ServicePoint.Certificate.GetCertHashString() $certEffectiveDate = $req.ServicePoint.Certificate.GetEffectiveDateString() $certIssuer = $req.ServicePoint.Certificate.GetIssuerName() ##Report Logic #If the URL does not exist, it will return a value to the script saying that -736010 days remain. This logic specifically marks that item and moves on. if ($certExpiresIn -le -736010) { {Write-Host $url does not exist. -f Yellow} $output = "$url does not exist or is not responding.`r`n" Out-File -filepath .\sslresults.txt -inputobject $output -encoding ASCII -width 50 -Append } #If the URL is less than the number of acceptable expiration days but more than 0, the script will send a warning. if ($certExpiresIn -le $minimumCertAgeDays -and $certExpiresIn -gt 0) { {Write-Host Cert for site $url expires in $certExpiresIn days [on $expiration] -f Green} $output = "Notice - CERTIFICATE EXPIRING SOON - Cert for site $url expires in $certExpiresIn days [on $expiration]. Threshold is $minimumCertAgeDays days.`r`n" Out-File -filepath .\sslresults.txt -inputobject $output -encoding ASCII -width 50 -Append } #If the URL has expired (less than 0 days remaining), the script will flag accordingly. if ($certExpiresIn -lt 0 -and $certExpiresIn -gt -730160) { {Write-Host Cert for site $url expires in $certExpiresIn days [on $expiration] -f Green} $output = "**EXPIRED CERTIFICATE DETECTED** - Cert for site $url expires in $certExpiresIn days [on $expiration]. Threshold is $minimumCertAgeDays days.`r`n" Out-File -filepath .\sslresults.txt -inputobject $output -encoding ASCII -width 50 -Append } #If the cert is above the threshold, the script will not write to the file. else {Write-Host Cert for site $url expires in $certExpiresIn days [on $expiration] -f Green} #Uncomment this section for a full report that will show current, unexpired certificates# # $output = "Cert for site $url expires in $certExpiresIn days [on $expiration].`r`n" # Out-File -filepath .\sslresults.txt -inputobject $output -encoding ASCII -width 50 -Append rv req rv expiration rv certExpiresIn } Function Get-PKICertificates { [cmdletbinding( DefaultParameterSetName = 'PKI' )] param( [Parameter( Mandatory = $False, ParameterSetName = '', HelpMessage = "Computer to query certificates.", ValueFromPipeline = $True)] [string[]]$Computer = $Env:Computername, [Parameter( ParameterSetName = '', HelpMessage = "Acceptable values are 'LocalMachine','CurrentUser'. ` CurrentUser can only be access on local machine. LocalMachine can be accessed on local or remote machine.", ValueFromPipeline = $False)] [string][ValidateSet("LocalMachine","CurrentUser")] $StoreLocation = "LocalMachine", [Parameter( ParameterSetName = '', HelpMessage = "Acceptable values are 'AddressBook','AuthRoot','CertificateAuthority','Disallowed','My',` 'Root','TrustedPeople','TrustedPublisher'", ValueFromPipeline = $False)] [string][ValidateSet("AddressBook","AuthRoot","CA","Disallowed","My","Root","TrustedPeople","TrustedPublisher")] $StoreName = "My", [Parameter( Mandatory = $False, ParameterSetName = '', HelpMessage = "Acceptable values are 'ReadOnly','ReadWrite','MaxAllowed','OpenExistingOnly','IncludeArchived'", ValueFromPipeline = $False)] [string][ValidateSet("ReadOnly","ReadWrite","MaxAllowed","OpenExistingOnly","IncludeArchived")]$OpenFlag = "ReadOnly", [Parameter( Mandatory = $False, ParameterSetName = 'Expired', HelpMessage = "Show expired certificates", ValueFromPipeline = $False)] [switch]$ListExpired, [Parameter( Mandatory = $False, ParameterSetName = 'Expiring', HelpMessage = "Enter a number to list certificates expiring in given number of days", ValueFromPipeline = $False)] [Int32]$ExpiresIn ) Begin { #Create variable that holds the OpenFlags object Write-Verbose "Setting the OpenFlag variable" $ro=[System.Security.Cryptography.X509Certificates.OpenFlags]"$OpenFlag" #Create variable that holds the Store Location object Write-Verbose "Setting the Store Location variable" $cu=[System.Security.Cryptography.X509Certificates.StoreLocation]"$StoreLocation" } Process { ForEach ($c in $computer) { Try { #Check to see if computer is remote or local Write-Verbose "Checking to see if computer is local or remote." If ($Env:Computername -ne $c) { Write-Verbose "Computer is remote, verifying network connection" If (!(Test-Connection -ComputerName $c -Count 1 -Quiet)) { Write-Verbose "$($c): Unable to locate computer" Continue } Else { If ($StoreLocation -eq "CurrentUser") { Write-Verbose "Attempting to access Remote Computer with CurrentUser store name." Write-Verbose "Unable to access remote computer's CurrentUser store. ` `nYou can only do this with the LocalMachine store name." Continue } } } Switch ($StoreLocation) { LocalMachine { #Create new object and make connection to LocalMachine certificate store on computer Write-Verbose "Attempting to make connection to certificate store" $ce=new-object System.Security.Cryptography.X509Certificates.X509Store("\\$c\$StoreName",$cu) } CurrentUser { #Create new object and make connection to CurrentUser certificate store on computer Write-Verbose "Attempting to make connection to certificate store" $ce=new-object System.Security.Cryptography.X509Certificates.X509Store("$StoreName") } } #Open the store using defined flags Write-Verbose "Opening certificate store using defined OpenFlags" $ce.Open($ro) #Determine what will be displayed based on parameter set name Write-Verbose "Determining what certificates to display" Switch ($Pscmdlet.ParameterSetName) { "PKI" { #List all certificates in the store Write-Verbose "Listing all certificates in store" $ce.certificates } "Expired" { Write-Verbose "Listing all expired certificates" $ce.Certificates | ? {$_.NotAfter -le (Get-Date)} } "Expiring" { Write-Verbose "Listing certificates that expire in $ExpiresIn days" #Create a datetime object with the expiration threshold to compare against certificate expiration timestamp $deadline = (Get-Date).AddDays($ExpiresIn) $ce.Certificates | ? {$_.NotAfter -le ($deadline)} } } } Catch { #Write error that occurred with connection Write-Host -foregroundcolor Yellow "$($c): $($error[0])" } } } } $servers = get-content .\servers.txt Function List{ foreach ($server in $servers){ Get-PKICertificates -comp $server -StoreLocation LocalMachine -StoreName My -ExpiresIn 60 | Format-Table @{Label=”Server Name”;Expression={($server)}},FriendlyName, @{Label=”Expires In (Days)”;Expression={($_.NotAfter – (get-Date)).Days}} -auto } } List | Out-File .\servercerts.txt #Email Variables $date = Get-Date -Format "MMMM d, yyyy" $time = Get-Date -Format "hh:mmtt" $from = "ssl.report@domain.local" $to = "admin@mail.com" $subject = "SSL Report - $Date - $Time" $body = Get-Content .\sslresults.txt $SMTPServer = "smtp.local" $sslresults = get-content .\sslresults.txt $cerstore = get-content .\servercerts.txt #Mail action Send-MailMessage -from $from -to $to -subject $subject -body ($sslresults + $cerstore | out-string) -smtpserver $SMTPServer
Optional Paste Settings
Category:
None
Cryptocurrency
Cybersecurity
Fixit
Food
Gaming
Haiku
Help
History
Housing
Jokes
Legal
Money
Movies
Music
Pets
Photo
Science
Software
Source Code
Spirit
Sports
Travel
TV
Writing
Tags:
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
JSON
Java
JavaScript
Lua
Markdown (PRO members only)
Objective C
PHP
Perl
Python
Ruby
Swift
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
AIMMS
ALGOL 68
APT Sources
ARM
ASM (NASM)
ASP
ActionScript
ActionScript 3
Ada
Apache Log
AppleScript
Arduino
Asymptote
AutoIt
Autohotkey
Avisynth
Awk
BASCOM AVR
BNF
BOO
Bash
Basic4GL
Batch
BibTeX
Blitz Basic
Blitz3D
BlitzMax
BrainFuck
C
C (WinAPI)
C Intermediate Language
C for Macs
C#
C++
C++ (WinAPI)
C++ (with Qt extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
CMake
COBOL
CSS
Ceylon
ChaiScript
Chapel
Clojure
Clone C
Clone C++
CoffeeScript
ColdFusion
Cuesheet
D
DCL
DCPU-16
DCS
DIV
DOT
Dart
Delphi
Delphi Prism (Oxygene)
Diff
E
ECMAScript
EPC
Easytrieve
Eiffel
Email
Erlang
Euphoria
F#
FO Language
Falcon
Filemaker
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
GDB
GDScript
Game Maker
Genero
Genie
GetText
Go
Godot GLSL
Groovy
GwBasic
HQ9 Plus
HTML
HTML 5
Haskell
Haxe
HicEst
IDL
INI file
INTERCAL
IO
ISPF Panel Definition
Icon
Inno Script
J
JCL
JSON
Java
Java 5
JavaScript
Julia
KSP (Kontakt Script)
KiXtart
Kotlin
LDIF
LLVM
LOL Code
LScript
Latex
Liberty BASIC
Linden Scripting
Lisp
Loco Basic
Logtalk
Lotus Formulas
Lotus Script
Lua
M68000 Assembler
MIX Assembler
MK-61/52
MPASM
MXML
MagikSF
Make
MapBasic
Markdown (PRO members only)
MatLab
Mercury
MetaPost
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MySQL
Nagios
NetRexx
Nginx
Nim
NullSoft Installer
OCaml
OCaml Brief
Oberon 2
Objeck Programming Langua
Objective C
Octave
Open Object Rexx
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
PARI/GP
PCRE
PHP
PHP Brief
PL/I
PL/SQL
POV-Ray
ParaSail
Pascal
Pawn
Per
Perl
Perl 6
Phix
Pic 16
Pike
Pixel Bender
PostScript
PostgreSQL
PowerBuilder
PowerShell
ProFTPd
Progress
Prolog
Properties
ProvideX
Puppet
PureBasic
PyCon
Python
Python for S60
QBasic
QML
R
RBScript
REBOL
REG
RPM Spec
Racket
Rails
Rexx
Robots
Roff Manpage
Ruby
Ruby Gnuplot
Rust
SAS
SCL
SPARK
SPARQL
SQF
SQL
SSH Config
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
StandardML
StoneScript
SuperCollider
Swift
SystemVerilog
T-SQL
TCL
TeXgraph
Tera Term
TypeScript
TypoScript
UPC
Unicon
UnrealScript
Urbi
VB.NET
VBScript
VHDL
VIM
Vala
Vedit
VeriLog
Visual Pro Log
VisualBasic
VisualFoxPro
WHOIS
WhiteSpace
Winbatch
XBasic
XML
XPP
Xojo
Xorg Config
YAML
YARA
Z80 Assembler
ZXBasic
autoconf
jQuery
mIRC
newLISP
q/kdb+
thinBasic
Paste Expiration:
Never
Burn after read
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Exposure:
Public
Unlisted
Private
Folder:
(members only)
Password
NEW
Enabled
Disabled
Burn after read
NEW
Paste Name / Title:
Create New Paste
Hello
Guest
Sign Up
or
Login
Sign in with Facebook
Sign in with Twitter
Sign in with Google
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Public Pastes
Free money using older build [1.3]
2 min ago | 0.20 KB
✅ This month smells like money
CSS | 16 min ago | 0.20 KB
I earned $9,000 with this method
29 min ago | 0.20 KB
Earn big $ on trading
CSS | 42 min ago | 0.20 KB
Crypto Exchange Profits
55 min ago | 0.20 KB
biplas v37 - fixes
10 hours ago | 4.14 KB
Black Friday aanbiedingen bij Ai Linkbuilders
10 hours ago | 1.93 KB
Black Friday aanbod voor linkbuilding en SEO
11 hours ago | 1.92 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the
Cookies Policy
.
OK, I Understand
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!