Microsoft Edge Remote Code Execution
(CVE-2018-8495) Chaining a few bugs in Edge I was able to achieve remote code execution by mainly abusing custom URI schemes.(CVE-2018-8495) Xâu chuỗi một vài lỗi trong Edge Tôi có thể thực hiện mã từ xa bằng cách chủ yếu lạm dụng các lược đồ URI tùy chỉnh
Launching External Applications


Many of you are probably aware that within the browser one can launch the default mail client by having a user go to a URL that looks like 'mailto:test@test.test'
. A prompt will appear asking the user whether to switch applications, once a user agrees, the application will run. In my case, Outlook is the default mail application and as you can see in the image below certain parameters are sent to the Outlook executable. So there is user tainted string being passed as a parameter value, clearly something could go wrong here. But the question is – What other external-application-launching URI schemes are there?
Nhiều người trong số bạn có thể biết rằng trong trình duyệt, người ta có thể khởi chạy ứng dụng thư khách mặc định bằng cách cho người dùng truy cập vào một URL trông giống như ‘mailto: test@test.test’. Một dấu nhắc sẽ xuất hiện hỏi người dùng có chuyển đổi ứng dụng hay không, khi người dùng đồng ý, ứng dụng sẽ chạy. Trong trường hợp của tôi, Outlook là ứng dụng thư mặc định và như bạn có thể thấy trong hình bên dưới một số tham số nhất định được gửi đến tệp thực thi Outlook. Vì vậy, có chuỗi người dùng bị nhiễm độc được chuyển qua như một giá trị tham số, rõ ràng có điều gì đó có thể sai ở đây. Nhưng câu hỏi là – Những lược đồ URI khởi chạy ứng dụng bên ngoài nào khác?
The Most Convenient Protocol





When looking at the registry we can find all the registered custom protocols we can use. Within 'Computer\HKEY_CLASSES_ROOT\'
we look for folders which contain 'shell\open\command'
as sub folders. For example, I found that 'ms-word'
has such sub folders. So if we look at the values of 'Computer\HKEY_CLASSES_ROOT\ms-word\shell\open\command'
we find 'C:\Program Files (x86)\Microsoft Office\Root\Office16\protocolhandler.exe "%1"'
. This means if we have a user click on an anchor tag that points to 'ms-word:test'
the following will occur: I am too lazy to look at all the possible command line parameters we could throw at 'protocolhandler.exe'
to achieve something useful. So let’s take a look at a lower hanging fruit. Well, this is very convenient! A URI scheme that passes user tainted arguments directly to 'WScript.exe'
. In case you don’t know: “Windows Script Host provides an environment in which users can execute scripts in a variety of languages that use a variety of object models to perform tasks.” Let’s see what happens if a user navigates to 'wshfile:test'
from Edge. First, we get a prompt asking to choose the default application that should handle this URI scheme. By default, as we’ve seen in the registry, 'Windows Script Host (WScript.exe)'
is the handler. Pressing 'OK'
yields the following: What 'WScript.exe'
does is it attempts to execute the file located in the path you pass to it. In this case, it tried to locate 'C:\WINDOWS\system32\wshfile:test'
but it does not exist. So what can we do about this? Can we somehow drop a file that’s named 'wshfile:test'
? Nope. So what can we do?
Khi nhìn vào sổ đăng ký, chúng ta có thể tìm thấy tất cả các giao thức tùy chỉnh đã đăng ký mà chúng ta có thể sử dụng. Trong ‘Máy tính \ HKEY_CLASSES_ROOT \’, chúng tôi tìm các thư mục chứa ‘shell \ open \ lệnh’ làm thư mục con. Ví dụ: tôi thấy rằng ‘ms-word’ có các thư mục con như vậy. Vì vậy, nếu chúng ta xem xét các giá trị của ‘Máy tính \ HKEY_CLASSES_ROOT \ ms-word \ shell \ open \ lệnh’, chúng ta sẽ tìm thấy ‘C: \ Program Files (x86) \ Microsoft Office \ Root \ Office16 \ Protocolhandler.exe “% 1″‘ . Điều này có nghĩa là nếu chúng ta có một người dùng nhấp vào thẻ neo trỏ đến ‘ms-word: test’ thì điều sau đây sẽ xảy ra: Tôi quá lười để xem tất cả các tham số dòng lệnh có thể chúng ta có thể ném vào ‘Protocolhandler.exe’ để đạt được một cái gì đó hữu ích. Vì vậy, hãy nhìn vào một quả treo thấp hơn. Chà, điều này rất thuận tiện! Một lược đồ URI chuyển trực tiếp các đối số bị ô nhiễm của người dùng đến ‘WScript.exe’. Trong trường hợp bạn không biết: “Windows Script Host cung cấp một môi trường trong đó người dùng có thể thực thi các tập lệnh bằng nhiều ngôn ngữ sử dụng nhiều mô hình đối tượng để thực hiện các tác vụ.” Hãy xem điều gì xảy ra nếu người dùng điều hướng đến ‘wshfile: test’ từ Edge. Đầu tiên, chúng tôi nhận được lời nhắc yêu cầu chọn ứng dụng mặc định sẽ xử lý lược đồ URI này. Theo mặc định, như chúng ta đã thấy trong sổ đăng ký, ‘Windows Script Host (WScript.exe)’ là trình xử lý. Nhấn ‘OK’ sẽ mang lại kết quả như sau: ‘WScript.exe’ làm gì để nó thực thi tệp nằm trong đường dẫn bạn truyền tới nó. Trong trường hợp này, nó đã cố gắng định vị ‘C: \ WINDOWS \ system32 \ wshfile: test’ nhưng nó không tồn tại. vậy chúng ta có thể làm gì? Bằng cách nào đó chúng ta có thể bỏ một tệp có tên ‘wshfile: test’ không? Không. Vậy chúng ta có thể làm gì?
Exploitation

The first test here is obvious: path traversal. I simply navigated to 'wshfile:test/../../foo.vbs'
, pressed OK on the prompt and then: Awesome! We can now point to any file in any directory and so long as we can drop a file in a predictable location, we will have RCE. But that is easier said than done, looked like most if not all cached files from Edge go into a salted directory location. In other words, we could plant files but we can’t predict their location. This is where I remembered an awesome article written by Matt Nelson. In this article he points out that Windows comes with a signed VBS located in 'C:\Windows\System32\Printing_Admin_Scripts\en-US\pubprn.vbs'
that suffers from ‘WSH Injection’. I highly recommend you read it, it essentially shows that the specific VBS file accepts 2 arguments passed to it and these arguments can be crafted as such that it would trick the VBS script into executing arbitrary commands. But! This was fixed already and the only affected computers are the ones that haven’t updated yet. So that’s not good enough, the article mentions that many more such cases exist but did not specify, thus begins my search for a similar case.
I started by looking at every single VBS file I could find in Windows and then looking if it accepts any parameters. I found one located at
Thử nghiệm đầu tiên ở đây là rõ ràng: đường dẫn ngang. Tôi chỉ cần điều hướng đến ‘wshfile: test /../../ foo.vbs’, nhấn OK trên dấu nhắc và sau đó: Tuyệt vời! Bây giờ chúng ta có thể trỏ đến bất kỳ tệp nào trong bất kỳ thư mục nào và miễn là chúng ta có thể thả tệp vào một vị trí có thể dự đoán được, chúng ta sẽ có RCE. Nhưng nói thì dễ hơn làm, trông giống như hầu hết nếu không phải tất cả các tệp được lưu trong bộ nhớ cache từ Edge đều đi vào một vị trí thư mục được muối. Nói cách khác, chúng ta có thể trồng các tệp nhưng chúng ta không thể dự đoán vị trí của chúng. Đây là nơi tôi nhớ một bài viết tuyệt vời được viết bởi Matt Nelson. Trong bài viết này, ông chỉ ra rằng Windows đi kèm với một VBS có chữ ký nằm trong ‘C: \ Windows \ System32 \ Printing_Admin_Scripts \ en-US \ pubprn.vbs’ bị ‘WSH tiêm’. Tôi đặc biệt khuyên bạn nên đọc nó, về cơ bản nó cho thấy rằng tệp VBS cụ thể chấp nhận 2 đối số được truyền cho nó và các đối số này có thể được tạo ra để nó có thể lừa kịch bản VBS thực thi các lệnh tùy ý. Nhưng! Điều này đã được sửa và các máy tính bị ảnh hưởng duy nhất là những máy tính chưa được cập nhật. Vì vậy, điều đó không đủ tốt, bài viết đề cập rằng có nhiều trường hợp như vậy tồn tại nhưng không chỉ định, do đó bắt đầu tìm kiếm của tôi cho một trường hợp tương tự.
Tôi bắt đầu bằng cách xem xét mọi tệp VBS duy nhất tôi có thể tìm thấy trong Windows và sau đó xem liệu nó có chấp nhận bất kỳ tham số nào không. Tôi tìm thấy một cái nằm ở
'C:\Windows\WinSxS\amd64_microsoft-windows-a..nagement-appvclient_31bf3856ad364e35_10.0.17134.48_none_c60426fea249fc02\SyncAppvPublishingServer.vbs'
This specific script takes in a few arguments and passes them into a powershell.exe shell execution without filtering it, allowing us to inject arbitrary commands. If you look at line 36 of ‘SyncAppvPublishingServer.vbs’ we see:
Kịch bản cụ thể này nhận một vài đối số và chuyển chúng vào một thực thi shell powershell.exe mà không lọc nó, cho phép chúng ta thực hiện các lệnh tùy ý. Nếu bạn nhìn vào dòng 36 của ‘SyncAppvPublishingServer.vbs’, chúng tôi thấy:
psCmd = "powershell.exe -NonInteractive -WindowStyle Hidden -ExecutionPolicy RemoteSigned -Command &{" & syncCmd & "}"
And we can influence the value of 'syncCmd'
but not only that, Edge also does not sanitize quotation marks, so we can pass as many parameters to 'WScript.exe'
as we want. Again, conveniently this powershell will run hidden as indicated by '-WindowStyle Hidden'
which makes this a perfect WSH injection vector.
Và chúng tôi có thể ảnh hưởng đến giá trị của ‘syncCmd’ nhưng không chỉ vậy, Edge cũng không vệ sinh dấu ngoặc kép, vì vậy chúng tôi có thể chuyển bao nhiêu tham số cho ‘WScript.exe’ như chúng tôi muốn. Một lần nữa, thuận tiện, quyền hạn này sẽ chạy ẩn như được chỉ định bởi ‘-WindowStyle Hidden’which làm cho điều này trở thành một vectơ tiêm WSH hoàn hảo.
The problem in this version is that this specific folder name depends on what windows build the user is on. In my OS build 17134 the folder contains ‘10.0.17134’ if you were on a different OS build it will be different. As far as the other things, there is little to no documentation of how they are determined. This is the only article I found about it with any useful information.
Vấn đề trong phiên bản này là tên thư mục cụ thể này phụ thuộc vào cửa sổ xây dựng người dùng đang sử dụng. Trong bản dựng hệ điều hành 17134 của tôi, thư mục chứa ’10 .0.17134 ‘nếu bạn ở bản dựng hệ điều hành khác, nó sẽ khác. Đối với những thứ khác, có rất ít hoặc không có tài liệu về cách chúng được xác định. Đây là bài viết duy nhất tôi tìm thấy về nó với bất kỳ thông tin hữu ích.
I made the argument in my report that all we needed was a stepping stone vulnerability in Edge that allowed us to detect local files (not read them), I was not able to find such a bug but hypothetically it can popup at any moment. On top of that, we don’t have to guess the entire folder name char by char. In Windows folders come with a shorthand version called “DOS PATH” and so guessing the DOS path version of the folder location is more than possible.
Tôi đã đưa ra lập luận trong báo cáo của mình rằng tất cả những gì chúng tôi cần là một lỗ hổng bảo mật trong Edge cho phép chúng tôi phát hiện các tệp cục bộ (không đọc chúng), tôi không thể tìm thấy một lỗi như vậy nhưng theo giả thuyết thì nó có thể bật lên bất cứ lúc nào. Trên hết, chúng ta không phải đoán toàn bộ tên thư mục char theo char. Trong các thư mục Windows đi kèm với một phiên bản tốc ký gọi là “DOS PATH” và do đó, việc đoán phiên bản đường dẫn DOS của vị trí thư mục là nhiều hơn có thể.
Instead of trying to guess:
'C:\Windows\WinSxS\amd64_microsoft-windows-a..nagement-appvclient_31bf3856ad364e35_10.0.17134.48_none_c60426fea249fc02\SyncAppvPublishingServer.vbs'
We can guess:
'C:\Windows\WinSxS\AMD921~1.48_\SyncAppvPublishingServer.vbs'
So this makes my argument even stronger. Since both of these point to the exact same file.
Vì vậy, điều này làm cho lập luận của tôi mạnh mẽ hơn. Vì cả hai đều trỏ đến cùng một tệp.
But wait, what about that pesky prompt that appears? No user would be fooled into clicking ‘OK’ and run Windows Script Host! Thankfully when this prompt appears, the default focus is on the ‘OK’ button which means all the user has to do is hold down enter key and we can trick them into accepting the prompt.
Nhưng chờ đã, còn lời nhắc nhở phiền phức đó xuất hiện thì sao? Không người dùng nào bị lừa khi nhấp vào ‘OK’ và chạy Windows Script Host! Rất may khi lời nhắc này xuất hiện, tiêu điểm mặc định nằm ở nút ‘OK’, điều đó có nghĩa là tất cả những gì người dùng phải làm là nhấn giữ phím enter và chúng ta có thể lừa họ chấp nhận lời nhắc.
Finally
The final proof of concept is as follows:
<a id="q" href='wshfile:test/../../WinSxS/AMD921~1.48_/SyncAppvPublishingServer.vbs" test test;calc;"'>test</a> <script> window.onkeydown=e=>{ window.onkeydown=z={}; q.click() } </script>
..and the a video of it in action:
This was my first time reporting through ZDI and I must say that it is a breath of fresh air. The fact that I did not have to deal with vendors directly was a big plus, as I could focus on other things.
Comments