From 6b1d13b3f429f2a3aa4cf54da813ee61b5aa6a6a Mon Sep 17 00:00:00 2001 From: Omar Santos Date: Mon, 18 Sep 2023 19:41:50 -0400 Subject: [PATCH] Create get_cert_info.py --- .../certificate_information/get_cert_info.py | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 programming_and_scripting_for_cybersecurity/recon_scripts/certificate_information/get_cert_info.py diff --git a/programming_and_scripting_for_cybersecurity/recon_scripts/certificate_information/get_cert_info.py b/programming_and_scripting_for_cybersecurity/recon_scripts/certificate_information/get_cert_info.py new file mode 100644 index 0000000..8e0de7b --- /dev/null +++ b/programming_and_scripting_for_cybersecurity/recon_scripts/certificate_information/get_cert_info.py @@ -0,0 +1,40 @@ +''' +This script takes a domain as input and returns the SSL certificate information of the domain. +Author: Omar Santos @santosomar +''' + +# Import the necessary modules +import ssl +import socket +from pprint import pprint +import argparse + +def get_certificate_info(hostname, port=443): + ''' + get certificate information + :param hostname: hostname + :param port: port + :return: None + ''' + context = ssl.create_default_context() + conn = context.wrap_socket(socket.socket(socket.AF_INET), server_hostname=hostname) + conn.settimeout(3.0) + + try: + conn.connect((hostname, port)) + cert = conn.getpeercert() + pprint(cert) + except Exception as e: + print(f"Could not retrieve certificate information: {e}") + finally: + conn.close() + +if __name__ == "__main__": + # Parse the command line arguments + parser = argparse.ArgumentParser(description='Get SSL certificate information of a domain.') + parser.add_argument('domain', type=str, help='Domain name to get the certificate information') + parser.add_argument('--port', type=int, default=443, help='Port number (default: 443)') + + args = parser.parse_args() + + get_certificate_info(args.domain, args.port)