bot: Get domains from cert
All checks were successful
Build Docker / Build Docker (push) Successful in 16s

This commit is contained in:
Nathan Woodburn 2023-09-27 18:18:35 +10:00
parent a88376555d
commit 6a23b9cecd
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1

14
bot.py
View File

@ -141,7 +141,7 @@ async def ssl(ctx, domain: str):
await ctx.response.send_message("Please provide a valid domain to check") await ctx.response.send_message("Please provide a valid domain to check")
return return
ctx.response.send_message(f"Checking SSL certificate for {domain}...") await ctx.response.send_message(f"Checking SSL certificate for {domain}...")
message = "" message = ""
resolver = dns.resolver.Resolver() resolver = dns.resolver.Resolver()
resolver.nameservers = ["100.74.29.146"] resolver.nameservers = ["100.74.29.146"]
@ -177,6 +177,18 @@ async def ssl(ctx, domain: str):
certificates.append(current_cert) certificates.append(current_cert)
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----- # Remove anything before -----BEGIN CERTIFICATE-----
certificates = [cert[cert.find("-----BEGIN CERTIFICATE-----"):] for cert in certificates] certificates = [cert[cert.find("-----BEGIN CERTIFICATE-----"):] for cert in certificates]