Overview
| Artifact ID: | ba8f4fe0b6a9c3a89d5f12c717f3235406171243e0c3236750bb09501d015a5d |
|---|---|
| Ticket: | 21b0629c81fbe38ad153cd8fd899626200a66e15
0-day vulnerability - insufficient escape by exec of batch-files for windows |
| User & Date: | sebres on 2018-08-17 13:09:03 |
Changes
- assignee changed to: "nobody"
- closer changed to: "nobody"
- cmimetype changed to: "text/x-fossil-wiki"
- comment changed to:
0-day vulnerability in tcl-exec (for win) by calling of batch-files resp. default windows command processor. <code><pre style="padding-left:10pt"> % exec cmd /c echo {test&whoami} <b style="color:green"> "test&whoami" </b> % exec cmd /c echo {test"&whoami} <b style="color:red"> "test\" my_domain\sebres</b> </pre></code> Rather it is a matter the weird windows unescape behavior in case of command processor,<br/>therefore almost everything else beside Tcl is affected by same vulnerability also similar way. For example python (for win): <code><pre style="padding-left:10pt"> >>> subprocess.call(["cmd", "/c", "echo", 'test"&whoami']) <b style="color:red"> "test\" my_domain\sebres</b> </pre></code> Thanks to Peter (resuna) for link to <a href="https://blogs.msdn.microsoft.com/twistylittlepassagesallalike/2011/04/23/everyone-quotes-command-line-arguments-the-wrong-way/">discussion</a> It looks like the arguments containing unpaired quote-chars somewhere will cause processing of the special meta-characters, so it should be extra escaped using tripple circumflex but only for unpaired quote-chars (by paired quotes it remains the meta-char as well as <code>^^^</code> sequence). For more extensive PoC I wrote a small helper dumping arguments (here <code>test-dump.exe</code>) as well as small batch (<code>test-dump.cmd</code>) doing the same: <code><pre style="padding-left:10pt"> @pushd %~dp0 @rem echo %* @test-dump.exe %* @popd </pre></code> And following tcl-script: <code><pre style="padding-left:10pt"> </pre></code> The results: <code><pre style="padding-left:10pt"> % source test-dump.tcl -------------------- <b>* 1) ‘test-dump.exe’ ‘test&whoami’</b> 0: [test-dump.exe] 1: [test&whoami] <b>* 1) ‘test-dump.CMD’ ‘test&whoami’</b> 0: [test-dump.exe] 1: [test&whoami] -------------------- <b>* 2) ‘test-dump.exe’ ‘test|whoami’</b> 0: [test-dump.exe] 1: [test|whoami] <b>* 2) ‘test-dump.CMD’ ‘test|whoami’</b> <b style="color:red"> my_domain\sebres</b> -------------------- <b>* 3) ‘test-dump.exe’ ‘"test&whoami’</b> 0: [test-dump.exe] 1: ["test&whoami] <b>* 3) ‘test-dump.CMD’ ‘"test&whoami’</b> <b style="color:red"> 0: [test-dump.exe] 1: ["test] my_domain\sebres</b> -------------------- <b>* 4) ‘test-dump.exe’ ‘"test|whoami’</b> 0: [test-dump.exe] 1: ["test|whoami] <b>* 4) ‘test-dump.CMD’ ‘"test|whoami’</b> 0: [test-dump.exe] 1: ["test|whoami] -------------------- <b>* 5) ‘test-dump.exe’ ‘test"&whoami’</b> 0: [test-dump.exe] 1: [test"&whoami] <b>* 5) ‘test-dump.CMD’ ‘test"&whoami’</b> <b style="color:red"> 0: [test-dump.exe] 1: [test"] my_domain\sebres</b> -------------------- <b>* 6) ‘test-dump.exe’ ‘test"|whoami’</b> 0: [test-dump.exe] 1: [test"|whoami] <b>* 6) ‘test-dump.CMD’ ‘test"|whoami’</b> 0: [test-dump.exe] 1: [test"|whoami] -------------------- <b>* 7) ‘test-dump.exe’ ‘"test"&whoami’</b> 0: [test-dump.exe] 1: ["test"&whoami] <b>* 7) ‘test-dump.CMD’ ‘"test"&whoami’</b> 0: [test-dump.exe] 1: ["test"&whoami] -------------------- <b>* 8) ‘test-dump.exe’ ‘"test"|whoami’</b> 0: [test-dump.exe] 1: ["test"|whoami] <b>* 8) ‘test-dump.CMD’ ‘"test"|whoami’</b> <b style="color:red"> my_domain\sebres</b> -------------------- <b>* 9) ‘test-dump.exe’ ‘""test"&whoami’</b> 0: [test-dump.exe] 1: [""test"&whoami] <b>* 9) ‘test-dump.CMD’ ‘""test"&whoami’</b> <b style="color:red"> 0: [test-dump.exe] 1: [""test"] my_domain\sebres</b> -------------------- <b>* 10) ‘test-dump.exe’ ‘""test"|whoami’</b> 0: [test-dump.exe] 1: [""test"|whoami] <b>* 10) ‘test-dump.CMD’ ‘""test"|whoami’</b> 0: [test-dump.exe] 1: [""test"|whoami] % </pre></code> The major injury is happened by processing of the arguments containing quotes, but some tests show that Tcl seems to have here additionally insufficient escaping by some special characters like pipe (at least looks like vulnerable arguments-handling, also by execution of some tests without unpaired quotes, see for example test 2 and completely another behavior compared to ampersand-character, see tests 9/10, where args of test 10 seems to be not affected in opposite to test 9 with the same quote-chars state inside argument). WiP. I have almost fixed this for Tcl >= 8.5, working on test-cases and review, so coming soon. - foundin changed to: "all (win)"
- is_private changed to: "0"
- login: "sebres"
- priority changed to: "5 Medium"
- resolution changed to: "None"
- severity changed to: "Critical"
- status changed to: "Open"
- submitter changed to: "sebres"
- subsystem changed to: "16. Commands A-H"
- title changed to:
0-day vulnerability - insufficient escape by exec of batch-files for windows
- type changed to: "Bug"