Assessing Remote Certificates with Powershell
Building on our last conversation about HTTPS and Powershell, let’s look at another common thing you’d do with HTTPS in a system administrator, or in a security assessment or penetration test – let’s assess the HTTPS certificates themselves. As in our last “episode”, we’ll need to rely on .NET to deal with certificates. Powershell on its own doesn’t have the commands to do the job. The following code worked OK for anything with a valid, trusted certificate:
However, if the host has a self-signed certificate, it will choke on the “AuthenticateAsClient” line. Since we’re almost guaranteed to find these on an internal subnet (and lots of internet-facing subnets too), we’ll need to get around this problem. Let’s try another approach:
Now again, with a bit of error checking this time, and some cleanup – we’ll also close the SSL Stream and the TCP Socket (always a good idea)
Note that you don’t want to run this indiscriminately across a subnet – if you try to “assess” a host that doesn’t have an open port, or doesn’t have an HTTPS server on that port, then you’ll get some not-so-pretty error messages, and either your script will have a lengthy delay or an ungraceful exit. Stay tuned – tomorrow’s story we’ll deal with those two issues.
Let’s take a look at the contents of the ISC’s certificate:
Which certificate values might you most frequently look at? Likely the dates, issuer and signature algorithms for starters. Let’s look at two examples of a self-signed certificate – first, an ASA Firewall:
Compared to a Palo Alto firewall:
Or a certificate issued by a “real” CA (the certificate for isc.sans.edu):
Checking a certificate's expiry date:
And signature algorithms:
Finally, Powershell / .Net has a neat “is this a valid certificate” check, where the local workstation checks validity from its perspective- checking it’s local certificate store, then chaining up to trusted CA's and so on. Let’s look first at an internal host, with a self-signed certificate, and then the cert on the ISC’s site:
The cool thing? You can easily, just by changing the port number, check certificates on things like:
- RDP services on Windows or Linux hosts
- Lync (or Skype for Business) server certificates
- STARTTLS certificates on mail servers
... really anything.
If this seems pretty basic, stay tuned - we'll use these functions for some serious automation tomorrow
===============
Rob VandenBrink
Compugen
Comments
www
Nov 17th 2022
6 months ago
EEW
Nov 17th 2022
6 months ago
qwq
Nov 17th 2022
6 months ago
mashood
Nov 17th 2022
6 months ago
isc.sans.edu
Nov 23rd 2022
6 months ago
isc.sans.edu
Nov 23rd 2022
6 months ago
isc.sans.edu
Dec 3rd 2022
6 months ago
isc.sans.edu
Dec 3rd 2022
6 months ago
<a hreaf="https://technolytical.com/">the social network</a> is described as follows because they respect your privacy and keep your data secure. The social networks are not interested in collecting data about you. They don't care about what you're doing, or what you like. They don't want to know who you talk to, or where you go.
<a hreaf="https://technolytical.com/">the social network</a> is not interested in collecting data about you. They don't care about what you're doing, or what you like. They don't want to know who you talk to, or where you go. The social networks only collect the minimum amount of information required for the service that they provide. Your personal information is kept private, and is never shared with other companies without your permission
isc.sans.edu
Dec 26th 2022
5 months ago
isc.sans.edu
Dec 26th 2022
5 months ago