Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions modules/signatures/all/pe_cert_suspicious.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,19 @@ def run(self):
ds = pe.get("digital_signers") or []
gs = pe.get("guest_signers") or {}

# A root CA signs itself, so a complete chain always holds a self-signed
# certificate. Only one that issued none of the others is the signer.
issuers = {
cert.get("issuer_commonName", "").lower()
for cert in ds
if cert.get("subject_commonName", "").lower() != cert.get("issuer_commonName", "").lower()
}
for cert in ds:
subject = cert.get("subject_commonName", "")
issuer = cert.get("issuer_commonName", "")
if not subject or not issuer:
continue
if subject.lower() != issuer.lower():
if subject.lower() != issuer.lower() or subject.lower() in issuers:
continue
if _is_known_ca(subject):
continue
Expand All @@ -80,12 +87,12 @@ def run(self):
)

if not self.data:
for signer in gs.get("aux_signers") or []:
if "Certificate Chain" not in (signer.get("name") or ""):
continue
chain = [s for s in gs.get("aux_signers") or [] if "Certificate Chain" in (s.get("name") or "")]
chain_issuers = {s.get("Issued by", "") for s in chain if s.get("Issued to") != s.get("Issued by")}
for signer in chain:
issued_to = signer.get("Issued to", "")
issued_by = signer.get("Issued by", "")
if issued_to and issued_to == issued_by and not _is_known_ca(issued_to):
if issued_to and issued_to == issued_by and issued_to not in chain_issuers and not _is_known_ca(issued_to):
self.data.append(
{
"subject": issued_to,
Expand Down
Loading