Created
September 29, 2014 10:01
-
-
Save moranned/745868fb26102298e837 to your computer and use it in GitHub Desktop.
grabs SSL Cert from specified Domain/IP
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
import ssl | |
import sys | |
import optparse | |
import ConfigParser | |
import OpenSSL | |
def getCertificate(s): | |
cert_pem = ssl.get_server_certificate((s, 443)) | |
cert_der = ssl.PEM_cert_to_DER_cert(cert_pem) | |
x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, cert_pem) | |
fingerprint = x509.digest('sha1') | |
fingerprint = ':'.join(fingerprint[pos:pos+2] for pos in xrange(0,len(fingerprint),2)) | |
subject = x509.get_subject() | |
print '%-25s %s' %('SHA1 Fingerprint:',fingerprint) | |
print '%-25s %s' %('Serial Number:',x509.get_serial_number()) | |
print '%-25s %s' %('Common Name:',subject.CN) | |
print '%-25s %s' %('Organization:',subject.O) | |
print '%-25s %s' %('Issue Date:',x509.get_notBefore()) | |
print '%-25s %s' %('Expiration Date:', x509.get_notAfter()) | |
cert_out = open(s,'wb') | |
cert_out.write(cert_pem) | |
cert_out.close() | |
def readConfigs(args): | |
usage = "Usage: python %prog [options] " | |
parser = optparse.OptionParser(usage=usage) | |
parser.add_option('--server', '-s', action='store', default=None, help='server to enumnerate') | |
global options | |
(options,server) = parser.parse_args(args) | |
def main(args): | |
readConfigs(args) | |
if options.server: | |
getCertificate(options.server) | |
if __name__ == "__main__": | |
args = sys.argv[1:] | |
if args: | |
main(args) | |
else: | |
print "See help (-h) for details" | |
sys.exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment