CVE-2020-0668 - A Trivial Privilege Escalation Bug in Windows Service Tracing

栏目: IT技术 · 发布时间: 4年前

内容简介:In this post, I’ll discuss an arbitrary file move vulnerability I found inA service or module is associated to a registry key. Each key contains 6 values (i.e. settings). The 3 values we will focus on are:

In this post, I’ll discuss an arbitrary file move vulnerability I found in Windows Service Tracing . From my testing, it affected all versions of Windows from Vista to 10 but it’s probably even older because this feature was already present in XP.

TL;DR

Service Tracing is an old feature that I could trace back to Windows XP but it probably already existed in previous versions of the OS. It aims at providing some basic debug information about running services and modules. It can be configured by any local user, simply by editing some registry keys and values under HKLM\SOFTWARE\Microsoft\Tracing .

A service or module is associated to a registry key. Each key contains 6 values (i.e. settings). The 3 values we will focus on are: EnableFileTracing (enable / disable the “tracing”), FileDirectory (set the location of the output log file) and MaxFileSize (set the maximum file size of the log file).

Once EnableFileTracing is enabled, the target service will start writing to its log file in the directory of your choice . As soon as the size of the output file exceeds MaxFileSize , it will be moved (the .LOG extension is replaced by .OLD ) and a new log file will be created.

Thanks to James Forshaw’s symbolic link testing tools , the exploit is quite simple. All you need to do is set the target directory as a mountpoint to the \RPC Control object directory and then create two symbolic links:

  • A symbolic link from MODULE.LOG to a file you own (its size must be greater than MaxFileSize ).
  • A symbolic link from MODULE.OLD to any file on the file system (e.g.: C:\Windows\System32\WindowsCoreDeviceInfo.dll ).

Finally, the file move can be triggered by targeting a service running as NT AUTHORITY\SYSTEM and, the Update Session Orchestrator service can then be leveraged to get arbitrary code execution.

The Tracing Feature for Services

As briefly mentioned before, the Service Tracing feature can be configured by any local user, simply by editing some registry keys and values under HKLM\SOFTWARE\Microsoft\Tracing .

Using AccessChk from the Windows Sysinternals tools suite, we can see that regular Users have Read / Write permissions on almost all the sub-keys.

CVE-2020-0668 - A Trivial Privilege Escalation Bug in Windows Service Tracing

For the rest of this article, I’ll use the RASTAPI module as an example since it’s the one I leveraged in my exploit. This module is used by the IKEEXT service. Therefore, log events can be easily triggered by initiating dummy VPN connections. The following screenshot shows the default content of the registry key. The exact same values are configured for the other services and modules.

CVE-2020-0668 - A Trivial Privilege Escalation Bug in Windows Service Tracing

From a local attacker’s standpoint, here are the most interesting values:

Name Possible values Description
EnableFileTracing 0 - 1 Start / Stop writing to the log file.
FileDirectory A String The absolute path of a directory.
MaxFileSize 0x00000000 - 0xffffffff The maximum size of the output log file.

By setting these values, we can:

  • Force a specific service or module to start or stop writing debug information to a log file by setting EnableFileTracing to either 0 or 1 .
  • Specify the location of the log file by setting FileDirectory .
  • Specify the maximum size of the output file by setting MaxFileSize .

The only caveat is that we cannot choose the name of the output file since it’s based on the name of the debugged service or module. This issue can be easily addressed using symbolic links though.

The Arbitrary File Move Vulnerability

With all the previous elements of context in mind, the vulnerability can be easily explained.

Case #1: MaxFileSize - Default value

For this first test case, I simply set C:\LOGS as the output directory and enabled the File Tracing .

CVE-2020-0668 - A Trivial Privilege Escalation Bug in Windows Service Tracing

Now, if we want the target service to start writing to this file, we must generate some events. A very simple way to do so is to initiate a dummy VPN connection using the rasdial command and a PBK file.

CVE-2020-0668 - A Trivial Privilege Escalation Bug in Windows Service Tracing

It worked! The log file was written by NT AUTHORITY\SYSTEM . Its size is now around 24KB.

CVE-2020-0668 - A Trivial Privilege Escalation Bug in Windows Service Tracing

Case #2: MaxFileSize - Custom value

In the previous test, we saw that the final size of the output log file was around 24KB. Therefore, this time, we will set MaxFileSize to 0x4000 (16,384 bytes) and restart the test.

CVE-2020-0668 - A Trivial Privilege Escalation Bug in Windows Service Tracing

The events captured by “Process Monitor” can be summarized as follows:

  1. Basic information about the log file is fetched by the service. We can see that the EndOfFile is at offset 23,906 , which is the size of the file at this moment. The problem is that we specified a max file size of 16,384 bytes so, the system will consider that there is no more free space.
  2. SetRenameInformationFile is called with FileName=C:\LOGS\RASTAPI.OLD . In other words, since the existing file is considered as full, it is moved from C:\LOGS\RASTAPI.LOG to C:\LOGS\RASTAPI.OLD .
  3. The service creates a new C:\LOGS\RASTAPI.LOG file and starts writing to it.

CVE-2020-0668 - A Trivial Privilege Escalation Bug in Windows Service Tracing

The “Move” operation is performed as NT AUTHORITY\SYSTEM . Therefore, it can be leveraged to move a user-owned file to any location on the file system, such as C:\Windows\System32\ .

The Exploit

The exploit is simple and can be summarized as follows:

  1. Create (or copy) a file with a size greater than 0x8000 (32,768) bytes.
  2. Create a new directory ( C:\EXPLOIT\mountpoint\ for example) and set it as a mountpoint to \RPC Control .
  3. Create the following symbolic links:
    \RPC Control\RASTAPI.LOG -> \??\C:\EXPLOIT\FakeDll.dll (owner = current user)
    \RPC Control\RASTAPI.OLD -> \??\C:\Windows\System32\WindowsCoreDeviceInfo.dll
  4. Configure the following values in the registry:
    FileDirectory = C:\EXPLOIT\mountpoint
    MaxFileSize = 0x8000 (32,768‬ bytes)
    EnableFileTracing = 1
  5. Trigger RASTAPI related events using the RasDial function from the Windows API.
  6. Trigger the Update Session Orchestrator service to load the DLL in the context of NT AUTHORITY\SYSTEM .

Demo

CVE-2020-0668 - A Trivial Privilege Escalation Bug in Windows Service Tracing

Links & Resources


以上所述就是小编给大家介绍的《CVE-2020-0668 - A Trivial Privilege Escalation Bug in Windows Service Tracing》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

敏捷项目管理

敏捷项目管理

马克·莱顿 / 人民邮电出版社 / 2015-12-1 / CNY 69.00

当你进行软件开发时,你一定需要一种更快捷、更灵活的方式。《敏捷项目管理》将通过手把手的方式帮你充分发挥你手中的所有可利用工具和技术,以一种非常有效的方式管理好你的项目。通过《敏捷项目管理》,你可以学到:在数周内而不是数月内完成你的软件开发;使用敏捷技术降低项目风险,并提升核心收益;将敏捷理论付诸实践;避免项目管理普遍存在的误区。一起来看看 《敏捷项目管理》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具