[EXP]Microsoft Windows - DfMarshal Unsafe Unmarshaling Privilege Escalation
Windows: DfMarshal Unsafe Unmarshaling Elevation of Privilege (Master)
Platform: Windows (not tested earlier, although code looks similar on Win8+)
Class: Elevation of Privilege Note, this is the master issue report for the DfMarshal unmarshaler. I’m reporting multiple, non-exhaustive, issues in this marshaler in case you decide that you want to try and “fix” it rather than blocking the marshaler outright. Summary: The unmarshaler for Storage objects is complete unsafe and yet is marked as a system trusted marshaler. There are multiple ways of abusing this to unmarshaler to get privilege escalation. Description: Storage objects are used by different parts of the OS and Office as a structured container format for sub-streams of data. You can create a new instance using APIs such as StgCreateDocFile. Being a COM object it can be marshaled around between processes, including special support during COM activation through CoGetInstanceFromIStorage. While all the important interfaces have proxy support the object also supports custom marshaling to improve performance when marshaling either INPROC or a LOCAL context. The COM class DfMarshal CLSID:0000030b---c000- (in coml2.dll on Windows , ole32.dll downlevel) implements the custom unmarshaling for storage objects. When marshaling the implementation generates the following output: MSHFLAGS < bytes>
Object Type IID < bytes> - Either IID_IStream or IID_IStorage.
Standard Marshaled Interface <Variable> - Used if the custom marshal fails.
SDfMarshalPacket <0x70 bytes on bit, 0x44 on bit> - Data for the custom marshal. The SDfMarshalPacket has the following structure, note this comes from the Windows 8.1 private symbols for OLE32.DLL which are available on the public symbol server. On Windows when the code was moved to COML2.DLL the private symbols didn’t move with it, however the code only seems to have had minor changes between 8.1 and . struct SDfMarshalPacket
{
CBasedPubDocFilePtr pdf;
CBasedPubStreamPtr pst;
CBasedSeekPointerPtr psp;
CBasedMarshalListPtr pml;
CBasedDFBasisPtr pdfb;
CBasedGlobalContextPtr pgc;
CBasedGlobalFileStreamPtr fsBase;
CBasedGlobalFileStreamPtr fsDirty;
CBasedGlobalFileStreamPtr fsOriginal;
unsigned int ulHeapName;
unsigned int cntxid;
GUID cntxkey;
CPerContext *ppc;
HANDLE hMem;
}; The Ptr structures are native pointer sized values which are used as relative offsets into a shared memory section. The cntxid is the PID of the marshaling process, the hMem a handle to a section object which contains the shared allocation pool for use between processes. When the custom unmarshaling process starts the receiving process will try and open the process containing the shared memory handle (using cntxid and hMem) and duplicate it into the current process. Then it will map the section into memory and rebuild a local storage object based on the various relative pointers stored in the marshaled structure. Note that there is provision for performance improvements for in-process marshaling where cntxkey is a random GUID value which is known only to the process (it’s not set for cross context marshal). In that case ppc is used as a valid pointer, but ppc is always set so this leaks memory layout information to the process the object is marshaled to (not reporting this one separately). This will only work if the process can open the marshalling process for PROCESS_DUP_HANDLE access. This restricts this to processes at the same or higher privilege, therefore an obvious target would be unmarshaling this data from a user into a system service. Fortunately there’s some protection against that, the unmarshal occurs in CSharedMemoryBlock::InitUnMarshal and looks something like the following: int CSharedMemoryBlock::InitUnMarshal(void *hMem,
unsigned int dwProcessId,
unsigned int culCommitSize) {
unsigned int dwCurrentSession;
unsigned int dwSourceSession; ProcessIdToSessionId(dwProcessId, &dwSourceSession);
ProcessIdToSessionId(GetCurrentProcessId(), &dwCurrentSession);
if (dwSourceSession != dwCurrentSession)
return E_ACCESSDENIED;
HANDLE hProcess = OpenProcess(PROCESS_DUP_HANDLE, , dwProcessId);
...
} The code contains a check that the process containing the shared section is in the same console session as the process doing the unmarshal. If they’re not in the same session then the unmarshal process will fail. It’s unclear if this is a security check or whether it’s a reliability check, and even if it’s a security check it’s not hard to find a way around this. One thought would be to try and use this to escape a sandbox, such as AppContainer as the sandbox process and a likely COM target would all be in the same session. While there are checks for the current process being in an AppContainer (so an AC process will never use the custom unmarshaling) there are no checks for the caller being an in AC. In fact there would be as the default HYBRID custom marshaling policy should kick in and block the custom unmarshal. However as DfMarshal is marked as a system trusted marshaler, it will still execute. It turns out that it’s difficult to trivially use this from a sandbox as later in the initialization an event object is opened by name (in CDfMutex::Init) from the current session’s BaseNamedObjects directory which an AC can’t write to. However if some other process in the same session had already shared a storage object, creating the event _and_ the AC could read the randomly assigned name it could be hijacked. So we’re back to either abusing something like UAC elevated processes/runas on the same desktop (doable but not a security boundary) or try and bypass the check to unmarshal from a user process into a system process. The key is the knowledge that the unmarshaler will open any process we tell it to, including other services in Session . The code could try and query the PID of the caller through COM (and thereby through MSRPC/ALPC) but it doesn’t. This means as long as we can get a writable section shared between our process and a process in session we can tell the unmarshaler to look there for the section handle. After some investigation I discovered that the Audio Service will create a writable section handle for you (actually via AUDIODG) and share it back to you when you create a rendering buffer (I didn’t investigation any further). This section is large enough to copy our existing shared memory from the marshal process. We can therefore create the section, copy over the existing shared memory (or fake one from scratch) then provide the PID and handle to the system service for use in unmarshaling. We don’t have to guess the handle as the handle table from NtQuerySystemInformation reports object addresses so you just match the current process’s handle and the AUDIODG handles. When the system service unmarshals this it will now pass the session check, we also have to create a duplicate event object in the global BNO but a normal user has access to that. During the unmarshal process the implementation interacts with the shared memory as an allocation region, this is where all the issues occur. In theory if you could find a system process which actually interacts with the storage object you might find some more interesting behaviors (such as getting the system service to write to arbitrary files) but everything I’ll describe in other issues all occur during the unmarshal process and so can be used to target any system COM service using CoGetInstanceFromStorage. Basically the storage object code uses the shared memory section as if everything is running at the same level of trust and doesn’t take any real precautions against a malicious actor which has access to the same shared section or controls the existing data. As mentioned I’m reporting other issues/bug classes at the same time. This is the master issue, and potentially you can mark the others as duplicates depending on how you want to fix them. Though I’d remind you that when you marked a bug as duplicate last time it didn’t get fixed so perhaps exercise caution. The four issues I’m reporting at the same time are: - DfMarshal Missing Bounds Checking Elevation of Privilege
- DfMarshal Shared Allocator Elevation of Privilege
- DfMarshal Arbitrary File Delete Elevation of Privilege
- DfMarshal Handle Duplication TOCTOU Elevation of Privilege Possible fixing ideas: DO NOT just remove the class from the trusted marshaler’s list. Some COM services such as SearchIndexer runs without the EOAC_NO_CUSTOM_MARSHAL flag set. You could query the PID of the caller in the unmarshal process and only duplicate from that process, or processes in the same session as the caller. However bear in mind that when unmarshaling during activation (through CoGetInstanceFromStorage) the caller will actually be RPCSS so this might be bypassable. Depending on how you did it this might mean that a session hopping bug (which I’ve found before) would allow you to elevate privilege. You could just rewrite the whole thing, it’s an incredibly bad piece of code. You could just restrict it to a very limited set of scenarios, but again you risk bypasses due to mistakes in the checks. Proof of Concept: See the separate reports for PoCs for various issues I identified. The source for all PoCs is attached to this issue. After looking again at the implementation of the unmarshaler there is a check in DfUnmarshalInterface for the caller being in an AC using the IMarshalingStream::GetMarshalingContextAttribute method which ultimately tries to impersonate the caller and check if the impersonation token is an AC or not. Quick update on RS5, as this was also discovered internal to Microsoft (I believe). There has been changes to the unmarshaler in three ways: ) A check is now performed on the owner of the section from its security descriptor which must now match the current process' user.
) All classes now have a GUID associated with them which is verified before trusting the data from the shared section.
) Addition of bounds checking on structure data size. isn't that hard to bypass, although the PoC provided won't as it gets a section from the Audio Service which is running as LOCAL SERVICE. and 3only matters for the cases where we we're trying to read out of bounds such as issue 1645 . Microsoft will apparently be fixing RS5 as well and won't be backporting this changes verbatim to prior versions as it wouldn't be possible in some cases (such as 1 not working on Windows 7). This does look in many ways like a non-backported fix, even if it doesn't really fix much. Due to the opaqueness of MSRC it's hard to confirm or deny that they weren't going to fix down level at some point. Fixed in https://portal.msrc.microsoft.com/en-us/security-guidance/advisory/CVE-2018-8550. Proof of Concept:
https://github.com/offensive-security/exploitdb-bin-sploits/raw/master/bin-sploits/45893.zip
[EXP]Microsoft Windows - DfMarshal Unsafe Unmarshaling Privilege Escalation的更多相关文章
- [EXP]Memu Play 6.0.7 - Privilege Escalation
# Exploit Title: Memu Play - Privilege Escalation (PoC) # Date: // # Author: Alejandra Sánchez # Ven ...
- [EXP]Microsoft Windows CONTACT - Remote Code Execution
[+] Credits: John Page (aka hyp3rlinx) [+] Website: hyp3rlinx.altervista.org [+] Source: http://hyp3 ...
- [EXP]Microsoft Windows MSHTML Engine - "Edit" Remote Code Execution
# Exploit Title: Microsoft Windows (CVE-2019-0541) MSHTML Engine "Edit" Remote Code Execut ...
- [EXP]Microsoft Windows 10 - XmlDocument Insecure Sharing Privilege Escalation
Windows: XmlDocument Insecure Sharing Elevation of Privilege Platform: Windows (almost certainly ear ...
- [EXP]Microsoft Windows 10 (Build 17134) - Local Privilege Escalation (UAC Bypass)
#include "stdafx.h" #include <Windows.h> #include "resource.h" void DropRe ...
- Windows XP SP1 Privilege Escalation
MS05-018 MS05-018 Works for Windows 2K SP3/4 | Windows XP SP1/2 Download ms05-018.exe: https://githu ...
- OSCP Learning Notes - Privilege Escalation
Privilege Escalation Download the Basic-pentesting vitualmation from the following website: https:// ...
- Linux/Unix System Level Attack、Privilege Escalation(undone)
目录 . How To Start A System Level Attack . Remote Access Attack . Local Access Attack . After Get Roo ...
- Microsoft Windows 远程权限提升漏洞(CVE-2013-3175)(MS13-062)
漏洞版本: Microsoft Windows XP Microsoft Windows Vista Microsoft Windows Server 2008 Microsoft Windows R ...
随机推荐
- maven 在clean package时,出现:找不到符号 [ERROR] 符号: 方法 sqlDdlFilter(java.lang.String) 解决办法
另一个项目中增加了,sqlDdlFilter 在调用的项目中clean package时,出现 找不到符号[ERROR] 符号: 方法 sqlDdlFilter(java.lang.String) 原 ...
- mysql too many connection 解决
最近的项目用了动态切换数据源起初感觉还好,后来发现每次切换数据库都会创建一个新的连接,这样就导致大量的sleep线程.而mysql的默认sleep时间是28800秒....默认最大连接数为151,这就 ...
- C#学习笔记14——TRACE、DEBUG和TRACESOURCE的使用以及日志设计
Trace.Debug和TraceSource的使用以及日志设计 .NET Framework 命名空间 System.Diagnostics 包含用于跟踪执行流程的 Trace.Debug 和 ...
- 详细分析LoadRunner参数化
在进行网页的性能测试时,对网页的登录界面进行压力测试情况下就会使用到多用户进行登录,就需要对登录名和密码进行参数化,那么loadrunner怎么参数化设置呢?下面我们来详细分析一下. 一.我们这里通过 ...
- 计算机爱好者协会技术贴markdown第二期
上一期我们学了多级标题,加粗,加斜以及蛮好看的小方块,这一期来继续学习吧 Txt版本: *上一期说这样可以加斜* _其实这样也可以加斜_ **上一期说这样可以加粗** __其实这样也可以加粗__ ** ...
- Cannot run CentOS 7 or RHEL 7 installer: “Failed to start Switch Root”
这个问题是由于安装程序默认的LABEL对于你要安装的磁盘系统分区不匹配造成的 通过编辑引导参数来使安装程序运行 在选择安装选项之前,按‘e’添加相应的引导参数
- Spring Boot的Maven配置
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...
- linux从0开始----01
1.VMware 虚拟机安装与卸载 推荐安装较高版本,11.x以后的.本课程安装12.x版本,需要序列号. 2.在vmware中安装centos客户机.初学者选择典型安装也可以. 1.vware文件菜 ...
- (PMP)解题技巧和典型题目分析(0903-2班)
1.计算题 ,5 2.概念题,少 3.情景题,很多 C B C D ------------------------------------------------------------------ ...
- PHP中this,self,parent的区别
{一}PHP中this,self,parent的区别之一this篇 面向对象编程(OOP,Object OrientedProgramming)现已经成为编程人员的一项基本技能.利用OOP的思想进行P ...