You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.5 KiB

#!/usr/bin/perl -w
use strict;
use XML::Simple;
use Data::Dumper;
# Date
use POSIX qw(strftime);
my $date = strftime "%d/%m/%Y %H:%M", localtime;
# Functions
sub uniq {
my %seen;
grep !$seen{$_}++, @_;
}
print "\033[33m \nDEFACEMENT CHECK [" . $date . "]\n\nSearching for suspects ...\n";
print "FOUND \t\t=> URLs\n";
# Import config
my @search;
my $keywords = 'conf/keywords.cfg';
if (open(my $f, '<:encoding(UTF-8)', $keywords)) {
while (my $row = <$f>) {
chomp $row;
push @search, $row;
}
} else {
warn "Could not open file '$keywords' $!";
}
# Open XML files
my @files = glob( "sitemap/*.xml" );
my $file;
foreach $file (@files)
{
my $xml = new XML::Simple (KeyAttr=>[]);
my $url;
my $data = $xml->XMLin($file);
foreach $url (@{$data->{url}})
{
my $survey = $url->{loc};
# Create a user agent object
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
# Create a request
my $req = HTTP::Request->new(GET => $survey);
# Pass request to the user agent and get a response back
my $res = $ua->request($req);
my $site = $res->content;
my @found;
my $total_found = 0;
foreach my $s (@search) {
foreach (grep(/$s/i, split(/\n/, $site))) {
push @found, $_;
}
}
# Results
foreach (uniq(@found)) {
$total_found++;
# print $total_found . " : " . $_ . "\n"; # VERBOSE MODE
}
if ($total_found == 0) {
print "\033[32m" . $total_found . "\t\t=> " . $survey. "\n";
} else {
print "\033[31m" . $total_found . "\t\t=> " . $survey. "\n";
}
}
}