Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add SAN with UPN by default when doing shadow credentials #1875

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion impacket/examples/ntlmrelayx/attacks/ldapattack.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def shadowCredentialsAttack(self, domainDumper):
LOG.info("Target user found: %s" % target_dn)

LOG.info("Generating certificate")
key,certificate = shadow_credentials.createSelfSignedX509Certificate(subject=currentShadowCredentialsTarget, nBefore=(-40 * 365), nAfter=(40 * 365))
key,certificate = shadow_credentials.createSelfSignedX509Certificate(subject=currentShadowCredentialsTarget, nBefore=(-40 * 365), nAfter=(40 * 365), domain=domain)
LOG.info("Certificate generated")
LOG.info("Generating KeyCredential")
keyCredential = shadow_credentials.KeyCredential(certificate,key,deviceId=shadow_credentials.getDeviceId(),currentTime=shadow_credentials.getTicksNow())
Expand Down
11 changes: 9 additions & 2 deletions impacket/examples/ntlmrelayx/utils/shadow_credentials.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from struct import pack
from Cryptodome.Util.number import long_to_bytes
from Cryptodome.PublicKey import RSA
from OpenSSL.crypto import PKey, X509, TYPE_RSA
from OpenSSL.crypto import PKey, X509, TYPE_RSA, X509Extension
import OpenSSL
import base64
import uuid
Expand All @@ -28,13 +28,20 @@ def getTicksNow():
def getDeviceId():
return uuid.uuid4().bytes

def createSelfSignedX509Certificate(subject,nBefore,nAfter,kSize=2048):
def createSelfSignedX509Certificate(subject,nBefore,nAfter,kSize=2048, domain=""):
key = PKey()
key.generate_key(TYPE_RSA,kSize)

certificate = X509()

certificate.get_subject().CN = subject

if domain != "":
certificate.set_version(2)
upn_extension = f"otherName:1.3.6.1.4.1.311.20.2.3;UTF8:{subject}@{domain}".encode('utf-8')
subjectAltName = X509Extension(b"subjectAltName", False, upn_extension)
certificate.add_extensions([subjectAltName])

certificate.set_issuer(certificate.get_subject())
certificate.gmtime_adj_notBefore(nBefore)
certificate.gmtime_adj_notAfter(nAfter)
Expand Down