From 6a23b9cecdbf8dbdbf7b4b98bda090cd905fa3b9 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Wed, 27 Sep 2023 18:18:35 +1000 Subject: [PATCH] bot: Get domains from cert --- bot.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/bot.py b/bot.py index 079bb65..19c27f5 100644 --- a/bot.py +++ b/bot.py @@ -141,7 +141,7 @@ async def ssl(ctx, domain: str): await ctx.response.send_message("Please provide a valid domain to check") return - ctx.response.send_message(f"Checking SSL certificate for {domain}...") + await ctx.response.send_message(f"Checking SSL certificate for {domain}...") message = "" resolver = dns.resolver.Resolver() resolver.nameservers = ["100.74.29.146"] @@ -177,6 +177,18 @@ async def ssl(ctx, domain: str): certificates.append(current_cert) current_cert = "" + extracted_domains = [] + for cert in certificates: + domain_line = [line for line in cert.split("\n") if "Subject: CN" in line] + if domain_line: + domain = domain_line[0].split("Subject: CN=")[1] + extracted_domains.append(domain) + + if extracted_domains: + message = message + "\n## Extracted domains:\n" + for domain in extracted_domains: + message = message + "- " + domain + "\n" + # Remove anything before -----BEGIN CERTIFICATE----- certificates = [cert[cert.find("-----BEGIN CERTIFICATE-----"):] for cert in certificates]