Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: e5efe114aa4ed46a96e2fb2789787b032793162449e713eb7208135a7d4fd994
Ticket: 344b1a0c0f0e2fda1e4ad6520cbf5e0af35eb332
exec on Windows broken when '%' is used
User & Date: sebres on 2019-01-17 09:00:11
Changes

  1. icomment:
    <p>Just for the record</p>
    <p>As for [pwd] normalization...<br>Well, as already said, I don't think it is still an issue under windows.</p>
    <p>As for "the percent character has to be escaped"... <br>Sure it must be, but for batch/exe, and as regards the execution of command processor - it was just unintended after-effect of the fix. Shit happens.<br>The escape is necessary because of certain issue how Windows processes unpaired quotes (it is vulnerable at the moment and MS won't fix this due to compat-reasons, see <a href="https://github.com/Microsoft/console/issues/250">Microsoft/console/issues/250)</a>, so it is possible to produce an unpaired quote after substitution of some env-vars (like paths, containing quotes, which are substituted in call, so no more under control of Tcl). Just because several quotation marks together are processed differently, there are even weird cases where triple-quotes will be unescaped similar to double-quotes, or they can even "reverse" unescape strategy MS used here. <br>For example <code>C" "C</code>, <code>"C C"</code> and <code>""C" "C""</code> are the same under windows, so following substitutions cause the same result:</p>
    <p><pre style="font-size: 80%">
    &gt; echo puts $::argv | tclsh - C" "C
    - {C C}
    &gt; echo puts $::argv | tclsh - "C C"
    - {C C}
    &gt; echo puts $::argv | tclsh - ""C" "C""
    - {C C}
    </pre>
    So if you basically don't have the quotes under your control and in principle you do not, because the internal %-substitution of variables has precedence here, so could damn your composited command line, also in case it was initially quoted properly.<br>Then the usage of some parameters like "| %COMSPEC% /c do-something-evil" after such break, e. g. passed from foreign user-input and normally proper quoted/escaped as regards the single argument, allow intruder to construct an injection and produce exploit.<br><br>That's as regards the batch-execution etc.<br>As already said, cmd /c is rather an exception here (and was just an after-effect, so blame on me), but I'll try to provide the fix as soon as possible.</p>
    <p>As for "don't think that could be accomplished using double quotes". Yes you are right, it is not really possible, and this is also explained in <a href="https://core.tcl-lang.org/tcl/info/cc35e8ac4d9f98e6">my last comment</a> to&nbsp;mentioned 0-day vulni-ticket (but it is at least securer as it was previously).<br>The magic word here is circumflex (^) character and I've already potential solution for this, just the mixed escape using circumflex and quotes together is a bit complex (see <a href="https://github.com/sebres/PoC/issues/1">sebres/PoC/issues/1</a>). <br>Additionally it deviates a bit by the call of batch and executable, and I would resolve this deviation before, as well as provide good test-coverage for both variants (now 3, inclusive comspec).</p>
    <p>17.01.2019 01:19, Joe Mistachkin wrote:</p>
    <blockquote type="cite" style="padding-left: 5px; border-left: #1010ff 2px solid; margin-left: 5px">
    <div dir="ltr">
    <div>The original problem being solved was that [pwd] did not preserve the exact case of the current directory.&nbsp; I'm struggling to recall, but I think making the test result comparison case-insensitive was not an appropriate option.</div>
    <div>&nbsp;</div>
    <div>That being said, given the command escaping algorithm in use for Windows [exec] in 8.6.9, I'm surprised that other people haven't noticed that things don't work quite the same.&nbsp; Also, I'm confused by the percent character has to be escaped, since it does not typically impact argument boundaries on Windows.&nbsp; Furthermore, *if* it had to be escaped, I don't think that could be accomplished using double quotes.</div>
    
  2. login: "sebres"
  3. mimetype: "text/html"