e04c03e
------------------------------------------------------------------------
e04c03e
r7439 | rony | 2014-03-30 17:52:10 -0500 (Sun, 30 Mar 2014) | 5 lines
e04c03e
e04c03e
bug#0002405: SQL injection in graph_xport.php
e04c03e
e04c03e
 - Fixed form input validation problems
e04c03e
 - Fixed rrd export and graph shell escape issues
e04c03e
e04c03e
------------------------------------------------------------------------
e04c03e
Index: branches/0.8.8/graph_xport.php
e04c03e
===================================================================
e04c03e
--- branches/0.8.8/graph_xport.php	(revision 7438)
e04c03e
+++ branches/0.8.8/graph_xport.php	(revision 7439)
e04c03e
@@ -47,43 +47,48 @@
e04c03e
 
e04c03e
 $graph_data_array = array();
e04c03e
 
e04c03e
+/* ================= input validation ================= */
e04c03e
+input_validate_input_number(get_request_var("local_graph_id"));
e04c03e
+input_validate_input_number(get_request_var("rra_id"));
e04c03e
+/* ==================================================== */
e04c03e
+
e04c03e
 /* override: graph start time (unix time) */
e04c03e
-if (!empty($_GET["graph_start"]) && $_GET["graph_start"] < 1600000000) {
e04c03e
-	$graph_data_array["graph_start"] = $_GET["graph_start"];
e04c03e
+if (!empty($_GET["graph_start"]) && is_numeric($_GET["graph_start"] && $_GET["graph_start"] < 1600000000)) {
e04c03e
+	$graph_data_array["graph_start"] = get_request_var("graph_start");
e04c03e
 }
e04c03e
 
e04c03e
 /* override: graph end time (unix time) */
e04c03e
-if (!empty($_GET["graph_end"]) && $_GET["graph_end"] < 1600000000) {
e04c03e
-	$graph_data_array["graph_end"] = $_GET["graph_end"];
e04c03e
+if (!empty($_GET["graph_end"]) && is_numeric($_GET["graph_end"]) && $_GET["graph_end"] < 1600000000) {
e04c03e
+	$graph_data_array["graph_end"] = get_request_var("graph_end");
e04c03e
 }
e04c03e
 
e04c03e
 /* override: graph height (in pixels) */
e04c03e
-if (!empty($_GET["graph_height"]) && $_GET["graph_height"] < 3000) {
e04c03e
-	$graph_data_array["graph_height"] = $_GET["graph_height"];
e04c03e
+if (!empty($_GET["graph_height"]) && is_numeric($_GET["graph_height"]) && $_GET["graph_height"] < 3000) {
e04c03e
+	$graph_data_array["graph_height"] = get_request_var("graph_height");
e04c03e
 }
e04c03e
 
e04c03e
 /* override: graph width (in pixels) */
e04c03e
-if (!empty($_GET["graph_width"]) && $_GET["graph_width"] < 3000) {
e04c03e
-	$graph_data_array["graph_width"] = $_GET["graph_width"];
e04c03e
+if (!empty($_GET["graph_width"]) && is_numeric($_GET["graph_width"]) && $_GET["graph_width"] < 3000) {
e04c03e
+	$graph_data_array["graph_width"] = get_request_var("graph_width");
e04c03e
 }
e04c03e
 
e04c03e
 /* override: skip drawing the legend? */
e04c03e
 if (!empty($_GET["graph_nolegend"])) {
e04c03e
-	$graph_data_array["graph_nolegend"] = $_GET["graph_nolegend"];
e04c03e
+	$graph_data_array["graph_nolegend"] = get_request_var("graph_nolegend");
e04c03e
 }
e04c03e
 
e04c03e
 /* print RRDTool graph source? */
e04c03e
 if (!empty($_GET["show_source"])) {
e04c03e
-	$graph_data_array["print_source"] = $_GET["show_source"];
e04c03e
+	$graph_data_array["print_source"] = get_request_var("show_source");
e04c03e
 }
e04c03e
 
e04c03e
-$graph_info = db_fetch_row("SELECT * FROM graph_templates_graph WHERE local_graph_id='" . $_REQUEST["local_graph_id"] . "'");
e04c03e
+$graph_info = db_fetch_row("SELECT * FROM graph_templates_graph WHERE local_graph_id='" . get_request_var("local_graph_id") . "'");
e04c03e
 
e04c03e
 /* for bandwidth, NThPercentile */
e04c03e
 $xport_meta = array();
e04c03e
 
e04c03e
 /* Get graph export */
e04c03e
-$xport_array = @rrdtool_function_xport($_GET["local_graph_id"], $_GET["rra_id"], $graph_data_array, $xport_meta);
e04c03e
+$xport_array = @rrdtool_function_xport($_GET["local_graph_id"], get_request_var("rra_id"), $graph_data_array, $xport_meta);
e04c03e
 
e04c03e
 /* Make graph title the suggested file name */
e04c03e
 if (is_array($xport_array["meta"])) {
e04c03e
Index: branches/0.8.8/lib/rrd.php
e04c03e
===================================================================
e04c03e
--- branches/0.8.8/lib/rrd.php	(revision 7438)
e04c03e
+++ branches/0.8.8/lib/rrd.php	(revision 7439)
e04c03e
@@ -865,13 +865,13 @@
e04c03e
 	/* basic graph options */
e04c03e
 	$graph_opts .=
e04c03e
 		"--imgformat=" . $image_types{$graph["image_format_id"]} . RRD_NL .
e04c03e
-		"--start=$graph_start" . RRD_NL .
e04c03e
-		"--end=$graph_end" . RRD_NL .
e04c03e
+		"--start=" . cacti_escapeshellarg($graph_start) . RRD_NL .
e04c03e
+		"--end=" . cacti_escapeshellarg($graph_end) . RRD_NL .
e04c03e
 		"--title=" . cacti_escapeshellarg($graph["title_cache"]) . RRD_NL .
e04c03e
 		"$rigid" .
e04c03e
-		"--base=" . $graph["base_value"] . RRD_NL .
e04c03e
-		"--height=$graph_height" . RRD_NL .
e04c03e
-		"--width=$graph_width" . RRD_NL .
e04c03e
+		"--base=" . cacti_escapeshellarg($graph["base_value"]) . RRD_NL .
e04c03e
+		"--height=" . cacti_escapeshellarg($graph_height) . RRD_NL .
e04c03e
+		"--width=" . cacti_escapeshellarg($graph_width) . RRD_NL .
e04c03e
 		"$scale" .
e04c03e
 		"$unit_value" .
e04c03e
 		"$unit_exponent_value" .
e04c03e
@@ -1606,8 +1606,8 @@
e04c03e
 
e04c03e
 	/* basic export options */
e04c03e
 	$xport_opts =
e04c03e
-		"--start=$xport_start" . RRD_NL .
e04c03e
-		"--end=$xport_end" . RRD_NL .
e04c03e
+		"--start=" . cacti_escapeshellarg($xport_start) . RRD_NL .
e04c03e
+		"--end=" . cacti_escapeshellarg($xport_end) . RRD_NL .
e04c03e
 		"--maxrows=10000" . RRD_NL;
e04c03e
 
e04c03e
 	$xport_defs = "";
e04c03e
@@ -1997,7 +1997,7 @@
e04c03e
 			$stacked_columns["col" . $j] = ($graph_item_types{$xport_item["graph_type_id"]} == "STACK") ? 1 : 0;
e04c03e
 			$j++;
e04c03e
 
e04c03e
-			$txt_xport_items .= "XPORT:" . $data_source_name . ":" . str_replace(":", "", cacti_escapeshellarg($legend_name)) ;
e04c03e
+			$txt_xport_items .= "XPORT:" . cacti_escapeshellarg($data_source_name) . ":" . str_replace(":", "", cacti_escapeshellarg($legend_name)) ;
e04c03e
 		}else{
e04c03e
 			$need_rrd_nl = FALSE;
e04c03e
 		}