LibreOffice Arbitrary File Write (CVE-2023-1883)
LibreOffice Base allowed an attacker to write arbitrary files by embedding a malicious SQL SCRIPT statement in the database/script file of an .odb document. When the victim opened the document and clicked on the Queries button, the SCRIPT command executed and wrote a file to a path of the attacker's choosing, potentially leading to code execution if a file like ~/.bash_aliases was overwritten.
Published on secfault-security.com
During our internal research, we’ve decided to take a look at the LibreOffice suite, because.. why not?
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the database engine (HSQLDB) executed SQL statements from the untrusted database/script file without restricting the SCRIPT command's ability to write to arbitrary filesystem paths.
Impact
An attacker could write arbitrary files to the victim's filesystem, potentially leading to code execution if a file like ~/.bash_aliases is overwritten, but the exploit requires the victim to open a malicious .odb file and click the Queries button, and the written file must not already exist.
What the attacker needed
Victim opens a malicious .odb file; victim clicks the Queries button; target file must not already exist
The fix
The issue was fixed by LibreOffice and HSQLDB teams, likely by restricting the SCRIPT command or sanitising the database/script file.
How it was found
- Create a new LibreOffice Base database and save it as an .odb file.
- Unzip the .odb file and edit the database/script file to include a SCRIPT statement pointing to a target file path.
- Re-zip the directory structure into a new .odb file.
- Open the .odb file in LibreOffice and click on the 'Queries' button to trigger execution of the SQL statements.
- Observe that the target file is created with the contents of the database/script file.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
LibreOffice Base is a database program. It stores its data in a file that is actually a zip archive. Inside that archive, a file called database/script contains SQL commands. The program runs these commands when you click certain buttons. The researcher found that one SQL command, SCRIPT, can write a file to any location on your computer. By crafting a malicious .odb file, an attacker could make the program write a file, such as a startup script, that would run code when you next log in.
What is File upload?
An upload feature accepts a file that the server or other users' browsers then treat as code or as something trusted.