robercik1010

Untitled

May 11th, 2014
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.25 KB | None | 0 0
  1. #!perl
  2.  
  3. #Copryight 2011 by Wilbe
  4. #License GNU GPL
  5.  
  6. use LWP::UserAgent;
  7. use HTTP::Request;
  8. use Getopt::Long;
  9. use POSIX qw(strftime);
  10. use Time::HiRes qw(usleep);
  11.  
  12. $| = 1;
  13. $count = 0;
  14.  
  15. Print("Inicjalizacja skanera");
  16.  
  17. $ua = LWP::UserAgent->new(timeout => 15, agent => '');
  18. $ua->proxy(['http', 'ftp'], 'localhost:8118');
  19. $result = GetOptions ("h|host=s" => \$host,
  20. "p|port=i" => \$port,
  21. "w|wordlist=s" => \$wordlist,
  22. "b|base=s" => \$base,
  23. "t|timeout=s" => \$timeout,
  24. "m|method=s" => \$method,
  25. "u|usage" => \$usage);
  26.  
  27. if ($usage) {
  28. Usage();
  29. }
  30.  
  31. print "Sprawdzanie danych wejsciowych...";
  32.  
  33. if ($port) {
  34. if ($port !~ /^([0-9])*$/g) {
  35. Error("Niepoprawnie zdefiniowany port");
  36. }
  37. } else {
  38. $port = 80;
  39. }
  40.  
  41. Usage("TRUE") if (!$host);
  42. $host = "http://".$host if ($host !~ /http:\/\/(.*)$/);
  43.  
  44. if (!$base) {
  45. $base = "/";
  46. } else {
  47. $base = $base."/" if ($base !~ /^(.*)\/$/);
  48. $base = "/".$base if ($base !~ /^\/(.*)$/);
  49. }
  50.  
  51. if ($wordlist) {
  52. @WORDLIST = split(",", $wordlist);
  53. } else {
  54. $wordlist = 'default';
  55. }
  56.  
  57. if ($request) {
  58. if ($request !~ /^get$/i && $request !~ /^head$/i) {
  59. Error("Niepoprawnie zdefiniowany request");
  60. }
  61. } else {
  62. $request = "head";
  63. }
  64.  
  65. if ($timeout) {
  66. if ($timeout !~ /^([0-9])*$/g) {
  67. Error("Niepoprawnie zdefiniowany timeout");
  68. }
  69. $timeout = $timeout * 1000;
  70. }
  71.  
  72.  
  73.  
  74. if ($method) {
  75. @method = split(",", $method);
  76.  
  77. for ($i = 0; $i < int(@method); $i++) {
  78. if ($method[$i] eq "bruteforce") {
  79. push(@DB, $_) for (0..100, 'a'..'zzz');
  80. }
  81.  
  82. if ($method[$i] eq "wordlist") {
  83. $scan_wordlist = 1;
  84. }
  85. }
  86. } elsif (!$method) {
  87. $scan_wordlist = 1;
  88. }
  89.  
  90. print "[OK]\n";
  91.  
  92.  
  93. print "Ladowanie plikow...";
  94. if ($scan_wordlist == 1) {
  95. opendir(DIR,"wordlists/") || Error("Nie mozna otworzyc katalogu wordlists/");
  96. @files = grep { /\.lst$/ } readdir DIR;
  97. closedir DIR;
  98.  
  99.  
  100. foreach $file (@files) {
  101. open(FILE, "<wordlists/$file") || Error("Nie mozna otworzyc pliku wordlists/$file");
  102. $file =~ s/.lst$//gi;
  103. eval "push \@$file,\<FILE>";
  104. push (@wordlists, $file);
  105. close(FILE);
  106. }
  107.  
  108.  
  109. @split = split(',', $wordlist);
  110.  
  111.  
  112. for ($i = 0; $i < int(@split); $i++) {
  113. $found = 0;
  114. for ($j = 0; $j < int(@wordlists); $j++) {
  115. if (lc($split[$i]) eq lc($wordlists[$j])) {
  116. $found = 1;
  117. eval "push \@DB,\@$wordlists[$j]";
  118. last;
  119. }
  120. }
  121. if ($found == 0) {
  122. Error("Nie mozna otworzyc pliku wordlists/$split[$i].lst");
  123. }
  124. }
  125. }
  126.  
  127. print "[OK]\n";
  128.  
  129.  
  130. print "Sprawdzanie serwera...";
  131.  
  132. @chars=('a'..'z','A'..'Z','0'..'9','_');
  133.  
  134. foreach (1..10)
  135. {
  136. $random_string.=$chars[rand @chars];
  137. }
  138.  
  139. Connect($host.":$port/");
  140. $exist_response = $res;
  141. Connect($host.":$port/$random_string");
  142. $unexist_response = $res;
  143.  
  144. if ($exist_response == $unexist_response) {
  145. Error("Serwer odpowiada identycznie na zapytania");
  146. }
  147.  
  148. if ($base ne "/") {
  149. Connect("$host$base");
  150.  
  151. if ($res == $unexist_response) {
  152. Error("Katalog bazowy ($base) nie istnieje");
  153. }
  154. }
  155. print "[OK]\n";
  156.  
  157. Print("Skanowanie rozpoczete");
  158.  
  159. $db_size = int(@DB);
  160. $found = 0;
  161. foreach $dir (@DB) {
  162. $dir =~ s/[\r\n\s]//g;
  163.  
  164. Connect($host.":$port$base$dir");
  165. if ($res != $unexist_response) {
  166. print "$host$base$dir - $res\n";
  167. $found++;
  168. }
  169. $time_now = strftime "[%H:%M:%S]", localtime;
  170. $procent = sprintf("%.2f", (($count+1) / $db_size) * 100);
  171. print "$time_now $procent%\r";
  172. $count++;
  173. }
  174.  
  175. if ($found == 0) {
  176. print "Nic nie znaleziono...\n";
  177. }
  178.  
  179. Print("Skanowanie zakonczone");
  180. print "Skanowanych plikow: $db_size\n";
  181. print "Znalezionych: $found\n";
  182.  
  183. sub Connect {
  184. usleep($timeout);
  185.  
  186. if ($request eq "head") {
  187. $response = $ua->head("$_[0]");
  188. } else {
  189. $response = $ua->get("$_[0]");
  190. }
  191.  
  192. $res = $response->status_line;
  193. $res =~ s/([A-Za-z])|(\s)//g;
  194.  
  195. if ($res =~ /^500/) {
  196. Error("Nie mozna polaczyc z $host");
  197. }
  198. }
  199.  
  200. sub Error {
  201. print "[BLAD] $_[0]\n";
  202. exit;
  203. }
  204.  
  205. sub Print {
  206. print "-" x 79;
  207. print "\n";
  208. print "$_[0]\n";
  209. print "-" x 79;
  210. print "\n";
  211. }
  212.  
  213. sub Usage {
  214.  
  215. if ($_[0] eq "TRUE") {
  216. print "[BLAD] Brak zdefiniowanego hosta\n\n";
  217. }
  218.  
  219. print <<EOF;
  220. Uzytkowanie:
  221. > perl indir-ng.pl -h victim.org [OPCJE]
  222.  
  223. Opcje:
  224. -h --host => host do skanowania
  225. -p --port => port serwera
  226. -b --base => katalog bazowy
  227. -w --wordlist => wordlista
  228. -m --method => metoda skanowania [wordlist,bruteforce]
  229. -t --timeout => odstep czasowy zapytan[w milisekundach]
  230. -u --usage => wyswietla liste opcji
  231. EOF
  232. exit;
  233. }
Advertisement
Add Comment
Please, Sign In to add comment