-
Notifications
You must be signed in to change notification settings - Fork 29
security: fix SQLi, XSS, credential exposure, and insecure deserialization #322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -746,7 +746,6 @@ function mactrack_device_import_processor(&$devices) { | |||||||||||||||||
| if (cacti_sizeof($line_array)) { | ||||||||||||||||||
| foreach ($line_array as $line_item) { | ||||||||||||||||||
| if (in_array($j, $insert_columns, true)) { | ||||||||||||||||||
| $line_item = trim(str_replace("'", '', $line_item)); | ||||||||||||||||||
| $line_item = trim(str_replace('"', '', $line_item)); | ||||||||||||||||||
|
|
||||||||||||||||||
| if (!$first_column) { | ||||||||||||||||||
|
|
@@ -759,15 +758,15 @@ function mactrack_device_import_processor(&$devices) { | |||||||||||||||||
| if ($sql_where != '') { | ||||||||||||||||||
| switch($j) { | ||||||||||||||||||
| case $save_site_id_id: | ||||||||||||||||||
| $sql_where .= " AND site_id='$line_item'"; | ||||||||||||||||||
| $sql_where .= ' AND site_id=' . db_qstr($line_item); | ||||||||||||||||||
|
|
||||||||||||||||||
| break; | ||||||||||||||||||
| case $save_snmp_port_id: | ||||||||||||||||||
| $sql_where .= " AND snmp_port='$line_item'"; | ||||||||||||||||||
| $sql_where .= ' AND snmp_port=' . db_qstr($line_item); | ||||||||||||||||||
|
|
||||||||||||||||||
| break; | ||||||||||||||||||
| case $save_host_id: | ||||||||||||||||||
| $sql_where .= " AND hostname='$line_item'"; | ||||||||||||||||||
| $sql_where .= ' AND hostname=' . db_qstr($line_item); | ||||||||||||||||||
|
|
||||||||||||||||||
| break; | ||||||||||||||||||
| default: | ||||||||||||||||||
|
|
@@ -776,15 +775,15 @@ function mactrack_device_import_processor(&$devices) { | |||||||||||||||||
| } else { | ||||||||||||||||||
| switch($j) { | ||||||||||||||||||
| case $save_site_id_id: | ||||||||||||||||||
| $sql_where .= "WHERE site_id='$line_item'"; | ||||||||||||||||||
| $sql_where .= 'WHERE site_id=' . db_qstr($line_item); | ||||||||||||||||||
|
|
||||||||||||||||||
| break; | ||||||||||||||||||
| case $save_snmp_port_id: | ||||||||||||||||||
| $sql_where .= "WHERE snmp_port='$line_item'"; | ||||||||||||||||||
| $sql_where .= 'WHERE snmp_port=' . db_qstr($line_item); | ||||||||||||||||||
|
|
||||||||||||||||||
| break; | ||||||||||||||||||
| case $save_host_id: | ||||||||||||||||||
| $sql_where .= "WHERE hostname='$line_item'"; | ||||||||||||||||||
| $sql_where .= 'WHERE hostname=' . db_qstr($line_item); | ||||||||||||||||||
|
|
||||||||||||||||||
| break; | ||||||||||||||||||
| default: | ||||||||||||||||||
|
|
@@ -809,7 +808,7 @@ function mactrack_device_import_processor(&$devices) { | |||||||||||||||||
| $device_name = $line_item; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| $save_value .= "'" . $line_item . "'"; | ||||||||||||||||||
| $save_value .= db_qstr($line_item); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| $j++; | ||||||||||||||||||
|
|
@@ -935,10 +934,10 @@ function mactrack_device_edit() { | |||||||||||||||||
| $snmp_objid = str_replace('OID: ', '', $snmp_objid); | ||||||||||||||||||
| $snmp_objid = str_replace('.iso', '.1', $snmp_objid); | ||||||||||||||||||
|
|
||||||||||||||||||
| print '<strong>' . __('System:', 'mactrack') . "</strong> $snmp_system<br>\n"; | ||||||||||||||||||
| print '<strong>' . __('Uptime:', 'mactrack') . "</strong> $snmp_uptime<br>\n"; | ||||||||||||||||||
| print '<strong>' . __('Hostname:', 'mactrack') . "</strong> $snmp_hostname<br>\n"; | ||||||||||||||||||
| print '<strong>' . __('ObjectID:', 'mactrack') . "</strong> $snmp_objid<br>\n"; | ||||||||||||||||||
| print '<strong>' . __('System:', 'mactrack') . '</strong> ' . html_escape($snmp_system) . "<br>\n"; | ||||||||||||||||||
| print '<strong>' . __('Uptime:', 'mactrack') . '</strong> ' . html_escape($snmp_uptime) . "<br>\n"; | ||||||||||||||||||
| print '<strong>' . __('Hostname:', 'mactrack') . '</strong> ' . html_escape($snmp_hostname) . "<br>\n"; | ||||||||||||||||||
| print '<strong>' . __('ObjectID:', 'mactrack') . '</strong> ' . html_escape($snmp_objid) . "<br>\n"; | ||||||||||||||||||
| } | ||||||||||||||||||
| ?> | ||||||||||||||||||
| </span> | ||||||||||||||||||
|
|
@@ -973,9 +972,9 @@ function mactrack_device_edit() { | |||||||||||||||||
| function mactrack_get_devices(&$sql_where, $rows, $apply_limits = true) { | ||||||||||||||||||
| // form the 'where' clause for our main sql query | ||||||||||||||||||
| if (get_request_var('filter') != '') { | ||||||||||||||||||
| $sql_where = ($sql_where != '' ? ' AND ' : 'WHERE ') . "(mtd.hostname like '%" . get_request_var('filter') . "%' | ||||||||||||||||||
| OR mtd.device_name like '%" . get_request_var('filter') . "%' | ||||||||||||||||||
| OR mtd.notes like '%" . get_request_var('filter') . "%')"; | ||||||||||||||||||
| $sql_where = ($sql_where != '' ? ' AND ' : 'WHERE ') . "(mtd.hostname LIKE " . db_qstr('%' . get_request_var('filter') . '%') . " | ||||||||||||||||||
| OR mtd.device_name LIKE " . db_qstr('%' . get_request_var('filter') . '%') . " | ||||||||||||||||||
| OR mtd.notes LIKE " . db_qstr('%' . get_request_var('filter') . '%') . ")"; | ||||||||||||||||||
|
Comment on lines
+975
to
+977
|
||||||||||||||||||
| $sql_where = ($sql_where != '' ? ' AND ' : 'WHERE ') . "(mtd.hostname LIKE " . db_qstr('%' . get_request_var('filter') . '%') . " | |
| OR mtd.device_name LIKE " . db_qstr('%' . get_request_var('filter') . '%') . " | |
| OR mtd.notes LIKE " . db_qstr('%' . get_request_var('filter') . '%') . ")"; | |
| $filter = db_qstr('%' . get_request_var('filter') . '%'); | |
| $sql_where = ($sql_where != '' ? ' AND ' : 'WHERE ') . | |
| '(mtd.hostname LIKE ' . $filter . | |
| ' OR mtd.device_name LIKE ' . $filter . | |
| ' OR mtd.notes LIKE ' . $filter . ')'; |
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -88,7 +88,12 @@ function form_actions() { | |||||||||||||||
|
|
||||||||||||||||
| // if we are to save this form, instead of display it | ||||||||||||||||
| if (isset_request_var('selected_items')) { | ||||||||||||||||
| $selected_items = unserialize(get_nfilter_request_var('selected_items')); | ||||||||||||||||
| $selected_items = cacti_unserialize(stripslashes(get_nfilter_request_var('selected_items'))); | ||||||||||||||||
|
|
||||||||||||||||
| if (!is_array($selected_items)) { | ||||||||||||||||
| header('Location: mactrack_view_macs.php'); | ||||||||||||||||
| exit; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
|
Comment on lines
+91
to
97
|
||||||||||||||||
| $selected_items = cacti_unserialize(stripslashes(get_nfilter_request_var('selected_items'))); | |
| if (!is_array($selected_items)) { | |
| header('Location: mactrack_view_macs.php'); | |
| exit; | |
| } | |
| $selected_items = sanitize_unserialize_selected_items(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as the device import: this CSV import logic strips all double quotes from fields and depends on a simplistic comma split earlier, which will corrupt valid CSV containing quoted fields, embedded commas, or escaped quotes. Consider using a proper CSV parser (
str_getcsv()/fgetcsv()) and removing the blanket quote stripping so imports are correct and predictable.