ResultCode CreateAltWindowStation(HWINSTA* winsta) { // Get the security attributes from the current window station; we will // use this as the base security attributes for the new window station.
HWINSTA current_winsta = ::GetProcessWindowStation();
if (!current_winsta) return SBOX_ERROR_CANNOT_GET_WINSTATION;
// Create the window station using nullptr for the name to ask the os to // generate it.
*winsta = ::CreateWindowStationW(
nullptr, 0, GENERIC_READ | WINSTA_CREATEDESKTOP, &attributes);
if (!*winsta && ::GetLastError() == ERROR_ACCESS_DENIED) {
*winsta = ::CreateWindowStationW(
nullptr, 0, WINSTA_READATTRIBUTES | WINSTA_CREATEDESKTOP, &attributes);
}
if (!winsta) {
desktop_name += L"local_winstation_";
}
// Append the current PID to the desktop name. wchar_t buffer[16];
_snwprintf_s(buffer, sizeof(buffer) / sizeof(wchar_t), L"0x%X",
::GetCurrentProcessId());
desktop_name += buffer;
if (!current_desktop) return SBOX_ERROR_CANNOT_GET_DESKTOP;
// Get the security attributes from the current desktop, we will use this as // the base security attributes for the new desktop.
absl::optional<base::win::SecurityDescriptor> sd =
base::win::SecurityDescriptor::FromHandle(
current_desktop, base::win::SecurityObjectType::kDesktop,
DACL_SECURITY_INFORMATION);
if (!sd) { return SBOX_ERROR_CANNOT_QUERY_DESKTOP_SECURITY;
}
if (sd->dacl() && sd->dacl()->is_null()) { // If the desktop had a NULL DACL, it allowed access to everything. When // we apply a new ACE with |kDesktopDenyMask| below, a NULL DACL would be // replaced with a new DACL with one ACE that denies access - which means // there is no ACE to allow anything access to the desktop. In this case, // replace the NULL DACL with one that has a single ACE that allows access // to everyone, so the desktop remains accessible when we further modify // the DACL. Also need WinBuiltinAnyPackageSid for AppContainer processes.
sd->SetDaclEntry(base::win::WellKnownSid::kAllApplicationPackages,
base::win::SecurityAccessMode::kGrant, GENERIC_ALL, 0);
sd->SetDaclEntry(base::win::WellKnownSid::kWorld,
base::win::SecurityAccessMode::kGrant, GENERIC_ALL, 0);
}
// Replace the DACL on the new Desktop with a reduced privilege version. // We can soft fail on this for now, as it's just an extra mitigation. staticconst ACCESS_MASK kDesktopDenyMask =
WRITE_DAC | WRITE_OWNER | DELETE | DESKTOP_CREATEMENU |
DESKTOP_CREATEWINDOW | DESKTOP_HOOKCONTROL | DESKTOP_JOURNALPLAYBACK |
DESKTOP_JOURNALRECORD | DESKTOP_SWITCHDESKTOP;
sd->SetDaclEntry(base::win::WellKnownSid::kRestricted,
base::win::SecurityAccessMode::kDeny, kDesktopDenyMask, 0);
// Back up the current window station, in case we need to switch it.
HWINSTA current_winsta = ::GetProcessWindowStation();
if (winsta) { // We need to switch to the alternate window station before creating the // desktop.
if (!::SetProcessWindowStation(winsta)) { return SBOX_ERROR_CANNOT_CREATE_DESKTOP;
}
}
if (winsta) { // Revert to the right window station.
if (!::SetProcessWindowStation(current_winsta)) { return SBOX_ERROR_FAILED_TO_SWITCH_BACK_WINSTATION;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.