Foros del Web » Programando para Internet » PHP »

Como agregarle seguridad a mi web

Estas en el tema de Como agregarle seguridad a mi web en el foro de PHP en Foros del Web. Buenas al foro, necesito una ayuda enorme, resulta que he realizando una pagina de noticias que ultimamente fue atacada y se redireccionaba hacia una leyenda ...
  #1 (permalink)  
Antiguo 22/09/2014, 14:06
 
Fecha de Ingreso: junio-2012
Mensajes: 30
Antigüedad: 11 años, 10 meses
Puntos: 0
Como agregarle seguridad a mi web

Buenas al foro, necesito una ayuda enorme, resulta que he realizando una pagina de noticias que ultimamente fue atacada y se redireccionaba hacia una leyenda que decia:

Hacked! Revolters Brazil HackTeam ;)

En el servicio del hosting me dijeron que mi aplicación no tiene seguridad y son las causas por las que inyectan Script malicioso dentro de tu base de datos. A parte me dijeron que no debo colocar consultas sql dentro de un archivo que uso de vista o que muestre algo al visitante el script que han infectado mi pagina se encuentra dentro de una noticia y es el siguiente:

'**<script>document.documentElement.innerHTML = unescape("<title>Hacked Revolters Brazil HackTeam </title><center><pre><b><big><big><big>Hacked! Revolters Brazil HackTeam ;)</pre></big></b>");</script></h3>**'.

Por eso recurro a Uds. para ver si pueden ayudarme a darle un poco mas de seguridad a mi web, he comentado la linea 117 de mi archivo index que realiza la consulta a esta tabla infectada.

Este es el index:
Código PHP:
Ver original
  1. <?php
  2. require 'conexion/conexion.php';
  3. ?>
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  5. <html xmlns="http://www.w3.org/1999/xhtml">
  6. <head>
  7. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  8. <title>Tu mejor parada</title>
  9. <link rel="stylesheet" href="estilo/estilo1.css" type="text/css"/>
  10. <link rel="shortcut icon" href="imagenes/favicon.ico" />
  11. </head>
  12.  
  13. <body>
  14.  
  15. <div id="cabecera">
  16.     <?php
  17.     $sql="select * from imagenes";
  18.     $res=mysql_query($sql,$con);
  19.     while ($reg=mysql_fetch_array($res))
  20.     {
  21.     ?>
  22.     <img src="imagenes/<?php echo $reg["imagen"];?>" />
  23.     <?php
  24.     }
  25.     ?>
  26. </div>
  27.  
  28. <div id="menu">
  29.     <ul id="button">
  30.     <li><a href="index.php">Inicio</a></li>
  31.     <li><a href="menu/noticias.php">Noticias</a></li>
  32.     <li><a href="menu/editorial.php">Editorial</a></li>
  33.     <li><a href="menu/contacto.php">Contacto</a></li>
  34.     </ul>
  35.     <div class="fechayhora">
  36.     <?php include ('admin/fecha.php') ?> - <?php include(   'admin/hora.php') ?>
  37.     </div>
  38. </div>
  39.  
  40. <div id="centro">
  41.  
  42. <div class="izquierda">
  43.     <div class="rotativas">
  44.    
  45.     <table width="100%" border="0">
  46.     <tr>
  47.     <td valign="top">
  48.     <ul class="ppt">
  49.         <?php
  50. $sql="select * FROM rotativas, noticia WHERE rotativas.id =  noticia.id ORDER BY rotativas_id DESC LIMIT 4";
  51. $res=mysql_query($sql,$con);
  52. while ($reg=mysql_fetch_array($res))
  53.     {
  54. ?>
  55.                <li><a href="admin/ver-noticias.php?id=<?php echo $reg["id"];?>"><img src="imagenes/<?php echo $reg["foto"];?>"alt="foto 1"></a><div class="ft-title" id="ft-title-ft"><h1><?php echo $reg["titulo"];?></h1></div></img></li>
  56.                <?php
  57.     }
  58.     ?>
  59.                </ul>
  60.          
  61.             <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
  62. <script type="text/javascript">
  63. $('.ppt li:gt(0)').hide();
  64. $('.ppt li:last').addClass('last');
  65. var cur = $('.ppt li:first');
  66.  
  67. function animate() {
  68. cur.fadeOut( 1000 );
  69. if ( cur.attr('class') == 'last' )
  70. cur = $('.ppt li:first');
  71. else
  72. cur = cur.next();
  73. cur.fadeIn( 1000 );
  74. }
  75.  
  76. $(function() {
  77. setInterval( "animate()", 5000 );
  78. } );
  79. </script>
  80.     </td>
  81.   </tr>
  82. </table>
  83.  
  84.    
  85.     </div>
  86.    
  87.     <div class="publi1">
  88.         <?php
  89.         $sql="select * from publicidad_central LIMIT 1";
  90.         $res=mysql_query($sql,$con);
  91.         while ($reg=mysql_fetch_array($res))
  92.         {
  93.         ?>
  94.         <img src="imagenes/<?php echo $reg["publicidad"];?>" />
  95.         <?php
  96.         }
  97.         ?>
  98.     </div>
  99.    
  100.     <?php
  101.         $sql="select * FROM editorial ORDER BY id DESC LIMIT 1";
  102.         $res=mysql_query($sql,$con);
  103.         while($mostrador = mysql_fetch_array($res))
  104.         {
  105.         ?>
  106.     <div class="editorial">
  107.     <a href="admin/ver-editorial.php?id=<?php echo $mostrador["id"];?>"><h1><?php echo $mostrador["titulo"];?></h1></a>
  108.     <img src="imagenes/<?php echo $mostrador["foto"];?>">
  109.     <p><?php echo $mostrador["copete"];?></p>
  110.     </div>
  111.     <?php
  112.         }
  113.     ?>
  114.    
  115.     <div class="noticias">
  116.     <?php
  117.         //$sql="select * FROM noticia ORDER BY id DESC LIMIT 0, 10"; -----------******* (ACA ES DONDE ME CARGA EL SCRIPT Y ME PIDIERIO QUE NO HAGA CONSULTA SQL)
  118.         $res=mysql_query($sql,$con);
  119.         ?>
  120.     <table width="100%" cellspacing="10"  border="0" class="tabla-noticia" >
  121.     <tr valign="top">
  122.     <?php
  123.          $i = 0;
  124.         while($mostrador = mysql_fetch_array($res))  {
  125.             $r = $i % 2;
  126.            
  127.         echo '<td valign="top">';
  128.                 echo '<a href=admin/ver-noticias.php?id='.$mostrador[id].'><h1>'.$mostrador[titulo].'</h1></a>';
  129.                 echo '<img src="imagenes/'.$mostrador[foto].'">';
  130.                 echo '<p>'.$mostrador['subtitulo'].'</p>';
  131.         echo '</td>';
  132.         if ($i > 0 && $r == 1) {
  133.         echo '</tr>';
  134.         echo '<tr>';
  135.         }
  136.             $i++;
  137.         }
  138.     ?>
  139. </tr>
  140. </table>
  141.     </div>
  142.    
  143.     <div class="publi2">
  144.     <table width="100%" border="0">
  145.     <?php
  146.     $sql="select * from publicidad_central2 LIMIT 1";
  147.     $res=mysql_query($sql,$con);
  148.     while ($reg=mysql_fetch_array($res))
  149.     {
  150.     ?>
  151.     <tr>
  152.     <td><img src="imagenes/<?php echo $reg["publicidad"];?>" /></td>
  153.     </tr>
  154.     <?php
  155.     }
  156.     ?>
  157.     </table>
  158.     </div>
  159.    
  160.     <div class="noticias">
  161.     <?php
  162.         $sql="select * FROM noticia ORDER BY id DESC LIMIT 10, 10";
  163.         $res=mysql_query($sql,$con);
  164.         ?>
  165.     <table width="100%" cellspacing="10"  border="0" class="tabla-noticia" >
  166.     <tr valign="top">
  167.     <?php
  168.          $i = 0;
  169.         while($mostrador = mysql_fetch_array($res))  {
  170.             $r = $i % 2;
  171.            
  172.         echo '<td valign="top">';
  173.                 echo '<a href=admin/ver-noticias.php?id='.$mostrador[id].'><h1>'.$mostrador[titulo].'</h1></a>';
  174.                 echo '<img src="imagenes/'.$mostrador[foto].'">';
  175.                 echo '<p>'.$mostrador['subtitulo'].'</p>';
  176.         echo '</td>';
  177.         if ($i > 0 && $r == 1) {
  178.         echo '</tr>';
  179.         echo '<tr>';
  180.         }
  181.             $i++;
  182.         }
  183.     ?>
  184. </tr>
  185. </table>
  186.     </div>
  187.        
  188. </div>
  189.  
  190. <div class="derecha">
  191.    
  192.     <div align="center" class="buscador">
  193. <form name="buscador" method="get" action="admin/buscar.php" >
  194. <input type="text" name="s" class="busca1">
  195. <a href="javascript:void(0)" title="Buscar" onClick="document.buscador.submit();">
  196. <img src="imagenes/lupa.png" width="24" height="24" border="0">
  197. </a>
  198. </form>
  199. </div>
  200.  
  201.     <center><div class="clima">
  202.     <?php
  203.     $sql="select * from clima";
  204.     $res=mysql_query($sql,$con);
  205.     while ($reg=mysql_fetch_array($res))
  206.     {
  207.         echo chao_tilde($reg["clima"]);
  208.     }
  209.     ?>
  210.     </div></center>
  211.    
  212.     <div class="plublicidadlateral">
  213.     <?php
  214.         $sql="select * from publicidad_lateral ORDER BY publicidad_id DESC";
  215.         $res=mysql_query($sql,$con);
  216.         while ($reg=mysql_fetch_array($res))
  217.         {
  218.         ?>
  219.         <img src="imagenes/<?php echo $reg["publicidad"];?>" />
  220.         <?php
  221.         }
  222.         ?>
  223.     </div>
  224.     </div>
  225.  
  226. </div>

Este es el archivo que tambien me carga el script que es donde se muestra todas las noticias:

Código PHP:
Ver original
  1. <?php
  2. require '../conexion/conexion.php';
  3. ?>
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  5. <html xmlns="http://www.w3.org/1999/xhtml">
  6. <head>
  7. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  8. <title>Tu mejor parada</title>
  9. <link rel="stylesheet" href="../estilo/estilo1.css" type="text/css"/>
  10. <link rel="stylesheet" href="../estilo/zebra_pagination.css" type="text/css">
  11. <link rel="shortcut icon" href="../imagenes/favicon.ico" />
  12. </head>
  13.  
  14. <body>
  15.  
  16. <div id="cabecera">
  17.     <?php
  18.     $sql="select * from imagenes";
  19.     $res=mysql_query($sql,$con);
  20.     while ($reg=mysql_fetch_array($res))
  21.     {
  22.     ?>
  23.     <img src="../imagenes/<?php echo $reg["imagen"];?>" />
  24.     <?php
  25.     }
  26.     ?>
  27. </div>
  28.  
  29. <div id="menu">
  30.     <ul id="button">
  31.     <li><a href="../index.php">Inicio</a></li>
  32.     <li><a href="noticias.php">Noticias</a></li>
  33.     <li><a href="editorial.php">Editorial</a></li>
  34.     <li><a href="contacto.php">Contacto</a></li>
  35.     </ul>
  36.     <div class="fechayhora">
  37.     <?php include ('../admin/fecha.php') ?> - <?php include('../admin/hora.php') ?>
  38.     </div>
  39. </div>
  40.  
  41. <?php
  42.  
  43. require_once '../admin/ez_sql_core.php';
  44. require_once '../admin/ez_sql_mysql.php';
  45. require_once '../admin/Zebra_Pagination.php';
  46.  
  47. $conn = new ezSQL_mysql('tiempos1_tiempos', 'b6zTg7xG49', 'tiempos1_tiemposdehoy');
  48.  
  49. $total_paises = $conn->get_var('SELECT count(*) FROM noticia');
  50. $resultados   = 20;
  51.  
  52. $paginacion = new Zebra_Pagination();
  53. $paginacion->records($total_paises);
  54. $paginacion->records_per_page($resultados);
  55. // Quitar ceros en numeros con 1 digito en paginacion
  56. $paginacion->padding(false);
  57.  
  58. $noticias = $conn->get_results('SELECT * FROM noticia ORDER BY id DESC LIMIT ' . (($paginacion->get_page() - 1) * $resultados) . ', ' . $resultados);
  59. ?>
  60.        
  61.  
  62.  
  63. <div id="noticias">
  64.         <table width="100%" border="0" cellspacing="10" class="catnoticia">
  65.         <?php foreach ($noticias as $noticia): ?>
  66.     <tr>
  67.    
  68.     <td width="15%" valign="top"><img src="../imagenes/<?php echo $noticia->foto;?>"></td>
  69.     <td width="85%" valign="top">
  70.     <a href="../admin/ver-noticias.php?id=<?php echo $noticia->id;?>"><h1><?php echo $noticia->titulo;?></h1></a>
  71.     <p><?php echo $noticia->subtitulo;?></p>
  72.     </td>
  73.    
  74.   </tr>
  75.     <?php endforeach ?>
  76.     </table>
  77.         <?php
  78.         // render the pagination links
  79.         $paginacion->render();
  80.  
  81.         ?>
  82. </div>
  83.  
  84.  
  85. </body>
  86. </html>

Por favor necesito de su ayuda, soy muy novato en esto de programación. Desde ya muchas gracias a todos
  #2 (permalink)  
Antiguo 22/09/2014, 18:51
Avatar de Triby
Mod on free time
 
Fecha de Ingreso: agosto-2008
Ubicación: $MX->Gto['León'];
Mensajes: 10.106
Antigüedad: 15 años, 8 meses
Puntos: 2237
Respuesta: Como agregarle seguridad a mi web

Hay mucho trabajo por hacer, revisa esto: http://www.forosdelweb.com/f18/aport...a-php-1011808/
__________________
- León, Guanajuato
- GV-Foto
  #3 (permalink)  
Antiguo 23/09/2014, 07:32
Avatar de alealvaro  
Fecha de Ingreso: junio-2004
Ubicación: BA - Argentina
Mensajes: 210
Antigüedad: 19 años, 11 meses
Puntos: 12
Respuesta: Como agregarle seguridad a mi web

Creo que un buen paso que deberías tomar es aprender/aplicar el modelo MVC, y un buen camino para ello sería que comiences a utilizar algún framework. Tu código quedará más ordenado, y a la vez más protegido.
Podrías comenzar con CodeIgniter, te familiarizarás enseguida y te será sencillo rehacer tu código en ese framework.
Me cuentas y cualquier inquietud, avisas! :)
Saludos!
__________________
Always learning a little more...
Videos y frases para dedicar
Quotes and Phrases for You
  #4 (permalink)  
Antiguo 24/09/2014, 14:44
 
Fecha de Ingreso: junio-2012
Mensajes: 30
Antigüedad: 11 años, 10 meses
Puntos: 0
Respuesta: Como agregarle seguridad a mi web

Muchas gracias Triby, me sirvio el material que me pasaste, ahora tengo una idea de como darle seguridad a mi web, cualquier cosa te estare molestando si tengo alguna duda.
También muchas gracias alealvaro por tu consejo de usar un framework, ya he bajado el que me aconsejaste, CodeIgniter, como dije anteriormente te estare consultando si tengo alguna duda.

Etiquetas: html, mysql, seguridad, select, sql, tabla
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 12:46.