This source file includes following definitions.
- TestProcessAccess
- VolumeSupportsACLs
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
#include <shlwapi.h>
#include "base/win/windows_version.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "sandbox/win/tests/common/controller.h"
#pragma comment(lib, "shlwapi.lib")
namespace {
void TestProcessAccess(sandbox::TestRunner* runner, DWORD target) {
const wchar_t *kCommandTemplate = L"OpenProcessCmd %d %d";
wchar_t command[1024] = {0};
wsprintf(command, kCommandTemplate, target, PROCESS_CREATE_THREAD);
EXPECT_EQ(sandbox::SBOX_TEST_DENIED, runner->RunTest(command));
wsprintf(command, kCommandTemplate, target, PROCESS_DUP_HANDLE);
EXPECT_EQ(sandbox::SBOX_TEST_DENIED, runner->RunTest(command));
wsprintf(command, kCommandTemplate, target, PROCESS_SET_INFORMATION);
EXPECT_EQ(sandbox::SBOX_TEST_DENIED, runner->RunTest(command));
wsprintf(command, kCommandTemplate, target, PROCESS_VM_OPERATION);
EXPECT_EQ(sandbox::SBOX_TEST_DENIED, runner->RunTest(command));
wsprintf(command, kCommandTemplate, target, PROCESS_VM_READ);
EXPECT_EQ(sandbox::SBOX_TEST_DENIED, runner->RunTest(command));
wsprintf(command, kCommandTemplate, target, PROCESS_VM_WRITE);
EXPECT_EQ(sandbox::SBOX_TEST_DENIED, runner->RunTest(command));
wsprintf(command, kCommandTemplate, target, PROCESS_QUERY_INFORMATION);
EXPECT_EQ(sandbox::SBOX_TEST_DENIED, runner->RunTest(command));
wsprintf(command, kCommandTemplate, target, WRITE_DAC);
EXPECT_EQ(sandbox::SBOX_TEST_DENIED, runner->RunTest(command));
wsprintf(command, kCommandTemplate, target, WRITE_OWNER);
EXPECT_EQ(sandbox::SBOX_TEST_DENIED, runner->RunTest(command));
wsprintf(command, kCommandTemplate, target, READ_CONTROL);
EXPECT_EQ(sandbox::SBOX_TEST_DENIED, runner->RunTest(command));
}
}
namespace sandbox {
bool VolumeSupportsACLs(const wchar_t* any_path) {
wchar_t expand[MAX_PATH +1];
DWORD len =::ExpandEnvironmentStringsW(any_path, expand, _countof(expand));
if (0 == len) return false;
if (len > _countof(expand)) return false;
if (!::PathStripToRootW(expand)) return false;
DWORD fs_flags = 0;
if (!::GetVolumeInformationW(expand, NULL, 0, 0, NULL, &fs_flags, NULL, 0))
return false;
if (fs_flags & FILE_PERSISTENT_ACLS) return true;
return false;
}
TEST(ValidationSuite, TestSuite) {
TestRunner runner;
ASSERT_EQ(SBOX_TEST_PING_OK, runner.RunTest(L"ping"));
}
TEST(ValidationSuite, TestFileSystem) {
ASSERT_TRUE(VolumeSupportsACLs(L"%SystemDrive%\\"));
ASSERT_TRUE(VolumeSupportsACLs(L"%SystemRoot%\\"));
ASSERT_TRUE(VolumeSupportsACLs(L"%ProgramFiles%\\"));
ASSERT_TRUE(VolumeSupportsACLs(L"%Temp%\\"));
ASSERT_TRUE(VolumeSupportsACLs(L"%AppData%\\"));
TestRunner runner;
EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(L"OpenFile %SystemDrive%"));
EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(L"OpenFile %SystemRoot%"));
EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(L"OpenFile %ProgramFiles%"));
EXPECT_EQ(SBOX_TEST_DENIED,
runner.RunTest(L"OpenFile %SystemRoot%\\System32"));
EXPECT_EQ(SBOX_TEST_DENIED,
runner.RunTest(L"OpenFile %SystemRoot%\\explorer.exe"));
EXPECT_EQ(SBOX_TEST_DENIED,
runner.RunTest(L"OpenFile %SystemRoot%\\Cursors\\arrow_i.cur"));
EXPECT_EQ(SBOX_TEST_DENIED,
runner.RunTest(L"OpenFile %AllUsersProfile%"));
EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(L"OpenFile %Temp%"));
EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(L"OpenFile %AppData%"));
}
TEST(ValidationSuite, TestRegistry) {
TestRunner runner;
EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(L"OpenKey HKLM"));
EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(L"OpenKey HKCU"));
EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(L"OpenKey HKU"));
EXPECT_EQ(SBOX_TEST_DENIED,
runner.RunTest(
L"OpenKey HKLM "
L"\"Software\\Microsoft\\Windows NT\\CurrentVersion\\WinLogon\""));
}
TEST(ValidationSuite, TestDesktop) {
TestRunner runner;
runner.GetPolicy()->SetAlternateDesktop(true);
EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(L"OpenInteractiveDesktop NULL"));
EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(L"SwitchToSboxDesktop NULL"));
}
TEST(ValidationSuite, TestAlternateDesktop) {
base::win::Version version = base::win::GetVersion();
if (version < base::win::VERSION_WIN7)
return;
TestRunner runner;
EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(L"EnumAlternateWinsta NULL"));
wchar_t command[1024] = {0};
runner.SetTimeout(3600000);
runner.GetPolicy()->SetAlternateDesktop(true);
runner.GetPolicy()->SetDelayedIntegrityLevel(INTEGRITY_LEVEL_UNTRUSTED);
base::string16 desktop_name = runner.GetPolicy()->GetAlternateDesktop();
desktop_name = desktop_name.substr(desktop_name.find('\\') + 1);
wsprintf(command, L"OpenAlternateDesktop %lS", desktop_name.c_str());
EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(command));
}
TEST(ValidationSuite, TestWindows) {
TestRunner runner;
wchar_t command[1024] = {0};
wsprintf(command, L"ValidWindow %d", ::GetDesktopWindow());
EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(command));
wsprintf(command, L"ValidWindow %d", ::FindWindow(NULL, NULL));
EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(command));
}
TEST(ValidationSuite, TestProcessDenyLockdown) {
TestRunner runner;
TestRunner target;
wchar_t command[1024] = {0};
target.SetAsynchronous(true);
EXPECT_EQ(SBOX_TEST_SUCCEEDED, target.RunTest(L"SleepCmd 30000"));
TestProcessAccess(&runner, target.process_id());
}
TEST(ValidationSuite, TestProcessDenyLowIntegrity) {
if (base::win::Version() < base::win::VERSION_VISTA)
return;
TestRunner runner;
TestRunner target;
wchar_t command[1024] = {0};
target.SetAsynchronous(true);
target.GetPolicy()->SetDelayedIntegrityLevel(INTEGRITY_LEVEL_LOW);
runner.GetPolicy()->SetIntegrityLevel(INTEGRITY_LEVEL_LOW);
runner.GetPolicy()->SetTokenLevel(USER_RESTRICTED_SAME_ACCESS,
USER_INTERACTIVE);
EXPECT_EQ(SBOX_TEST_SUCCEEDED, target.RunTest(L"SleepCmd 30000"));
TestProcessAccess(&runner, target.process_id());
}
TEST(ValidationSuite, TestProcessDenyBelowLowIntegrity) {
if (base::win::Version() < base::win::VERSION_VISTA)
return;
TestRunner runner;
TestRunner target;
wchar_t command[1024] = {0};
target.SetAsynchronous(true);
target.GetPolicy()->SetIntegrityLevel(INTEGRITY_LEVEL_LOW);
target.GetPolicy()->SetTokenLevel(USER_RESTRICTED_SAME_ACCESS,
USER_INTERACTIVE);
runner.GetPolicy()->SetDelayedIntegrityLevel(INTEGRITY_LEVEL_UNTRUSTED);
runner.GetPolicy()->SetTokenLevel(USER_RESTRICTED_SAME_ACCESS,
USER_INTERACTIVE);
EXPECT_EQ(SBOX_TEST_SUCCEEDED, target.RunTest(L"SleepCmd 30000"));
TestProcessAccess(&runner, target.process_id());
}
TEST(ValidationSuite, TestThread) {
TestRunner runner;
wchar_t command[1024] = {0};
wsprintf(command, L"OpenThreadCmd %d", ::GetCurrentThreadId());
EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(command));
}
}