| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/macros.h" | 6 #include "base/macros.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "base/test/histogram_tester.h" | 8 #include "base/test/histogram_tester.h" |
| 9 #include "chrome/browser/extensions/extension_browsertest.h" |
| 9 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/browser_commands.h" | 11 #include "chrome/browser/ui/browser_commands.h" |
| 11 #include "chrome/browser/ui/singleton_tabs.h" | 12 #include "chrome/browser/ui/singleton_tabs.h" |
| 12 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 13 #include "chrome/test/base/in_process_browser_test.h" | |
| 14 #include "chrome/test/base/ui_test_utils.h" | 14 #include "chrome/test/base/ui_test_utils.h" |
| 15 #include "content/public/browser/notification_observer.h" | 15 #include "content/public/browser/notification_observer.h" |
| 16 #include "content/public/browser/notification_service.h" | 16 #include "content/public/browser/notification_service.h" |
| 17 #include "content/public/browser/notification_types.h" | 17 #include "content/public/browser/notification_types.h" |
| 18 #include "content/public/browser/render_frame_host.h" | 18 #include "content/public/browser/render_frame_host.h" |
| 19 #include "content/public/browser/render_process_host.h" | 19 #include "content/public/browser/render_process_host.h" |
| 20 #include "content/public/browser/resource_request_details.h" | 20 #include "content/public/browser/resource_request_details.h" |
| 21 #include "content/public/browser/web_contents_observer.h" | 21 #include "content/public/browser/web_contents_observer.h" |
| 22 #include "content/public/common/content_switches.h" | 22 #include "content/public/common/content_switches.h" |
| 23 #include "content/public/test/browser_test_utils.h" | 23 #include "content/public/test/browser_test_utils.h" |
| 24 #include "net/dns/mock_host_resolver.h" | 24 #include "net/dns/mock_host_resolver.h" |
| 25 #include "net/test/embedded_test_server/embedded_test_server.h" | 25 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 26 | 26 |
| 27 // The goal of these tests is to "simulate" exploited renderer processes, which | 27 // The goal of these tests is to "simulate" exploited renderer processes, which |
| 28 // can send arbitrary IPC messages and confuse browser process internal state, | 28 // can send arbitrary IPC messages and confuse browser process internal state, |
| 29 // leading to security bugs. We are trying to verify that the browser doesn't | 29 // leading to security bugs. We are trying to verify that the browser doesn't |
| 30 // perform any dangerous operations in such cases. | 30 // perform any dangerous operations in such cases. |
| 31 // This is similar to the security_exploit_browsertest.cc tests, but also | 31 // This is similar to the security_exploit_browsertest.cc tests, but also |
| 32 // includes chrome/ layer concepts such as extensions. | 32 // includes chrome/ layer concepts such as extensions. |
| 33 class ChromeSecurityExploitBrowserTest : public InProcessBrowserTest { | 33 class ChromeSecurityExploitBrowserTest : public ExtensionBrowserTest { |
| 34 public: | 34 public: |
| 35 ChromeSecurityExploitBrowserTest() {} | 35 ChromeSecurityExploitBrowserTest() {} |
| 36 ~ChromeSecurityExploitBrowserTest() override {} | 36 ~ChromeSecurityExploitBrowserTest() override {} |
| 37 | 37 |
| 38 void SetUpOnMainThread() override { | 38 void SetUpOnMainThread() override { |
| 39 ExtensionBrowserTest::SetUpOnMainThread(); |
| 40 |
| 39 ASSERT_TRUE(embedded_test_server()->Start()); | 41 ASSERT_TRUE(embedded_test_server()->Start()); |
| 40 host_resolver()->AddRule("*", "127.0.0.1"); | 42 host_resolver()->AddRule("*", "127.0.0.1"); |
| 43 |
| 44 extension_ = LoadExtension(test_data_dir_.AppendASCII("simple_with_icon")); |
| 41 } | 45 } |
| 42 | 46 |
| 43 void SetUpCommandLine(base::CommandLine* command_line) override { | 47 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 48 ExtensionBrowserTest::SetUpCommandLine(command_line); |
| 44 // Since we assume exploited renderer process, it can bypass the same origin | 49 // Since we assume exploited renderer process, it can bypass the same origin |
| 45 // policy at will. Simulate that by passing the disable-web-security flag. | 50 // policy at will. Simulate that by passing the disable-web-security flag. |
| 46 command_line->AppendSwitch(switches::kDisableWebSecurity); | 51 command_line->AppendSwitch(switches::kDisableWebSecurity); |
| 47 } | 52 } |
| 48 | 53 |
| 54 const extensions::Extension* extension() { return extension_; } |
| 55 |
| 49 private: | 56 private: |
| 57 const extensions::Extension* extension_; |
| 58 |
| 50 DISALLOW_COPY_AND_ASSIGN(ChromeSecurityExploitBrowserTest); | 59 DISALLOW_COPY_AND_ASSIGN(ChromeSecurityExploitBrowserTest); |
| 51 }; | 60 }; |
| 52 | 61 |
| 53 IN_PROC_BROWSER_TEST_F(ChromeSecurityExploitBrowserTest, | 62 IN_PROC_BROWSER_TEST_F(ChromeSecurityExploitBrowserTest, |
| 54 ChromeExtensionResources) { | 63 ChromeExtensionResources) { |
| 55 // Load a page that requests a chrome-extension:// image through XHR. We | 64 // Load a page that requests a chrome-extension:// image through XHR. We |
| 56 // expect this load to fail, as it is an illegal request. | 65 // expect this load to fail, as it is an illegal request. |
| 57 GURL foo = embedded_test_server()->GetURL("foo.com", | 66 GURL foo = embedded_test_server()->GetURL("foo.com", |
| 58 "/chrome_extension_resource.html"); | 67 "/chrome_extension_resource.html"); |
| 59 | 68 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 77 | 86 |
| 78 content::RenderFrameHost* rfh = | 87 content::RenderFrameHost* rfh = |
| 79 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(); | 88 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(); |
| 80 | 89 |
| 81 // All these are attacker controlled values. The UUID is arbitrary. | 90 // All these are attacker controlled values. The UUID is arbitrary. |
| 82 std::string blob_id = "2ce53a26-0409-45a3-86e5-f8fb9f5566d8"; | 91 std::string blob_id = "2ce53a26-0409-45a3-86e5-f8fb9f5566d8"; |
| 83 std::string blob_type = "text/html"; | 92 std::string blob_type = "text/html"; |
| 84 std::string blob_contents = "<script>chrome.extensions</script>"; | 93 std::string blob_contents = "<script>chrome.extensions</script>"; |
| 85 std::string blob_path = "5881f76e-10d2-410d-8c61-ef210502acfd"; | 94 std::string blob_path = "5881f76e-10d2-410d-8c61-ef210502acfd"; |
| 86 | 95 |
| 87 // Target the bookmark manager extension. | 96 // Target an extension. |
| 88 std::string target_origin = | 97 std::string target_origin = "chrome-extension://" + extension()->id(); |
| 89 "chrome-extension://eemcgdkfndhakfknompkggombfjjjeno"; | |
| 90 | 98 |
| 91 // Set up a blob ID and populate it with attacker-controlled value. This | 99 // Set up a blob ID and populate it with attacker-controlled value. This |
| 92 // message is allowed, because this data is not in any origin. | 100 // message is allowed, because this data is not in any origin. |
| 93 content::PwnMessageHelper::CreateBlobWithPayload( | 101 content::PwnMessageHelper::CreateBlobWithPayload( |
| 94 rfh->GetProcess(), blob_id, blob_type, "", blob_contents); | 102 rfh->GetProcess(), blob_id, blob_type, "", blob_contents); |
| 95 | 103 |
| 96 // This IPC should result in a kill because |target_origin| is not commitable | 104 // This IPC should result in a kill because |target_origin| is not commitable |
| 97 // in |rfh->GetProcess()|. | 105 // in |rfh->GetProcess()|. |
| 98 base::HistogramTester histograms; | 106 base::HistogramTester histograms; |
| 99 content::RenderProcessHostWatcher crash_observer( | 107 content::RenderProcessHostWatcher crash_observer( |
| (...skipping 26 matching lines...) Expand all Loading... |
| 126 rfh->ExecuteJavaScriptWithUserGestureForTests( | 134 rfh->ExecuteJavaScriptWithUserGestureForTests( |
| 127 base::ASCIIToUTF16("var r = new XMLHttpRequest();" | 135 base::ASCIIToUTF16("var r = new XMLHttpRequest();" |
| 128 "r.open('GET', '/slow?99999', false);" | 136 "r.open('GET', '/slow?99999', false);" |
| 129 "r.send(null);" | 137 "r.send(null);" |
| 130 "while (1);")); | 138 "while (1);")); |
| 131 | 139 |
| 132 // JS code that the attacker would like to run in an extension process. | 140 // JS code that the attacker would like to run in an extension process. |
| 133 std::string payload = "<html><body>pwned.</body></html>"; | 141 std::string payload = "<html><body>pwned.</body></html>"; |
| 134 std::string payload_type = "text/html"; | 142 std::string payload_type = "text/html"; |
| 135 | 143 |
| 136 // Target the bookmark manager extension. | 144 // Target an extension. |
| 137 std::string target_origin = | 145 std::string target_origin = "chrome-extension://" + extension()->id(); |
| 138 "chrome-extension://eemcgdkfndhakfknompkggombfjjjeno/"; | |
| 139 | 146 |
| 140 // Set up a blob ID and populate it with the attacker-controlled payload. | 147 // Set up a blob ID and populate it with the attacker-controlled payload. |
| 141 // This is allowed, because this data is not in any origin; | 148 // This is allowed, because this data is not in any origin; |
| 142 // the UUID is arbitrary. | 149 // the UUID is arbitrary. |
| 143 std::string blob_id = "2ce53a26-0409-45a3-86e5-f8fb9f5566d8"; | 150 std::string blob_id = "2ce53a26-0409-45a3-86e5-f8fb9f5566d8"; |
| 144 content::PwnMessageHelper::CreateBlobWithPayload(rfh->GetProcess(), blob_id, | 151 content::PwnMessageHelper::CreateBlobWithPayload(rfh->GetProcess(), blob_id, |
| 145 payload_type, "", payload); | 152 payload_type, "", payload); |
| 146 | 153 |
| 147 // Note: a well-behaved renderer would always send the following message here, | 154 // Note: a well-behaved renderer would always send the following message here, |
| 148 // but it's actually not necessary for the original attack to succeed, so we | 155 // but it's actually not necessary for the original attack to succeed, so we |
| 149 // omit it. As a result there are some log warnings from the quota observer. | 156 // omit it. As a result there are some log warnings from the quota observer. |
| 150 // | 157 // |
| 151 // IPC::IpcSecurityTestUtil::PwnMessageReceived( | 158 // IPC::IpcSecurityTestUtil::PwnMessageReceived( |
| 152 // rfh->GetProcess()->GetChannel(), | 159 // rfh->GetProcess()->GetChannel(), |
| 153 // FileSystemHostMsg_OpenFileSystem(22, GURL(target_origin), | 160 // FileSystemHostMsg_OpenFileSystem(22, GURL(target_origin), |
| 154 // storage::kFileSystemTypeTemporary)); | 161 // storage::kFileSystemTypeTemporary)); |
| 155 | 162 |
| 156 GURL target_url = | 163 GURL target_url = |
| 157 GURL("filesystem:" + target_origin + "temporary/exploit.html"); | 164 GURL("filesystem:" + target_origin + "/temporary/exploit.html"); |
| 158 | 165 |
| 159 content::PwnMessageHelper::FileSystemCreate(rfh->GetProcess(), 23, target_url, | 166 content::PwnMessageHelper::FileSystemCreate(rfh->GetProcess(), 23, target_url, |
| 160 false, false, false); | 167 false, false, false); |
| 161 | 168 |
| 162 // Write the blob into the file. If successful, this places an | 169 // Write the blob into the file. If successful, this places an |
| 163 // attacker-controlled value in a resource on the extension origin. | 170 // attacker-controlled value in a resource on the extension origin. |
| 164 content::PwnMessageHelper::FileSystemWrite(rfh->GetProcess(), 24, target_url, | 171 content::PwnMessageHelper::FileSystemWrite(rfh->GetProcess(), 24, target_url, |
| 165 blob_id, 0); | 172 blob_id, 0); |
| 166 | 173 |
| 167 // Now navigate to |target_url| in a new tab. It should not contain |payload|. | 174 // Now navigate to |target_url| in a new tab. It should not contain |payload|. |
| 168 AddTabAtIndex(0, target_url, ui::PAGE_TRANSITION_TYPED); | 175 AddTabAtIndex(0, target_url, ui::PAGE_TRANSITION_TYPED); |
| 169 content::WaitForLoadStop(browser()->tab_strip_model()->GetWebContentsAt(0)); | 176 content::WaitForLoadStop(browser()->tab_strip_model()->GetWebContentsAt(0)); |
| 170 rfh = browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(); | 177 rfh = browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(); |
| 171 EXPECT_EQ(GURL(target_origin), rfh->GetSiteInstance()->GetSiteURL()); | 178 EXPECT_EQ(GURL(target_origin), rfh->GetSiteInstance()->GetSiteURL()); |
| 172 std::string body; | 179 std::string body; |
| 173 std::string script = R"( | 180 std::string script = R"( |
| 174 var textContent = document.body.innerText.replace(/\n+/g, '\n'); | 181 var textContent = document.body.innerText.replace(/\n+/g, '\n'); |
| 175 window.domAutomationController.send(textContent); | 182 window.domAutomationController.send(textContent); |
| 176 )"; | 183 )"; |
| 177 | 184 |
| 178 EXPECT_TRUE(content::ExecuteScriptAndExtractString(rfh, script, &body)); | 185 EXPECT_TRUE(content::ExecuteScriptAndExtractString(rfh, script, &body)); |
| 179 EXPECT_EQ( | 186 EXPECT_EQ( |
| 180 "\nYour file was not found\n" | 187 "\nYour file was not found\n" |
| 181 "It may have been moved or deleted.\n" | 188 "It may have been moved or deleted.\n" |
| 182 "ERR_FILE_NOT_FOUND\n", | 189 "ERR_FILE_NOT_FOUND\n", |
| 183 body); | 190 body); |
| 184 } | 191 } |
| OLD | NEW |