Class: Yawast::Scanner::Plugins::DNS::Generic
- Inherits:
-
Object
- Object
- Yawast::Scanner::Plugins::DNS::Generic
- Defined in:
- lib/scanner/plugins/dns/generic.rb
Class Method Summary collapse
- .dns_info(uri, options) ⇒ Object
- .find_srv(root_domain, resv) ⇒ Object
- .find_subdomains(root_domain, resv) ⇒ Object
- .get_network_info(ip) ⇒ Object
Class Method Details
.dns_info(uri, options) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/scanner/plugins/dns/generic.rb', line 10 def self.dns_info(uri, ) begin puts 'DNS Information:' root_domain = PublicSuffix.parse(uri.host).domain dns = Resolv::DNS.new Resolv::DNS.open do |resv| a = resv.getresources(uri.host, Resolv::DNS::Resource::IN::A) unless a.empty? a.each do |ip| begin host_name = dns.getname(ip.address) rescue host_name = 'N/A' end Yawast::Utilities.puts_info "\t\t#{ip.address} (#{host_name})" Yawast::Shared::Output.log_value 'dns', 'a', ip.address, host_name # if address is private, force internal SSL mode, don't show links if IPAddr.new(ip.address.to_s, Socket::AF_INET).private? .internalssl = true Yawast::Shared::Output.log_value 'force_internal_ssl', true else #show network info Yawast::Utilities.puts_info "\t\t\t#{get_network_info(ip.address)}" puts "\t\t\thttps://www.shodan.io/host/#{ip.address}" puts "\t\t\thttps://censys.io/ipv4/#{ip.address}" end end end aaaa = resv.getresources(uri.host, Resolv::DNS::Resource::IN::AAAA) unless aaaa.empty? aaaa.each do |ip| begin host_name = dns.getname(ip.address) rescue host_name = 'N/A' end Yawast::Utilities.puts_info "\t\t#{ip.address} (#{host_name})" Yawast::Shared::Output.log_value 'dns', 'aaaa', ip.address, host_name # if address is private, force internal SSL mode, don't show links if IPAddr.new(ip.address.to_s, Socket::AF_INET6).private? .internalssl = true else #show network info Yawast::Utilities.puts_info "\t\t\t#{get_network_info(ip.address)}" puts "\t\t\thttps://www.shodan.io/host/#{ip.address.to_s.downcase}" end end end txt = resv.getresources(uri.host, Resolv::DNS::Resource::IN::TXT) unless txt.empty? txt.each do |rec| Yawast::Utilities.puts_info "\t\tTXT: #{rec.data}" Yawast::Shared::Output.log_append_value 'dns', 'txt', uri.host, rec.data end end #check for higher-level TXT records, if we aren't already at the top if root_domain != uri.host begin txt = resv.getresources(root_domain, Resolv::DNS::Resource::IN::TXT) unless txt.empty? txt.each do |rec| Yawast::Utilities.puts_info "\t\tTXT (#{root_domain}): #{rec.data}" Yawast::Shared::Output.log_append_value 'dns', 'txt', root_domain, rec.data end end rescue => e Yawast::Utilities.puts_error "\t\tTXT: #{root_domain} (Error: #{e.})" end end mx = resv.getresources(uri.host, Resolv::DNS::Resource::IN::MX) unless mx.empty? mx.each do |rec| begin ip = resv.getaddress rec.exchange Yawast::Utilities.puts_info "\t\tMX: #{rec.exchange} (#{rec.preference}) - #{ip} (#{get_network_info(ip.to_s)})" Yawast::Shared::Output.log_value 'dns', 'mx', rec.exchange, ip rescue => e Yawast::Utilities.puts_error "\t\tMX: #{rec.exchange} (#{rec.preference}) - Error: #{e.})" end end end #check for higher-level MX records, if we aren't already at the top if root_domain != uri.host mx = resv.getresources(root_domain, Resolv::DNS::Resource::IN::MX) unless mx.empty? mx.each do |rec| begin ip = resv.getaddress rec.exchange Yawast::Utilities.puts_info "\t\tMX (#{root_domain}): #{rec.exchange} (#{rec.preference}) - #{ip} (#{get_network_info(ip.to_s)})" Yawast::Shared::Output.log_value 'dns', 'mx', rec.exchange, ip rescue => e Yawast::Utilities.puts_error "\t\tMX (#{root_domain}): #{rec.exchange} (#{rec.preference}) - Error: #{e.})" end end end end ns = resv.getresources(root_domain, Resolv::DNS::Resource::IN::NS) unless ns.empty? ns.each do |rec| ip = resv.getaddress rec.name Yawast::Utilities.puts_info "\t\tNS: #{rec.name} - #{ip} (#{get_network_info(ip.to_s)})" Yawast::Shared::Output.log_value 'dns', 'ns', rec.name, ip end end if .srv find_srv root_domain, resv end if .subdomains find_subdomains root_domain, resv end end #get the CAA info - unless it's an IP unless IPAddress.valid? uri.host Yawast::Scanner::Plugins::DNS::CAA.caa_info uri end puts rescue => e Yawast::Utilities.puts_error "Error getting basic information: #{e.}" raise end end |
.find_srv(root_domain, resv) ⇒ Object
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/scanner/plugins/dns/generic.rb', line 160 def self.find_srv(root_domain, resv) File.open(File.dirname(__FILE__) + '/../../../resources/srv_list.txt', 'r') do |f| f.each_line do |line| host = line.strip + '.' + root_domain begin srv = resv.getresources(host, Resolv::DNS::Resource::IN::SRV) unless srv.empty? srv.each do |rec| ip = resv.getaddress rec.target Yawast::Utilities.puts_info "\t\tSRV: #{host}: #{rec.target}:#{rec.port} - #{ip} (#{get_network_info(ip.to_s)})" Yawast::Shared::Output.log_value 'dns', 'srv', host, "#{rec.target}:#{rec.port}" end end rescue #if this fails, don't really care end end end end |
.find_subdomains(root_domain, resv) ⇒ Object
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/scanner/plugins/dns/generic.rb', line 183 def self.find_subdomains(root_domain, resv) res = Resolver.new() File.open(File.dirname(__FILE__) + '/../../../resources/subdomain_list.txt', 'r') do |f| f.each_line do |line| host = line.strip + '.' + root_domain begin ## get CNAME records cname = res.query(host, 'CNAME') if cname.answer[0] != nil Yawast::Utilities.puts_info "\t\tCNAME: #{host}: #{cname.answer[0].rdata}" Yawast::Shared::Output.log_value 'dns', 'subdomain', host, cname.answer[0].rdata next end ## get A records a = resv.getresources(host, Resolv::DNS::Resource::IN::A) unless a.empty? a.each do |ip| if IPAddr.new(ip.address.to_s, Socket::AF_INET).private? Yawast::Utilities.puts_info "\t\tA: #{host}: #{ip.address}" else Yawast::Utilities.puts_info "\t\tA: #{host}: #{ip.address} (#{get_network_info(ip.address)})" end Yawast::Shared::Output.log_value 'dns', 'subdomain', host, ip.address end end ## get AAAA records aaaa = resv.getresources(host, Resolv::DNS::Resource::IN::AAAA) unless aaaa.empty? aaaa.each do |ip| if IPAddr.new(ip.address.to_s, Socket::AF_INET6).private? Yawast::Utilities.puts_info "\t\tAAAA: #{host}: #{ip.address}" else Yawast::Utilities.puts_info "\t\tAAAA: #{host}: #{ip.address} (#{get_network_info(ip.address)})" end Yawast::Shared::Output.log_value 'dns', 'subdomain', host, ip.address end end rescue #if this fails, don't really care end end end end |
.get_network_info(ip) ⇒ Object
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/scanner/plugins/dns/generic.rb', line 236 def self.get_network_info(ip) #check to see if we have this one cached @netinfo = Hash.new if @netinfo == nil return @netinfo[ip] if @netinfo[ip] != nil #check to see if this has failed, if so, skip it. We do this to avoid repeated timeouts if outbound #connections are blocked. @netinfo_failed = false if @netinfo_failed == nil return 'Network Information disabled due to prior failure' if @netinfo_failed begin network_info = Yawast::Shared::Http.get_json URI("https://api.iptoasn.com/v1/as/ip/#{ip}") ret = "#{network_info['as_country_code']} - #{network_info['as_description']}" @netinfo[ip] = ret Yawast::Shared::Output.log_value 'dns', 'asn_info', ip, ret return ret rescue => e @netinfo_failed = true if e..include? 'unexpected token' # this means that the service returned something invalid, like HTML return "Error: getting network information failed (the service returned an unexpected message)" else return "Error: getting network information failed (#{e.})" end end end |