Untitled

From Mungo Capybara, 1 Year ago, written in Plain Text, viewed 520 times.
URL http://stoicbaby.com/pastebin/view/8f1066bf Embed
Download Paste or View Raw
  1. #! /usr/bin/env perl
  2. use Tie::File;
  3. use Sys::Hostname;
  4. use strict;
  5. use warnings;
  6. my $wl = '/opt/mod_security/wprbl_whitelist.txt';
  7. my $log = '/opt/eig_linux/log/wprbl_whitelist.log';
  8. my $now = time;
  9. my $hostname = hostname();
  10.  
  11. die "usage: $0 whitelist <ip>\n"
  12.         unless @ARGV == 2 && $ARGV[0] eq 'whitelist' && $ARGV[1] =~ /^ \d+\. \d+\. \d+\. \d+ $/x;
  13.  
  14. my $ip = $ARGV[1];
  15. (my $range = "/$ip") =~ s: \.\d+$ :.:x;
  16.  
  17. tie my @wl, 'Tie::File', $wl or die "Unable to open $wl with Tie::File : $!\n";
  18. for (@wl) {
  19.         next unless $range eq $_;
  20.         die "[!] wprbl whitelist on $hostname already contains $_ (which includes $ip)\n";
  21. }
  22. print "[*] whitelisting 256 IPs in $range (which includes $ip)\n";
  23. push @wl, $range;
  24. untie @wl;
  25. logit("$now,$hostname,$ip,@{[blacklisted() ? 'blacklisted' : 'not listed']}\n");
  26.  
  27. print "[*] gracefulling apache... (this can take a few minutes)\n";
  28. my @out;
  29. if ($ENV{RUSER}) { # if not called through eigsh
  30.         system "/usr/sbin/httpd -k graceful 2>&1";
  31. } else {
  32.         @out = qx(/usr/sbin/httpd -k graceful 2>&1);
  33. }
  34. if ($?) {
  35.         print @out, "\n";
  36.         print "[!] failed to graceful apache! is the server OK?\n";
  37. } else {
  38.         print "[*] wprbl whitelist updated, on disk and for apache\n";
  39. }
  40.  
  41. sub logit {
  42.         open my $f, '>>', $log or warn "Failed to open $log for appending : $!";
  43.         print {$f} $_ for @_;
  44.         close $f;
  45. }
  46.  
  47. sub blacklisted { qx:/usr/bin/dig @{[join(".", reverse(split /\./, $ip), "testwprbl.websitewelcome.com")]}: =~ /127/ }

Reply to "Untitled"

Here you can reply to the paste above