Skip to content

Commit 50284cf

Browse files
Vex WooVex Woo
authored andcommitted
parse domain/ip info from certificate
1 parent c79c102 commit 50284cf

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

modules/auxiliary/gather/censys_search.rb

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
class MetasploitModule < Msf::Auxiliary
1111

12+
include Msf::Auxiliary::Report
13+
1214
def initialize(info={})
1315
super(update_info(info,
1416
'Name' => 'Censys Search',
@@ -80,14 +82,39 @@ def search(keyword, search_type)
8082
end
8183
end
8284

85+
def valid_domain?(domain)
86+
domain =~ /^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/
87+
end
88+
89+
def domain2ip(domain)
90+
ips = []
91+
begin
92+
ips = Rex::Socket.getaddresses(domain)
93+
rescue SocketError
94+
end
95+
ips
96+
end
97+
8398
def parse_certificates(records)
99+
ips = []
84100
records.each do |certificate|
85101
# parsed.fingerprint_sha256
86102
# parsed.subject_dn
87103
# parsed.issuer_dn
88-
print_status(certificate['parsed.fingerprint_sha256'].join(','))
89-
print_status(certificate['parsed.subject_dn'].join(','))
90-
print_status(certificate['parsed.issuer_dn'].join(','))
104+
subject_dn = certificate['parsed.subject_dn'].join(',')
105+
next unless subject_dn.include?('CN=')
106+
107+
host = subject_dn.split('CN=')[1]
108+
if Rex::Socket.is_ipv4?(host)
109+
ips << host
110+
elsif valid_domain?(host) # Fake DNS server
111+
ips |= domain2ip(host)
112+
end
113+
114+
ips.each do |ip|
115+
print_good("#{ip} - #{subject_dn}")
116+
report_host(:host => ip, :info => subject_dn)
117+
end
91118
end
92119
end
93120

0 commit comments

Comments
 (0)