what you don't know can hurt you
Home Files News &[SERVICES_TAB]About Contact Add New

Microsoft Windows Unsafe Handling Practices

Microsoft Windows Unsafe Handling Practices
Posted Jul 27, 2020
Authored by Stefan Kanthak

This post outlines multiple unsafe practices in Microsoft Windows that can allow for local privilege escalation.

tags | exploit, local
systems | windows
SHA-256 | 4bc0ba08bfeebdf7043e5c7d7060e65bdb0c48ca36fa23fc83ebabb77e5ff80d

Microsoft Windows Unsafe Handling Practices

Change Mirror Download
Hi @ll,

This multi-part post can be read even without a MIME-compliant program!

Back in 2014, I reported a vulnerability in CreateProcess()'s handling of
*.cmd and *.bat files that Microsoft fixed with MS14-019 alias MSKB 2922229
and assigned CVE-2014-0315: command lines with a batch script as first token
led to the execution of a (rogue) cmd.exe from the CWD (or the search path).

<https://blogs.technet.microsoft.com/srd/2014/04/08/ms14-019-fixing-a-binary-hijacking-via-cmd-or-bat-file/>
provides some details about the vulnerabilities attack vector.

With that in mind, read the documentation of the command processors START
builtin command <https://msdn.microsoft.com/en-us/library/cc770297.aspx> or
<https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/start>

| * When you run a command that contains the string "CMD" as the first token
| without an extension or path qualifier, "CMD" is replaced with the value
| of the COMSPEC variable. This prevents users from picking up cmd from
| the current directory.

This statement is but WRONG: START CMD ... picks a rogue cmd.exe from the CWD!

Demonstration/Proof of concept #1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

On a default installation of Windows XP or any newer version, start the command
processor CMD.EXE and run the following commands:

CHDIR /D "%TMP%"
COPY "%SystemRoot%\Write.exe" Cmd.exe
SET COMSPEC=
SET PATH=
START CMD /C PAUSE


This weakness is well-known and well-documented: see
<https://cwe.mitre.org/data/definitions/73.html>,
<https://cwe.mitre.org/data/definitions/426.html> and
<https://cwe.mitre.org/data/definitions/427.html>

For some of the well-known attacks see
<https://capec.mitre.org/data/definitions/13.html> and
<https://capec.mitre.org/data/definitions/471.html>


Now continue with the documentation of the command processors FOR builtin
command <https://msdn.microsoft.com/en-us/library/cc754900.aspx> or
<https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/for>

| * Parsing output:
| You can use the for /f command to parse the output of a command by placing
| a back-quoted <command> between the parentheses.

Back-quoted is only correct with FOR /F "UseBackQ" %<var> IN (´<command>´) DO ...
Without "UseBackQ" the command needs to be placed in single quotes!


| It is treated as a command line, which is passed to a child Cmd.exe.

That too is wrong: if COMSPEC is set, its value is used as file/pathname of the
child process; Cmd.exe is used only if COMSPEC is not set!

Demonstration/Proof of concept #2
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

On a default installation of Windows XP or any newer version, start the command
processor CMD.EXE and run the following commands:

SET COMSPEC=%SystemRoot%\System32\Reg.exe
FOR /F %? IN ('SET') DO @ECHO %?

Evaluating COMSPEC inside the command processor or executing the hard-coded
file Cmd.exe is both clumsy and unsafe!
The command processor can and should determine its own module name instead.


For a third bug and vulnerability see the following undocumented and outright
BRAINDEAD behaviour.

Demonstration/Proof of concept #3
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

On a default installation of Windows XP or any newer version, start the command
processor CMD.EXE and run the following commands:

SET COMSPEC=%SystemRoot%\System32\Reg.exe
ASSOC | CALL
ECHO | FTYPE
SET | More.com
...


Why does the command processor execute the EXTERNAL command specified in the
environment variable COMSPEC to run its builtin INTERNAL commands?


stay tuned, and far away from such blunders
Stefan Kanthak

PS: for more quirks see <https://skanthak.homepage.t-online.de/quirks.html>



Login or Register to add favorites

File Archive:

April 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Apr 1st
    10 Files
  • 2
    Apr 2nd
    26 Files
  • 3
    Apr 3rd
    40 Files
  • 4
    Apr 4th
    6 Files
  • 5
    Apr 5th
    26 Files
  • 6
    Apr 6th
    0 Files
  • 7
    Apr 7th
    0 Files
  • 8
    Apr 8th
    22 Files
  • 9
    Apr 9th
    14 Files
  • 10
    Apr 10th
    10 Files
  • 11
    Apr 11th
    13 Files
  • 12
    Apr 12th
    14 Files
  • 13
    Apr 13th
    0 Files
  • 14
    Apr 14th
    0 Files
  • 15
    Apr 15th
    30 Files
  • 16
    Apr 16th
    10 Files
  • 17
    Apr 17th
    22 Files
  • 18
    Apr 18th
    45 Files
  • 19
    Apr 19th
    8 Files
  • 20
    Apr 20th
    0 Files
  • 21
    Apr 21st
    0 Files
  • 22
    Apr 22nd
    11 Files
  • 23
    Apr 23rd
    68 Files
  • 24
    Apr 24th
    23 Files
  • 25
    Apr 25th
    16 Files
  • 26
    Apr 26th
    0 Files
  • 27
    Apr 27th
    0 Files
  • 28
    Apr 28th
    0 Files
  • 29
    Apr 29th
    0 Files
  • 30
    Apr 30th
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2022 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close