lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <AB22EE81117646DB9498B1BD80FBE1F6@W340>
Date: Mon, 7 Dec 2015 18:04:35 +0100
From: "Stefan Kanthak" <stefan.kanthak@...go.de>
To: <fulldisclosure@...lists.org>
Cc: <bugtraq@...urityfocus.com>
Subject: Executable installers are vulnerable^WEVIL (case 2): NSIS allows remote code execution with escalation of privilege

Hi @ll,

executable (un)installers [°] created with Nullsoft Scriptable Install
System (NSIS, see <http://nsis.sourceforge.net/>; for some of its
victims see <http://nsis.sourceforge.net/users>) are vulnerable:

1. They load and execute a rogue/bogus/malicious ShFolder.dll ['][²]
   (and other DLLs like SetupAPI.dll or UXTheme.dll too) eventually
   found in the directory they are started from (the "application
   directory").

   For software downloaded with a web browser this is typically the
   "Downloads" directory: see
   <https://insights.sei.cmu.edu/cert/2008/09/carpet-bombing-and-directory-poisoning.html>,
   <http://blog.acrossecurity.com/2012/02/downloads-folder-binary-planting.html>
   and <http://seclists.org/fulldisclosure/2012/Aug/134>

   If ShFolder.dll (or any of the other DLLs) gets planted in the
   "Downloads" directory per "drive-by download" this vulnerability
   becomes a remote code execution.

   Due to an application manifest embedded in the executable which
   specifies "requireAdministrator" or the "installer detection" (see
   <https://technet.microsoft.com/en-us/library/dd835540.aspx#BKMK_InstDet>)
   of Windows' "user account control" executable installers are
   typically started with administrative privileges ("protected"
   administrators are prompted for consent, unprivileged standard
   users are prompted for an administrator password); execution of
   ShFolder.dll et. al. then results in an escalation of privilege!

2. They extract embedded DLLs (System.dll, UserInfo.dll, Banner.dll,
   UAC.Dll, liteFirewallW.dll, ...) to an unsafe temporary
   (sub)directory "%TEMP%\ns<letter><random>.tmp\" and load them from
   there [³].

   These DLLs can be overwritten by an unprivileged user between their
   creation and execution, resulting in an escalation of privilege.

3. Their uninstaller copies itself to "%TEMP%\~nsu.tmp\<letter>u_.exe"
   and runs its copy from there, again loading
   "%TEMP%\~nsu.tmp\ShFolder.dll" and other DLLs, which can be created
   (in advance) or overwritten by an unprivileged user.

   Since "%TEMP%\~nsu.tmp\<letter>u_.exe" is typically started with
   administrative privileges this results in another escalation of
   privilege.

4. Executable (un)installers distributed per software deployment system
   (for example WSUS) or wrapped into a .MSI for deployment per group
   policies are (typically) run under "LocalSystem" account.

   Processes running under "LocalSystem" account use the global %TEMP%
   directory %SystemRoot%\Temp where EVERY (unprivileged) user can
   create (or overwrite) files and conduct all these attacks.

   For a recent example of such a vulnerability see
   <https://code.google.com/p/google-security-research/issues/detail?id=440>


Proof of concept/demonstration:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

1. visit <http://home.arcor.de/skanthak/sentinel.html>, download
   <http://home.arcor.de/skanthak/download/SENTINEL.DLL> and save
   it as ShFolder.dll in your "Downloads" directory, then copy it
   as UXTheme.dll and SetupAPI.dll there too;

2. download
   <http://prdownloads.sourceforge.net/nsis/nsis-2.46-setup.exe?download>
   or <http://prdownloads.sourceforge.net/nsis/nsis-3.02b-setup.exe?download>
   via <http://nsis.sourceforge.net/Download> and save it/them in
   your "Downloads" directory;

3. execute nsis-2.46-setup.exe or nsis-3.02b-setup.exe from your
   "Downloads" directory;

4. notice the message boxes displayed from ShFolder.dll etc. placed
   in step 1.


Detection:
~~~~~~~~~~

Unless overwritten by the creator of the executable installer the
strings "Nullsoft Install System" or "Nullsoft.NSIS.exehead"
contained in their embedded application manifest identify these
executable installers.

Use the commands
    FINDSTR.EXE /M /C:"Nullsoft" "%USERPROFILE%\Downloads\*.exe"
    FINDSTR.EXE /S /M /C:"Nullsoft" "%TEMP%\*.exe"
to find NSIS executable installers in your "downloads" and "temp"
directories.


Mitigation(s):
~~~~~~~~~~~~~~

0. DON'T USE EXECUTABLE INSTALLERS [°]!

   If your favourite applications are not distributed in the native
   installer package format of the resp. target platform: ask^WURGE
   their vendors/developers to provide native installation packages.
   If they don't: dump these applications, stay away from such cruft!

1. Turn off privilege elevation for standard users and installer
   detection for all users:

   [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System]
   "ConsentPromptBehaviorUser"=dword:00000000 ; Automatically deny elevation requests
   "EnableInstallerDetection"=dword:00000000

   See <https://technet.microsoft.com/en-us/library/dd835564.aspx#BKMK_RegistryKeys>

2. NEVER execute files in UNSAFE directories (like "Downloads" and
   and "%TEMP%")!

3. Deny execution (at least) in the "Downloads" directories and all
   "%TEMP%" directories and their subdirectories:

   * Add the NTFS ACE "(D;OIIO;WP;;;WD)" meaning "deny execution of
     files in this directory for everyone, inheritable to all files
     in all subdirectories" (use CACLS.EXE /S:<SDDL> for example);

   * Use "software restriction policies" resp. AppLocker.

   Consider to apply either/both to every "%USERPROFILE%" as well as
   "%ALLUSERSPROFILE%" alias %ProgramData%" and "%PUBLIC%": Windows
   doesn't place executables in these directories and beyond.

   See <http://home.arcor.de/skanthak/safer.html> and/or
   <http://mechbgon.com/srp/> plus
   <http://csrc.nist.gov/itsec/SP800-68r1.pdf>,
   <https://www.nsa.gov/ia/_files/os/win2k/application_whitelisting_using_srp.pdf>
   or <https://books.google.de/books?isbn=1437914926> and finally
   <http://www.asd.gov.au/infosec/top35mitigationstrategies.htm>!


stay tuned
Stefan Kanthak


PS: see <http://seclists.org/fulldisclosure/2015/Nov/101> (resp. the
    not yet finished <http://home.arcor.de/skanthak/!execute.html>)
    for more details!

PPS: the case numbers are not in chronological order.


[°] Self-extracting archives and executable installers are flawed^W
    b(rainde)ad in concept and dangerous in practice.

    DON'T USE SUCH CRUFT!
    ALWAYS use the resp. target platforms native package and archive
    format.

    For Windows these are .INF (plus .CAB) and .MSI (plus .CAB),
    introduced 20 years ago (with Windows 95 and Windows NT4) resp.
    16 years ago (with Office 2000).

    Both .INF and .MSI are "opened" by programs residing in
    %SystemRoot%\System32\ which are therefore immune to this kind of
    "DLL (and EXE) Search Order Hijacking" attack.
    Since both .INF and .MSI access the contents of .CAB directly
    they eliminate the attack vector "unsafe temporary directory" too.

['] ShFolder.dll is cruft from the last millennium, it was used on
    Windows 9x without Internet Explorer 4; see
    <https://support.microsoft.com/en-us/kb/241733>

    DONT USE the sample code shown in this MSKB article!

[²] A well-known (trivial, easy to exploit and easy to avoid) and
    well-documented vulnerability: see
    <https://cwe.mitre.org/data/definitions/426.html>,
    <https://cwe.mitre.org/data/definitions/427.html>,
    <https://capec.mitre.org/data/definitions/471.html>,
    <https://technet.microsoft.com/en-us/library/2269637.aspx>,
    <https://msdn.microsoft.com/en-us/library/ff919712.aspx> and
    <https://msdn.microsoft.com/en-us/library/ms682586.aspx>

[³] Another well-known (trivial, easy to exploit and easy to avoid)
    and well-documented vulnerability: see
    <https://cwe.mitre.org/data/definitions/377.html>,
    <https://cwe.mitre.org/data/definitions/379.html>,
    <https://capec.mitre.org/data/definitions/27.html>,
    <https://capec.mitre.org/data/definitions/29.html> ...


Timeline:
~~~~~~~~~

2015-10-28    vulnerability report sent to author

2015-11-06    response from other developer:
              "ShFolder.dll [...] is a application directory dll hijack
               and I have now changed it so we pass a full path to
               LoadLibrary."
              "[...] it is theoretically possible to write something
               that attacks our installers this way."

2015-11-07    attacks on unsafe temp directories are well-known and
              well-documented and have been demonstrated in practice

              NO ANSWER, not even an acknowledgement of receipt

2015-12-07    report published

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ