| 1 | package ZoneTransfer; |
|---|
| 2 | { |
|---|
| 3 | use Object::InsideOut; |
|---|
| 4 | use Net::DNS; |
|---|
| 5 | |
|---|
| 6 | # execute: Domain Base -> Output(Array) |
|---|
| 7 | # perform zone transfer domain |
|---|
| 8 | sub execute { |
|---|
| 9 | my ($self, $domain_obj, $base_obj) = @_; |
|---|
| 10 | |
|---|
| 11 | my $domain = $domain_obj->domain; |
|---|
| 12 | my $name_servers = $base_obj->name_servers; |
|---|
| 13 | my $res = Net::DNS::Resolver->new; |
|---|
| 14 | my (@zone, @output); |
|---|
| 15 | |
|---|
| 16 | if (scalar(@name_server) == 0 ) { |
|---|
| 17 | my $query = $res->query($domain, 'NS'); |
|---|
| 18 | if ($query) { |
|---|
| 19 | push(@output, "DNS Servers for $domain:\n"); |
|---|
| 20 | foreach my $rr (grep { $_->type eq 'NS' } $query->answer) { |
|---|
| 21 | my $dnssrv = $rr->nsdname; |
|---|
| 22 | push(@output, "\t$dnssrv\n"); |
|---|
| 23 | push (@name_servers, $rr->nsdname); |
|---|
| 24 | } |
|---|
| 25 | } |
|---|
| 26 | } |
|---|
| 27 | |
|---|
| 28 | if (scalar(@name_servers) > 0 ) { |
|---|
| 29 | push(@output, "\nTrying zone transfer...\n"); |
|---|
| 30 | for (@name_servers) { |
|---|
| 31 | $res->nameservers($_); |
|---|
| 32 | push(@output, "\tTesting $_\n"); |
|---|
| 33 | @zone = $res->axfr($domain); |
|---|
| 34 | @zone ? last : push(@output, "\t\tRequest timed out or transfer not allowed.\n"); |
|---|
| 35 | } |
|---|
| 36 | } |
|---|
| 37 | else { |
|---|
| 38 | print "Error: No name servers set\n"; |
|---|
| 39 | exit; |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | if (@zone) { |
|---|
| 43 | push(@output, "$_->string\n") for (@zone); |
|---|
| 44 | } |
|---|
| 45 | else { |
|---|
| 46 | push(@output, "\nUnsuccessful in zone transfer (it was worth a shot)\n"); |
|---|
| 47 | } |
|---|
| 48 | return @output; |
|---|
| 49 | } |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | 1; |
|---|