SQL Injection inside category creation (checkIfCategoryExists) in thorsten/phpmyfaq

Valid

Reported on

Oct 30th 2022


Description

A user with the permission to Add category can abuse this feature to execute his own SQL queries.

Proof of Concept

Static code analysis

The vulnerable php code is :

    public function checkIfCategoryExists(array $categoryData): int
    {
        $query = sprintf(
            "SELECT name from %sfaqcategories WHERE name = '%s' AND lang = '%s'",
            Database::getTablePrefix(),
            $categoryData['name'],
            $categoryData['lang']
        );

        $result = $this->config->getDb()->query($query);
        return $this->config->getDb()->numRows($result);
    }

The parameter name and lang are not escaped ! This leads to SQL injection.

False query

A false query will returns that "no category exists with this name", so it will create one as follows :

True query

A true query will returns that "the category already exists", so it will NOT create one :

The password hash for the user superadm is fdfff37a89b153..., so the first letter is f.

' OR 'f'=(SELECT SUBSTR(pass,1,1) FROM phpmyfaq_faquserlogin WHERE login='superadm') -- -

Impact

A user with the permission to add category can dump the whole database. It can use the data retrieved to get an administrator account. An attacker could also use mathematical functions to DDOS the SQL workers.

We are processing your report and will contact the thorsten/phpmyfaq team within 24 hours. a year ago
We have contacted a member of the thorsten/phpmyfaq team and are waiting to hear back a year ago
Thorsten Rinne validated this vulnerability a year ago
xanhacks has been awarded the disclosure bounty
The fix bounty is now up for grabs
The researcher's credibility has increased: +7
Thorsten Rinne
a year ago

Maintainer


Here's the fix: https://github.com/thorsten/phpMyFAQ/commit/137cc2bb9e48255931ee2f2a98803f7fd27edfd5

Thorsten Rinne marked this as fixed in 3.1.9 with commit 137cc2 a year ago
Thorsten Rinne has been awarded the fix bounty
This vulnerability will not receive a CVE
xanhacks
a year ago

Researcher


The fix looks good to me! Could we assign a CVE to this vulnerability ? @admin @maintainer

Thorsten Rinne gave praise a year ago
Yes, but it will take some days until I have time to release 3.1.9
The researcher's credibility has slightly increased as a result of the maintainer's thanks: +1
Thorsten Rinne published this vulnerability a year ago
xanhacks
a year ago

Researcher


Hey @maintainer @admin,

Could we assign a CVE to this vulnerability now ?

Best regards, xanhacks

Ben Harvie
10 months ago

Admin


Hey xanhacks, CVE assignment is in the hands of the maintainer, please refrain from tagging @admin's for this request. Thanks:)

to join this conversation