说明:该部分来自 《Google Hacking for Penetration Testers》第三版第四章的自动细化的内容
目标
找出文本中的邮箱地址、URL以及IP地址
Perl脚本
#!/usr/bin/perl
#
# Usage: ./search.pl FILE_TO_SEARCH WORDLIST
#
use strict;
open(SEARCHFILE,$ARGV[0]) || die("Can not open searchfile because $!");
open(WORDFILE,$ARGV[1]) || die("Can not open wordfile because $!");
my @WORDS=<WORDFILE>;
close(WORDFILE);
my $LineCount = 0;
while(<SEARCHFILE>){
foreach my $word (@WORDS){
chomp($word);
++$LineCount;
if(m/$word/) {
print "$&\n";
last;
}
}
}
close(SEARCHFILE);
补充
. 匹配除换行符以外的任意字符
\w 匹配字母或数字或下划线或汉字 等价于 ‘[^A-Za-z0-9_]’。
\s 匹配任意的空白符
\d 匹配数字
\b 匹配单词的开始或结束
^ 匹配字符串的开始
$ 匹配字符串的结束
IP正则
(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|[0-9])\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|[0-9])\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|[0-9])\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|[0-9])
URL正则
[a-zA-Z]{3,4}[sS]?://((([\w\d\-]+\.)+[a-zA-Z]{2,4})|((25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|[0-9])\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|[0-9])\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|[0-9])\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|[0-9])))((\?|/)[\w/=+#_~&:;%-\?\.]*)*
邮箱正则
[a-zA-Z0-9\._\-]+@(([a-zA-Z0-9._-]{2,99}\.)+[a-zA-Z]{2,4})|((25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|[0-9])\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|[0-9])\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|[0-9])\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|[0-9]))