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 support to impersonate_ssl module #16661

Merged
merged 1 commit into from
Jun 8, 2022
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
13 changes: 12 additions & 1 deletion modules/auxiliary/gather/impersonate_ssl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def initialize(info = {})
OptPath.new('PRIVKEY', [false, 'Sign the cert with your own CA private key', nil]),
OptString.new('PRIVKEY_PASSWORD', [false, 'Password for private key specified in PRIV_KEY (if applicable)', nil]),
OptPath.new('CA_CERT', [false, 'CA Public certificate', nil]),
OptString.new('ADD_CN', [false, 'Add CN to match spoofed site name (e.g. *.example.com)', nil])
OptString.new('ADD_CN', [false, 'Add CN to match spoofed site name (e.g. *.example.com)', nil]),
OptString.new('ADD_SAN', [false, 'Add SAN entries to certificate (e.g. alt.example.com,127.0.0.1)', nil])
]
)

Expand Down Expand Up @@ -180,6 +181,16 @@ def run
ef.create_extension('subjectKeyIdentifier', 'hash'),
]

# add additional SAN entries to the new cert
if !datastore['ADD_SAN'].nil? && !datastore['ADD_SAN'].empty?
sans = datastore['ADD_SAN'].to_s.split(/,/)
sans.map! do |san|
san = san =~ Resolv::IPv4::Regex || san =~ Resolv::IPv6::Regex ? "IP:#{san}" : "DNS:#{san}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
san = san =~ Resolv::IPv4::Regex || san =~ Resolv::IPv6::Regex ? "IP:#{san}" : "DNS:#{san}"
san = (san =~ Resolv::IPv4::Regex || san =~ Resolv::IPv6::Regex) ? "IP:#{san}" : "DNS:#{san}"

Suggestion for making this a little easier to read.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See https://support.f5.com/csp/article/K13471 for an example of how the IP and DNS fields might appear in a sample certificate. Adding this comment for future traveler's reference.

end
new_cert.add_extension(ef.create_extension('subjectAltName', sans.join(','), false))
print_status("Adding #{datastore['ADD_SAN']} to the certificate subject alternative names")
end

if !datastore['PRIVKEY'].nil? && !datastore['PRIVKEY'].empty?
new_cert.sign(ca_key, OpenSSL::Digest.new(hashtype))
new_key = ca_key # Set for file output
Expand Down