-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcertificate-inventory.ps1
69 lines (57 loc) · 2.99 KB
/
certificate-inventory.ps1
1
2
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
59
60
61
62
63
64
65
66
67
68
#Requires -version 2.0
##############################################
# This file is part of certificate-inventory.
#
# certificate-inventory is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# certificate-inventory is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# certificate-inventory. If not, see <http://www.gnu.org/licenses/>.
##############################################
##############################################
# Author: Oscar Koeroo <[email protected]>
# Office: KPN CISO / Red Team - Ethical Hacker
# Project: Certs-on-Fire
# Date: October 1, 2013
# Version: 0.1, powershell spinoff
# License: GPLv3
##############################################
$Ip = "62.132.193.64"
$Port = 443
$Connection = New-Object System.Net.Sockets.TcpClient($Ip,$Port)
$Connection.SendTimeout = 5000
$Connection.ReceiveTimeout = 5000
$Stream = $Connection.GetStream()
try {
$sslStream = New-Object System.Net.Security.SslStream($Stream,$False,([Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}))
$sslStream.AuthenticateAsClient($null)
#$Certificate = [Security.Cryptography.X509Certificates.X509Certificate2]$sslStream.RemoteCertificate
$cert = $sslStream.get_remotecertificate()
$cert2 = New-Object system.security.cryptography.x509certificates.x509certificate2($cert)
$validto = [datetime]::Parse($cert.getexpirationdatestring())
$validfrom = [datetime]::Parse($cert.geteffectivedatestring())
if ($cert.get_issuer().CompareTo($cert.get_subject())) {
$selfsigned = "no";
} else {
$selfsigned = "yes";
}
Write-Host '"' -nonewline; Write-Host $Ip -nonewline; Write-Host '",' -nonewline;
Write-Host '"' -nonewline; Write-Host $Port -nonewline; Write-Host '",' -nonewline;
Write-Host '"' -nonewline; Write-Host $cert.get_subject() -nonewline; Write-Host '",' -nonewline;
Write-Host '"' -nonewline; Write-Host $cert.get_issuer() -nonewline; Write-Host '",' -nonewline;
Write-Host '"' -nonewline; Write-Host $cert2.PublicKey.Key.KeySize -nonewline; Write-Host '",' -nonewline;
Write-Host '"' -nonewline; Write-Host $cert.getserialnumberstring() -nonewline; Write-Host '",' -nonewline;
Write-Host '"' -nonewline; Write-Host $validfrom -nonewline; Write-Host '",' -nonewline;
Write-Host '"' -nonewline; Write-Host $validto -nonewline; Write-Host '",' -nonewline;
Write-Host '"' -nonewline; Write-Host $selfsigned -nonewline; Write-Host '",' -nonewline;
Write-Host '"' -nonewline; Write-Host $cert2.SignatureAlgorithm.FriendlyName -nonewline; Write-Host '"';
} finally {
$Connection.Close()
}