Insufficient sanitizing can lead to arbitrary commands execution
Notepad++ fails to sanitise environment variable expansion in folder names when opening a command prompt, allowing an attacker to inject arbitrary commands. A crafted folder name containing a quote character can break out of the intended command and execute arbitrary code.
- Triaged in 34 hours
- Fixed in 43 days
- Paid in 37 days
- Disclosed after 4 months
##Information:
Summary: Notepad++ is vulnerable to a command injection attack.
Debug Info: Notepad++ v7.6.3 (32-bit) Build time : Jan 27 2019 - 17:20:30 Path : C:\Program Files (x86)\Notepad++\notepad++.exe Admin mode : ON Local Conf mode : OFF OS : Windows 10 (64-bit) Plugins : none
Description:
Let's look at this command execution for example in NppCommand.cpp:
case IDM_FILE_OPEN_CMD:
{
Command cmd(TEXT("cmd /K cd /d \"$(CURRENT_DIRECTORY)\""));
cmd.run(_pPublicInterface->getHSelf());
}
break;
\" have been introduced with commit 0f93670 to prevent RCE.
However it is still possible to inject arbitrary commands using environment variables. For example trying to open a folder named %TEST% will result in the expansion of the environment variable, if it contains a " then its possible to inject arbitrary commands after that " in the directory name.
Steps To Reproduce:
- Create a new environment variable (or a temporary one), let's name it
TESTand set its value:" - Create a new folder named
%TEST% && mkdir boomand create a text file in it, let's name that filetest.txt - Open
test.txtwith Notepad++ and click onFile->Open Containing Folder->cmd - The command in the folder name gets executed and the
boomfolder is created
Fix:
Escape %characters before executing the command: % -> ^%.
Impact
A successful attack can lead to arbitrary commands execution.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the application does not escape percent signs or quotes in folder names before passing them to the command shell, allowing environment variable expansion and command injection.
Impact
A successful attack can lead to arbitrary commands execution.
What the attacker needed
Ability to create a folder with a crafted name; ability to set an environment variable; victim opens the folder via Notepad++
How it was found
- Create an environment variable named TEST with the value a double quote.
- Create a folder named %TEST% && mkdir boom and place a text file inside.
- Open the text file in Notepad++ and use File->Open Containing Folder->cmd.
- The injected command executes and the boom folder is created.
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 report has not been written yet. The Original tab links to the source.
When you ask Notepad++ to open a command prompt in a folder, it builds a command using the folder's name. If the folder name contains special characters like a quote, the command can be broken and extra commands added. This lets someone run their own commands on your computer.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.