Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!perl
- #Copryight 2011 by Wilbe
- #License GNU GPL
- use LWP::UserAgent;
- use HTTP::Request;
- use Getopt::Long;
- use POSIX qw(strftime);
- use Time::HiRes qw(usleep);
- $| = 1;
- $count = 0;
- Print("Inicjalizacja skanera");
- $ua = LWP::UserAgent->new(timeout => 15, agent => '');
- $ua->proxy(['http', 'ftp'], 'localhost:8118');
- $result = GetOptions ("h|host=s" => \$host,
- "p|port=i" => \$port,
- "w|wordlist=s" => \$wordlist,
- "b|base=s" => \$base,
- "t|timeout=s" => \$timeout,
- "m|method=s" => \$method,
- "u|usage" => \$usage);
- if ($usage) {
- Usage();
- }
- print "Sprawdzanie danych wejsciowych...";
- if ($port) {
- if ($port !~ /^([0-9])*$/g) {
- Error("Niepoprawnie zdefiniowany port");
- }
- } else {
- $port = 80;
- }
- Usage("TRUE") if (!$host);
- $host = "http://".$host if ($host !~ /http:\/\/(.*)$/);
- if (!$base) {
- $base = "/";
- } else {
- $base = $base."/" if ($base !~ /^(.*)\/$/);
- $base = "/".$base if ($base !~ /^\/(.*)$/);
- }
- if ($wordlist) {
- @WORDLIST = split(",", $wordlist);
- } else {
- $wordlist = 'default';
- }
- if ($request) {
- if ($request !~ /^get$/i && $request !~ /^head$/i) {
- Error("Niepoprawnie zdefiniowany request");
- }
- } else {
- $request = "head";
- }
- if ($timeout) {
- if ($timeout !~ /^([0-9])*$/g) {
- Error("Niepoprawnie zdefiniowany timeout");
- }
- $timeout = $timeout * 1000;
- }
- if ($method) {
- @method = split(",", $method);
- for ($i = 0; $i < int(@method); $i++) {
- if ($method[$i] eq "bruteforce") {
- push(@DB, $_) for (0..100, 'a'..'zzz');
- }
- if ($method[$i] eq "wordlist") {
- $scan_wordlist = 1;
- }
- }
- } elsif (!$method) {
- $scan_wordlist = 1;
- }
- print "[OK]\n";
- print "Ladowanie plikow...";
- if ($scan_wordlist == 1) {
- opendir(DIR,"wordlists/") || Error("Nie mozna otworzyc katalogu wordlists/");
- @files = grep { /\.lst$/ } readdir DIR;
- closedir DIR;
- foreach $file (@files) {
- open(FILE, "<wordlists/$file") || Error("Nie mozna otworzyc pliku wordlists/$file");
- $file =~ s/.lst$//gi;
- eval "push \@$file,\<FILE>";
- push (@wordlists, $file);
- close(FILE);
- }
- @split = split(',', $wordlist);
- for ($i = 0; $i < int(@split); $i++) {
- $found = 0;
- for ($j = 0; $j < int(@wordlists); $j++) {
- if (lc($split[$i]) eq lc($wordlists[$j])) {
- $found = 1;
- eval "push \@DB,\@$wordlists[$j]";
- last;
- }
- }
- if ($found == 0) {
- Error("Nie mozna otworzyc pliku wordlists/$split[$i].lst");
- }
- }
- }
- print "[OK]\n";
- print "Sprawdzanie serwera...";
- @chars=('a'..'z','A'..'Z','0'..'9','_');
- foreach (1..10)
- {
- $random_string.=$chars[rand @chars];
- }
- Connect($host.":$port/");
- $exist_response = $res;
- Connect($host.":$port/$random_string");
- $unexist_response = $res;
- if ($exist_response == $unexist_response) {
- Error("Serwer odpowiada identycznie na zapytania");
- }
- if ($base ne "/") {
- Connect("$host$base");
- if ($res == $unexist_response) {
- Error("Katalog bazowy ($base) nie istnieje");
- }
- }
- print "[OK]\n";
- Print("Skanowanie rozpoczete");
- $db_size = int(@DB);
- $found = 0;
- foreach $dir (@DB) {
- $dir =~ s/[\r\n\s]//g;
- Connect($host.":$port$base$dir");
- if ($res != $unexist_response) {
- print "$host$base$dir - $res\n";
- $found++;
- }
- $time_now = strftime "[%H:%M:%S]", localtime;
- $procent = sprintf("%.2f", (($count+1) / $db_size) * 100);
- print "$time_now $procent%\r";
- $count++;
- }
- if ($found == 0) {
- print "Nic nie znaleziono...\n";
- }
- Print("Skanowanie zakonczone");
- print "Skanowanych plikow: $db_size\n";
- print "Znalezionych: $found\n";
- sub Connect {
- usleep($timeout);
- if ($request eq "head") {
- $response = $ua->head("$_[0]");
- } else {
- $response = $ua->get("$_[0]");
- }
- $res = $response->status_line;
- $res =~ s/([A-Za-z])|(\s)//g;
- if ($res =~ /^500/) {
- Error("Nie mozna polaczyc z $host");
- }
- }
- sub Error {
- print "[BLAD] $_[0]\n";
- exit;
- }
- sub Print {
- print "-" x 79;
- print "\n";
- print "$_[0]\n";
- print "-" x 79;
- print "\n";
- }
- sub Usage {
- if ($_[0] eq "TRUE") {
- print "[BLAD] Brak zdefiniowanego hosta\n\n";
- }
- print <<EOF;
- Uzytkowanie:
- > perl indir-ng.pl -h victim.org [OPCJE]
- Opcje:
- -h --host => host do skanowania
- -p --port => port serwera
- -b --base => katalog bazowy
- -w --wordlist => wordlista
- -m --method => metoda skanowania [wordlist,bruteforce]
- -t --timeout => odstep czasowy zapytan[w milisekundach]
- -u --usage => wyswietla liste opcji
- EOF
- exit;
- }
Advertisement
Add Comment
Please, Sign In to add comment