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

Lack of escaping on some pages can lead to XSS exposure (CVE-2020-7106) #3191

Closed
0xfatty opened this issue Jan 15, 2020 · 21 comments
Closed
Labels
bug Undesired behaviour resolved A fixed issue SECURITY A security issue reported through CVE

Comments

@0xfatty
Copy link

0xfatty commented Jan 15, 2020

Describe the bug
Data source input validation error leads to Stored XSS within Description after creating a device with Malicious code embedded in Description field.

To Reproduce
Steps to reproduce the behavior:

  1. Navigate to Console -> Create -> New Device
  2. In Description field, input script payload: <svg/onload=alert(1)>
  3. Fill out the rest of the form as normal
  4. Click Save. After the first click, there will be an error dialog saying Whitelisting is ON (yes, I turned it on this time). However, I was still able to save the "New Device" form by clicking "Save" once again.
  5. After the message of "Successfully operated", click on "Data Sources" on the top right menu. XSS dialog will pop up.

You might ask me questions about CSP and the whitelisting thing in config.php:
If I turned the whitelisting feature ON? YES
If I fixed html.php to append CSP policy? YES

Screenshots

@0xfatty 0xfatty changed the title Data source Data source input validation error leads to Stored XSS within Description Jan 15, 2020
@0xfatty 0xfatty changed the title Data source input validation error leads to Stored XSS within Description Device Description input validation error leads to Stored XSS in data_sources.php Jan 15, 2020
@0xfatty
Copy link
Author

0xfatty commented Jan 15, 2020

Remediation

  • Tracing back to the code, I saw that the Description gets stored into DB. Then in data_sources.php line 1331-1332, $description takes that string (XSS) from database and then gets displayed in raw by the $header which then leads to Cross-site scripting.
  • Hence, to fix this, I would suggest to run $description through htmlspecialchars() to avoid XSS payloads.

Original:

$description = db_fetch_cell_prepared('SELECT description FROM host WHERE id = ?', array(get_request_var('host_id')));
$header = __('Data Sources [ %s ]', $description);

Suggestion:

$description = db_fetch_cell_prepared('SELECT description FROM host WHERE id = ?', array(get_request_var('host_id')));
$description = htmlspecialchars($description, ENT_QUOTES);
$header = __('Data Sources [ %s ]', $description);

@0xfatty 0xfatty changed the title Device Description input validation error leads to Stored XSS in data_sources.php Vulnerability report: Device Description input validation error leads to Stored XSS in data_sources.php Jan 15, 2020
@bmfmancini
Copy link
Member

Wow great catch sir!!

@netniV
Copy link
Member

netniV commented Jan 15, 2020

Thanks for your ongoing efforts to improve the code Chi, appreciated. If you already have a patch, you should submit it as a pull request so we can merge it. Since this is an XSS bug, if you could do that against the 1.2.x branch and include the CHANGELOG entry too, that would be perfect.

@0xfatty
Copy link
Author

0xfatty commented Jan 16, 2020

Hi @netniV

Thank you for your response. I am happy to do so.

@cigamit
Copy link
Member

cigamit commented Jan 16, 2020

Yea, I found a few more. Comitting shortly.

@cigamit
Copy link
Member

cigamit commented Jan 16, 2020

total files are:

  • data_sources.php
  • color_templates_item.php
  • graphs.php
  • graph_items.php
  • lib/api_automation.php
  • user_admin.php
  • user_group_admin.php

Bummer.

@cigamit cigamit changed the title Vulnerability report: Device Description input validation error leads to Stored XSS in data_sources.php Vulnerability report: Lack of escaping on some pages can lead to XSS exposure Jan 16, 2020
cigamit added a commit that referenced this issue Jan 16, 2020
* Vulnerability report: Lack of escaping on some pages can lead
to XSS exposure
* Also cleaning up additional copyrights
* Make the way filter headers are escaped consistent
@cigamit
Copy link
Member

cigamit commented Jan 16, 2020

Okay, just committed the fixes. That's from a pretty comprehensive audit.

@cigamit
Copy link
Member

cigamit commented Jan 16, 2020

@smutranchi, if you can get a CVE number for this, it would be appreciated.

@cigamit cigamit added bug Undesired behaviour SECURITY A security issue reported through CVE resolved A fixed issue labels Jan 16, 2020
@0xfatty
Copy link
Author

0xfatty commented Jan 16, 2020

Hi @cigamit ,

Thank you for your response. I have raised a CVE request. I will put it in here once I got the number.

Sincerely,
Chi Tran

@0xfatty
Copy link
Author

0xfatty commented Jan 16, 2020

Hi @netniV @cigamit,

A CVE was assigned to this bug as:
CVE-2020-7106.

Please let me know if you need any further information.

Best regards,
Chi Tran

@netniV
Copy link
Member

netniV commented Jan 16, 2020

If you can review the code change, that would add some validation to the fix. We will use the CVE in our notifications on the next release.

cigamit added a commit that referenced this issue Jan 17, 2020
@cigamit
Copy link
Member

cigamit commented Jan 17, 2020

A double review of the commit would be appreciated.

@0xfatty
Copy link
Author

0xfatty commented Jan 17, 2020

I have just pulled new commits from 1.2.x branch and started reviewing. I will let you guys know if I found anything else.

@hlef
Copy link

hlef commented Jan 18, 2020

@cigamit is can see that several lines in this diff are still missing the __esc:

e.g.

4cbb045#diff-317c61020ed4b560afa7e1760f261534R1155

or

4cbb045#diff-3398f8d2633c0b07fbd66bd7b8f75ecdR2018

Is it intentional ?

@cigamit
Copy link
Member

cigamit commented Jan 18, 2020

Yes, if you follow the code, those two strings are included in a subsequent __esc() further in.

@0xfatty
Copy link
Author

0xfatty commented Jan 19, 2020

Hi @cigamit ,

I noticed that when a report is created. In file lib/html_reports.php, function reports_generate_html() gets called with param $reports passed in.

Tracing back to lib/reports.php where reports_generate_html() function is declared, I observed that the report tables prints $reports[‘name’] in raw. (Line 707 reports.php)

Hence, if we send an XSS payload into field “Report Name”, it will still be executed when users navigate to tab Preview.

@cigamit
Copy link
Member

cigamit commented Jan 19, 2020

Good catch.

cigamit added a commit that referenced this issue Jan 19, 2020
One additional lack of proper exscaping of stored database value.
@cigamit
Copy link
Member

cigamit commented Jan 19, 2020

Okay, got that one caught now.

@0xfatty
Copy link
Author

0xfatty commented Jan 23, 2020

Hi @cigamit ,

I tried to trace from the Device description and got one more file that is affected.
After changing Device description to XSS payload, all graph names (title) will become |host description| - graph feature

image

Then if admin turns on WEBLOG, cli/clog_webapi.php would be still fetching $ds_title in raw which contains XSS payload.

image

And pop XSS diaglog when admin navigate to Logs tab from Menu bar

image

image

@0xfatty
Copy link
Author

0xfatty commented Jan 23, 2020

I have just also made a change to 1.2.x branch on clog_webapi.php file.

0xfatty pushed a commit to 0xfatty/cacti that referenced this issue Jan 23, 2020
@0xfatty 0xfatty mentioned this issue Jan 23, 2020
0xfatty pushed a commit to 0xfatty/cacti that referenced this issue Jan 23, 2020
@netniV
Copy link
Member

netniV commented Jan 23, 2020

Thanks again Chi, I'll take a look and see about submitting it.

netniV pushed a commit that referenced this issue Jan 23, 2020
@netniV netniV changed the title Vulnerability report: Lack of escaping on some pages can lead to XSS exposure Lack of escaping on some pages can lead to XSS exposure (CVE-2020-7106) Feb 10, 2020
TheWitness added a commit that referenced this issue Apr 16, 2020
Security: required more fixing like #3191((CVE-2020-7106))
@github-actions github-actions bot locked and limited conversation to collaborators Jun 30, 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

6 participants