|
| 1 | +## |
| 2 | +# This module requires Metasploit: https://metasploit.com/download |
| 3 | +# Current source: https://github.com/rapid7/metasploit-framework |
| 4 | +## |
| 5 | + |
| 6 | +class MetasploitModule < Msf::Auxiliary |
| 7 | + include Msf::Exploit::Remote::DNS::Enumeration |
| 8 | + |
| 9 | + def initialize(info = {}) |
| 10 | + super( |
| 11 | + update_info( |
| 12 | + info, |
| 13 | + 'Name' => 'Azure Subdomain Scanner and Enumerator', |
| 14 | + 'Description' => 'This module enumerates public Azure services by locating valid subdomains through various DNS queries.', |
| 15 | + 'Author' => ['RoseSecurity <RoseSecurityResearch[at]protonmail.me>'], |
| 16 | + 'References' => ['www.netspi.com/blog/technical/cloud-penetration-testing/enumerating-azure-services'], |
| 17 | + 'License' => MSF_LICENSE |
| 18 | + ) |
| 19 | + ) |
| 20 | + register_options( |
| 21 | + [ |
| 22 | + OptString.new('DOMAIN', [true, 'The target domain without TLD (e.g., victim instead of victim.org)']), |
| 23 | + OptBool.new('PERMUTATIONS', [false, 'Prepend and append permuted keywords to the domain', false]), |
| 24 | + OptBool.new('ENUM_A', [true, 'Enumerate DNS A record', true]), |
| 25 | + OptBool.new('ENUM_CNAME', [true, 'Enumerate DNS CNAME record', true]), |
| 26 | + OptBool.new('ENUM_MX', [true, 'Enumerate DNS MX record', true]), |
| 27 | + OptBool.new('ENUM_NS', [true, 'Enumerate DNS NS record', true]), |
| 28 | + OptBool.new('ENUM_SOA', [true, 'Enumerate DNS SOA record', true]), |
| 29 | + OptBool.new('ENUM_TXT', [true, 'Enumerate DNS TXT record', true]) |
| 30 | + ] |
| 31 | + ) |
| 32 | + end |
| 33 | + |
| 34 | + def dns_enum(target_domains) |
| 35 | + target_domains.each do |domain| |
| 36 | + if dns_get_a(domain) |
| 37 | + print_good("Discovered Target Domain: #{domain}") |
| 38 | + perform_dns_queries(domain) |
| 39 | + end |
| 40 | + end |
| 41 | + end |
| 42 | + |
| 43 | + def perform_dns_queries(domain) |
| 44 | + dns_get_a(domain) if datastore['ENUM_A'] |
| 45 | + dns_get_cname(domain) if datastore['ENUM_CNAME'] |
| 46 | + dns_get_ns(domain) if datastore['ENUM_NS'] |
| 47 | + dns_get_mx(domain) if datastore['ENUM_MX'] |
| 48 | + dns_get_soa(domain) if datastore['ENUM_SOA'] |
| 49 | + dns_get_txt(domain) if datastore['ENUM_TXT'] |
| 50 | + end |
| 51 | + |
| 52 | + def generate_target_domains(domain, subdomains) |
| 53 | + if datastore['PERMUTATIONS'] |
| 54 | + permuted_domains = generate_permutations(domain) |
| 55 | + (subdomains + permuted_domains).flat_map do |subdomain| |
| 56 | + subdomains.map { |tld| domain + tld } |
| 57 | + end |
| 58 | + else |
| 59 | + subdomains.map { |tld| domain + tld } |
| 60 | + end |
| 61 | + end |
| 62 | + |
| 63 | + def generate_permutations(domain) |
| 64 | + keywords = %w[ |
| 65 | + root web api azure azure-logs data database data-private data-public dev development |
| 66 | + demo files filestorage internal keys logs private prod production public service services |
| 67 | + splunk sql staging storage storageaccount test useast useast2 centralus northcentralus westcentralus |
| 68 | + westus westus2 |
| 69 | + ] |
| 70 | + keywords.flat_map do |keyword| |
| 71 | + ["#{domain}-#{keyword}", "#{keyword}-#{domain}"] |
| 72 | + end |
| 73 | + end |
| 74 | + |
| 75 | + def run |
| 76 | + domain = datastore['DOMAIN'] |
| 77 | + subdomains = %w[ |
| 78 | + .onmicrosoft.com .scm.azurewebsites.net .azurewebsites.net .p.azurewebsites.net .cloudapp.net |
| 79 | + .file.core.windows.net .blob.core.windows.net .queue.core.windows.net .table.core.windows.net |
| 80 | + .mail.protection.outlook.com .sharepoint.com .redis.cache.windows.net .documents.azure.com |
| 81 | + .database.windows.net .vault.azure.net .azureedge.net .search.windows.net .azure-api.net .azurecr.io |
| 82 | + ] |
| 83 | + |
| 84 | + target_domains = generate_target_domains(domain, subdomains) |
| 85 | + dns_enum(target_domains) |
| 86 | + end |
| 87 | +end |
0 commit comments