PHP - Ayuda con XSS

 
Vista:

Ayuda con XSS

Publicado por Dani (11 intervenciones) el 19/09/2015 05:49:59
Tengo un script de php de web de música y tengo una caja de búsqueda de canciones. El problema es que al escrbir un script para probar la vulnerabilidad xss me doy cuenta que mi web es vulnerable. ¿Cómo puedo proteger ante esa vulnerabilidad? No tengo mucho conocimiento de códigos. Os dejo el código php del cuadro de búsqueda de mi web.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
 
// Load System files
require_once "load.php";
 
 
if(!empty($_GET['q'])){
 
    // Get search query
    define("search_query" , stripslashes(strip_tags(urlencode($_GET['q']))));
    define("title2" , lng_title_search);
 
    $page = $GLOBALS["pagination"]->search(search_query);
    $search_result    = $GLOBALS["get"]->get_rows_search(search_query, $page[0], $page[1]);
    $pagination_print = $page[2];
    $search_count     = $page[3];
    // check rows if not empty
    $check_row = $search_result[0]->kind;
 
 
        if(!empty($check_row)){
 
            define("not_found", false);
 
            // load template
            require("template/search.php");
 
 
        } else {
 
            define("not_found", true);
 
            // load template
            require("template/search.php");
 
        }
} else {
 
// redirect to 404 page if empty
header("location: ".$GLOBALS["sys"]->get_url()."page/404");
 
}
?>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de xve
Val: 3.943
Oro
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

Ayuda con XSS

Publicado por xve (6935 intervenciones) el 19/09/2015 18:51:57
Hola Dani, aquí no veo las consultas SQL... faltaría ver el contenido de la función get_rows_search() para ver como hace la consulta a la base de datos.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Ayuda con XSS

Publicado por dani (11 intervenciones) el 19/09/2015 21:12:53
Hola xve!! No entiendo mucho pero te dejo tambien la plantilla del buscador por si encuentras eso que dices:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<? if(!$_SERVER['HTTP_X_PJAX']){  require_once("header.php"); } ?>
<? if($_SERVER['HTTP_X_PJAX']){  echo"<title>"; ?><? echo title1; ?> - <? echo title2; ?><? echo "</title>"; }  ?>
        <div id="on-fixed"  class="container">
<? if( text_align=='left' ){ ?>
          <h2>
            <a class="pjaxer"  href="<? echo url; ?>"><i class="icon-arrow-<? echo text_align; ?>-3 fg-darker smaller"></i></a>
			<? echo lng_title_search; ?><small class="on-right"><i  style="background: <? echo style_color; ?>;color: white; padding: 5px; border-radius: 50%" class="icon-search" ></i></small>
          </h2>
<?} elseif( text_align=='right' ){ ?>
          <h2>
		    <small class="on-left"><i style="background: <? echo style_color; ?>;color: white; padding: 5px; border-radius: 50%" class="icon-search" ></i></small><? echo lng_title_search; ?>
            <a class="pjaxer"  href="<? echo url; ?>"><i class="icon-arrow-<? echo text_align; ?>-3 fg-darker smaller"></i></a>
          </h2>
<? } ?>
            <? $head_check = setting_head_html; if( !empty($head_check) ){ ?>
			<div class="panel" >
		    <div class="panel-content" >
			<? echo setting_head_html; ?>
			</div>
			</div>
			<? } ?>
		   <div class="panel" >
		   <div class="panel-content" >
<? if(!not_found){ ?>
<? echo lng_label_search_count_1." ".$search_count." ".lng_label_search_count_2; ?>
<hr>
<?  foreach($search_result as $search){ ?>
     <? if($search->streamable=="true"){ ?>
		<div class="search-result border" >
		<div class="no-tablet-portrait no-phone" >
		</div>
		<div class="search-image" >
        <div class="tile">
            <div class="tile-content image">
			<a href="<? echo $GLOBALS["sys"]->get_url("track", $search->permalink."-".$search->id); ?>" class="pjaxer" >
                <img src="<? echo $GLOBALS["sys"]->img($search->artwork_url, "100", $search->user->avatar_url); ?>" height="120" width="120">
			</a>
            </div>
            <div class="brand">
                <span style="float: left;" class="label fg-white"><? echo $GLOBALS["sys"]->get_views($search->playback_count, $search->comment_count); ?></span>
                <span class="badge bg-<? echo style; ?>"><i class="icon-music fg-white"></i></span>
            </div>
        </div>
		</div>
		<a href="<? echo $GLOBALS["sys"]->get_url("track", $search->permalink."-".$search->id); ?>" class="pjaxer no-desktop" ><h3 class="search-title" ><? echo $GLOBALS["sys"]->sh_title(urldecode($search->title), "25"); ?>.</h3></a>
		<a href="<? echo $GLOBALS["sys"]->get_url("track", $search->permalink."-".$search->id); ?>" class="pjaxer no-tablet-portrait no-phone" ><h2 class="search-title" ><? echo $GLOBALS["sys"]->sh_title(urldecode($search->title), "50"); ?></h2></a>
		<div class="rating small no-margin fg-<? echo style; ?>" style="float: <? echo text_align; ?>; width: auto;">
		    <ul>
            <? echo $GLOBALS["sys"]->get_stars($search->playback_count); ?>
           </ul>
		</div><hr>
		<div class="search-buttons" >
		<!-- ON DESKTOP -->
        <a class="no-tablet-portrait no-phone button primary" onclick="data_update('<? echo $GLOBALS["sys"]->to_http($search->waveform_url); ?>', '<? echo $search->id; ?>', '<? echo $search->user->id; ?>', '<? echo str_replace("'", "", urldecode($search->title)); ?>')" href="javascript:void(0);" title="<? echo lng_btn_play; ?>" ><i class="icon-play" ></i><? echo lng_btn_play; ?></a>
		<a onclick="open_select_playlist('<? echo $search->id; ?>');" class="no-tablet-portrait no-phone button warning" title="<? echo lng_btn_add_playlist; ?>" ><i  class="icon-playlist" ></i><? echo lng_btn_add_playlist; ?></a>
		<a onclick="addtofavorites(<? echo $search->id; ?>);" class="no-tablet-portrait no-phone button info no-phone" title="<? echo lng_btn_add_favorites; ?>" ><i class="icon-star" ></i><? echo lng_btn_add_favorites; ?></a>
		<a class="no-tablet-portrait no-phone button success" onclick="open_download('<? echo $GLOBALS["sys"]->get_url(); ?>download.php?download=<? echo $search->id; ?>', '<? echo download_mode; ?>');" title="<? echo lng_btn_download; ?>" ><i class="icon-box-add" ></i><? echo lng_btn_download; ?></a>
		<!-- ON PHONE OR TABLET -->
        <a class="no-desktop button primary" onclick="data_update('<? echo $GLOBALS["sys"]->to_http($search->waveform_url); ?>', '<? echo $search->id; ?>', '<? echo $search->user->id; ?>', '<? echo str_replace("'", "", urldecode($search->title)); ?>')" href="javascript:void(0);" title="<? echo lng_btn_play; ?>" ><i class="icon-play" ></i>  </a>
		<a onclick="open_select_playlist('<? echo $search->id; ?>');" class="no-desktop button warning" title="<? echo lng_btn_add_playlist; ?>" ><i  class="icon-playlist" ></i>  +  </a>
		<a onclick="addtofavorites(<? echo $search->id; ?>);" class="no-desktop button info no-phone" title="<? echo lng_btn_add_favorites; ?>" ><i class="icon-star" ></i> + </a>
		<a class="no-desktop button success" onclick="open_download('<? echo $GLOBALS["sys"]->get_url(); ?>download.php?download=<? echo $search->id; ?>', 'direct');" title="<? echo lng_btn_download; ?>" ><i class="icon-box-add" ></i>  </a>
		<!-- ON DESKTOP -->
		<a href="<? echo $GLOBALS["sys"]->get_url("artist", $search->user->permalink); ?>" class="pjaxer no-tablet-portrait no-phone button danger" title="<? echo $search->user->username; ?>" > <i class="icon-user-2" ></i>  </a>
		</div>
		</div>
		<div style="clear: both;"></div>
	<?  } ?>
<? } ?>
<hr>
<div class="pagination">
<? echo $pagination_print; ?>
</div>
<? }else{ ?>
           <center style="margin-top: 40px;" >
		   <h3><? echo lng_alert_error_not_found; ?> <i class="icon-info"></i> </h3>
		   </center><div style="margin-top: 40px;" ></div>
<? } ?>
		   </div>
		   </div>
            <? $footer_check = setting_footer_html; if(!empty($footer_check)){ ?>
			<div class="panel" >
		    <div class="panel-content" >
			<? echo setting_footer_html; ?>
			</div>
			</div>
			<? } ?>
        </div>
<? if(!$_SERVER['HTTP_X_PJAX']){  require_once("footer.php"); } ?>
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Miguel Angel

Ayuda con XSS

Publicado por Miguel Angel (13 intervenciones) el 20/09/2015 19:55:54
Utiliza un framework y te ahorras muchos dolores de cabeza. Uno bueno y fácil de usar es codeigniter. Caso contrario revisa bien las consultas, ahí es donde inyecta código, o usa pdo para las consultas.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar