Skip to content

SQL Injection vulnerability when using tree rules through Automation API

Moderate
netniV published GHSA-gj3f-p326-gh8r May 12, 2024

Package

Cacti (PHP)

Affected versions

<= 1.2.26

Patched versions

1.2.27

Description

Summary

Some of the data stored in automation_tree_rules.php is not thoroughly checked and is used to concatenate the SQL statement in
create_all_header_nodes() function from lib/api_automation.php , finally resulting in SQL injection.

Details

1. store dirty data

The writing of dirty data can be done from automation_tree_rules_form_save() function in automation_tree_rules.php. This requires administrator privileges of Automation .
image
image

In the database, the field field of this table are controllable and all is set to varchar 255, which can inject a lot of content.
image

2. read and use dirty data to concatenate the SQL statement

The attack starts with the form_action() function in host.php. Calling automation_update_device() function.
image

Alternatively, starting from the form_action() function in graphs.php . Calling automation_execut_graph_create_tree() function.
image

These two methods require administrator privileges respectively: Sites/Devices/Data, Graphs.
image

Finally arriving at lib/api.automation.php. when reading the field data of automation_tree_rule_items in database, variable $sql is not checked and concatenated directly, resulting in SQL injection.
image
image

PoC

1. store dirty data

POST access automation_tree_rules.php and submit the following data:

  • 'save_component_automation_tree_rule_item' => 1,
  • 'item_id'=>1,
  • 'id'=>1,
  • 'sequence'=>100,
  • 'field'=>"1;INSERT INTO plugin_hooks VALUES (3,'a','a','../../myVul/FileIncludeofgraph_image/test.php','.','a');#",
  • 'sort_type'=>1,
  • 'search_pattern'=>'TAINT',
  • 'action'=>'save',
  • '__csrf_magic'=> ''
    check field in automation_match_rule_items table.
    image

2. use dirty data to concatenate the SQL statement

GET access : "http://ip:port/host.php?action=actions&drp_action=6&selected_items=[1]".
image

Impact

Using SQL based secondary injection technology, attackers can modify the contents of the Cacti database, and based on the modified content, it may be possible to achieve further impact, such as arbitrary file reading, and even remote code execution through arbitrary file writing.

Researcher: ISHGARD-2, USTC

Severity

Moderate

CVE ID

CVE-2024-31460

Weaknesses

No CWEs

Credits