Описание
@saltcorn/server Remote Code Execution (RCE) / SQL injection via prototype pollution by manipulating lang and defstring parameters when setting localizer strings
Summary
The endpoint /site-structure/localizer/save-string/:lang/:defstring accepts two parameter values: lang and defstring. These values are used in an unsafe way to set the keys and value of the cfgStrings object. It allows to add/modify properties of the Object prototype that result in several logic issues, including:
- RCE vulnerabilities by polluting the
tempRootFolderproperty - SQL injection vulnerabilities by polluting the
schemaproperty when usingPostgreSQLdatabase.
Details
PoC
Setup:
- set
SALTCORN_NWORKERS=1before starting thesaltcornserver (to easily observe the behavior of the PoC)
- make sure to use PostgresSQL backend
- login with a user with admin permission
RCE
This PoC demonstrates how to escalate the Prototype Pollution vulnerability to change the behavior of certain command executed.
- check that the file that will be created does not exists:
- pollute the
Object.prototypewith atempRootFoldervalue set to;echo+"rce"|tee+/tmp/RCE;by sending the following request *** :
visit http://localhost:3000/plugins/new
- enter the following fields:
- Name:
test - Source:
git - other fields blank
- click
Create
- Name:
- you will get an error but the command
echo "rce" | tee /tmp/RCEwill be executed - to verify:
The RCE occurs because after the previous curl request, the tempRootFolder property is set to ;echo+"rce"|tee+/tmp/RCE; that is later used to build the shell commands.
SQL Injection
This PoC demonstrates how to escalate the Prototype Pollution vulnerability to change the behavior of certain SQL queries (i.e SQLi).
- visit
http://localhost:3000/tableto check the page returns some results (no errors) - pollute the
Object.prototypewith a schema value set to"(just to create an exception in the query that will be executed to demonstrate the issue) by sending the following request *** :
- visit again
http://localhost:3000/tablebut this time an SQL error will appear:
NOTE: Another payload to use as value could be pg_user"+WHERE+1=1+AND+(SELECT+pg_sleep(5))+IS+NOT+NULL+--
The SQL injection occurs because after the previous curl request, the schema property is set to ".
*** Retrieve valid values for the connect.sid (VALID_CONNECT_SID_COOKIE) and _csrf values (VALID_csrf_Value) :
- open the browser developer console and go to the
Networktab - visit
http://localhost:3000/site-structure/localizer/add-lang - add a language (
Name: test,Locale: test) and clickSave - under the
Networktab, filter forsave-langand check the request parameters (HeadersandPayload/Requesttabs) - copy the values for
connect.sidand_csrfand paste in the curl command above
Impact
Remote code execution (RCE), Sql injection and business logic errors.
Recommended Mitigation
Check the values of lang and defstring parameters against dangerous properties like __proto__, constructor, prototype.
Пакеты
@saltcorn/server
<= 1.0.0-beta.13
1.0.0-beta.14
7.3 High
CVSS4
7.2 High
CVSS3
Дефекты
7.3 High
CVSS4
7.2 High
CVSS3