forked from sensepost/SP-DNS-mine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSP-DNS-mine.pl
107 lines (93 loc) · 3.19 KB
/
SP-DNS-mine.pl
1
2
3
4
5
6
7
8
9
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
#!/usr/bin/perl
#
# Google DNS name / sub domain miner
# SensePost Research 2003
#
# Assumes the GoogleSearch.wsdl file is in same directory
#
use SOAP::Lite;
if ($#ARGV<0){die "perl dns-mine.pl domainname\ne.g. perl dns-mine.pl cnn.com\n";}
my $company = $ARGV[0];
####### You want to edit these four lines: ##############
$key = "----YOUR GOOGLE API KEY HERE----";
@randomwords=("site","web","document",$company);
my $service = SOAP::Lite->service('file:./GoogleSearch.wsdl');
my $numloops=2; #number of pages - max 100
#########################################################
## Loop through all the words to overcome Google's 1000 hit limit
foreach $randomword (@randomwords){
print "\nAdding word [$randomword]\n";
#method 1
my $query = "$randomword $company -www.$company";
push @allsites,DoGoogle($key,$query,$company);
#method 2
my $query = "-www.$company $randomword site:$company";
push @allsites,DoGoogle($key,$query,$company);
}
## Remove duplicates
@allsites=dedupe(@allsites);
print STDOUT "\n---------------\nDNS names:\n---------------\n";
foreach $site (@allsites){
print STDOUT "$site\n";
}
## Check for subdomains
foreach $site (@allsites){
my $splitter=".".$company;
my ($frontpart,$backpart)=split(/$splitter/,$site);
if ($frontpart =~ /\./){
@subs=split(/\./,$frontpart);
my $temp="";
for (my $i=1; $i<=$#subs; $i++){
$temp=$temp.(@subs[$i].".");
}
push @allsubs,$temp.$company;
}
}
print STDOUT "\n---------------\nSub domains:\n---------------\n";
@allsubs=dedupe(@allsubs);
foreach $sub (@allsubs){
print STDOUT "$sub\n";
}
############------subs-------##########
sub dedupe{
my (@keywords) = @_;
my %hash = ();
foreach (@keywords) {
$_ =~ tr/[A-Z]/[a-z]/;
chomp;
if (length($_)>1){$hash{$_} = $_;}
}
return keys %hash;
}
sub parseURL{
my ($site,$company)=@_;
if (length($site)>0){
if ($site =~ /:\/\/([\.\w]+)[\:\/]/){
my $mined=$1;
if ($mined =~/$company/){
return $mined;
}
}
}
return "";
}
sub DoGoogle{
my ($GoogleKey,$GoogleQuery,$company)=@_;
my @GoogleDomains="";
for ($j=0; $j<$numloops; $j++){
print STDERR "$j ";
my $results = $service
-> doGoogleSearch($GoogleKey,$GoogleQuery,(10*$j),10,"true","","true","","latin1","latin1");
my $re=(@{$results->{resultElements}});
foreach my $results(@{$results->{resultElements}}){
my $site=$results->{URL};
my $dnsname=parseURL($site,$company);
if (length($dnsname)>0){
push @GoogleDomains,$dnsname;
}
}
if ($re !=10){last;}
}
return @GoogleDomains;
}