ISC Stormcast For Monday, January 25th 2016

Assessing Remote Certificates with Powershell

Published: 2016-01-25
Last Updated: 2016-01-25 01:01:18 UTC
by Rob VandenBrink (Version: 1)
3 comment(s)

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

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

3 comment(s)


Diary Archives