Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a second-auth feature in SbieStart #4062

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [1.14.4 / 5.69.4] - 2024-07-13


### Changed
- improved removal of leftovers [#4050](https://github.com/sandboxie-plus/Sandboxie/pull/4050)

Expand Down
108 changes: 103 additions & 5 deletions Sandboxie/apps/start/start.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
#include "core/drv/api_defs.h"
#include <psapi.h>
#include <Shlwapi.h>

#include<wincred.h>
#pragma comment(lib,"credui.lib")

//---------------------------------------------------------------------------
// Defines
Expand Down Expand Up @@ -1112,6 +1113,7 @@ int Program_Start(void)
STARTUPINFO si;
PROCESS_INFORMATION pi;
HANDLE hNewProcess = NULL;
BOOL isAdminActual = IsUserAnAdmin();

memzero(&si, sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO);
Expand Down Expand Up @@ -1194,7 +1196,25 @@ int Program_Start(void)
//
// start program
//

typedef DWORD(*P_CredUIPromptForCredentialsW)(
PCREDUI_INFOW pUiInfo,
PCWSTR pszTargetName,
PCtxtHandle pContext,
DWORD dwAuthError,
PWSTR pszUserName,
ULONG ulUserNameBufferSize,
PWSTR pszPassword,
ULONG ulPasswordBufferSize,
BOOL* save,
DWORD dwFlags
);
typedef DWORD(*P_CredUIParseUserNameW)(
PCWSTR UserName,
WCHAR* user,
ULONG userBufferSize,
WCHAR* domain,
ULONG domainBufferSize
);
do {

//
Expand Down Expand Up @@ -1232,12 +1252,90 @@ int Program_Start(void)

ULONG64 ProcessFlags = SbieApi_QueryProcessInfo(0, 0);
if (! (ProcessFlags & SBIE_FLAG_DROP_RIGHTS)) {

if (SbieApi_QueryConfBool(NULL, L"ElevateWithPwOnly", FALSE)) {
PCREDUI_INFOW info = new CREDUI_INFOW();
info->cbSize = sizeof(CREDUI_INFO);
info->hbmBanner = NULL;
info->hwndParent = NULL;
info->pszCaptionText = SbieDll_FormatMessage0(3257);
info->pszMessageText = SbieDll_FormatMessage0(3258);

//P_CredUIPromptForCredentialsW rupfc = (P_CredUIPromptForCredentialsW)GetProcAddress(GetModuleHandleW(L"Credui.dll"), "CredUIPromptForCredentialsW");
//P_CredUIParseUserNameW cupun=(P_CredUIParseUserNameW)GetProcAddress(GetModuleHandleW(L"Credui.dll"), "CredUIParseUserNameW");
//if (rupfc&&cupun)
//{
BOOL bSave = false;
LPWSTR username = (WCHAR*)malloc(100), password = (WCHAR*)malloc(100), appName = const_cast<WCHAR*>(L"Start.exe");
memset(username, 0, 100);
memset(password, 0, 100);
if (CredUIPromptForCredentialsW(info, appName, NULL, 0, username, 100, password, 100, &bSave, CREDUI_FLAGS_COMPLETE_USERNAME | CREDUI_FLAGS_EXPECT_CONFIRMATION | CREDUI_FLAGS_REQUEST_ADMINISTRATOR | CREDUI_FLAGS_USERNAME_TARGET_CREDENTIALS | CREDUI_FLAGS_VALIDATE_USERNAME | CREDUI_FLAGS_DO_NOT_PERSIST | CREDUI_FLAGS_INCORRECT_PASSWORD | CREDUI_FLAGS_PASSWORD_ONLY_OK) == NO_ERROR) {
LPWSTR user = (WCHAR*)malloc(100), domain = (WCHAR*)malloc(100);
memset(user, 0, 100);
memset(domain, 0, 100);
CredUIParseUserName(username, user, 100, domain, 100);
HANDLE tempToken = NULL;
if (!LogonUser(user, domain, password, LOGON32_LOGON_BATCH, LOGON32_PROVIDER_DEFAULT, &tempToken)) {
MessageBox(NULL, SbieDll_FormatMessage0(3259), L"Sandboxie Start", MB_OK);
goto skipElevate;
}
CredUIConfirmCredentialsW(appName, FALSE);
CloseHandle(tempToken);
free(user);
free(domain);

}
//}
///else {
// MessageBox(NULL, SbieDll_FormatMessage0(3259), L"Sandboxie Start", MB_OK);
// goto skipElevate;
//}
}
shExecInfo.lpVerb = L"runas";
}
}
}
else {
if (SbieApi_QueryConfBool(NULL, L"ElevateWithPwOnly", FALSE)) {
PCREDUI_INFOW info = new CREDUI_INFOW();
info->cbSize = sizeof(CREDUI_INFO);
info->hbmBanner = NULL;
info->hwndParent = NULL;
info->pszCaptionText = SbieDll_FormatMessage0(3257);
info->pszMessageText = SbieDll_FormatMessage0(3258);

//P_CredUIPromptForCredentialsW rupfc = (P_CredUIPromptForCredentialsW)GetProcAddress(GetModuleHandleW(L"Credui.dll"), "CredUIPromptForCredentialsW");
//P_CredUIParseUserNameW cupun = (P_CredUIParseUserNameW)GetProcAddress(GetModuleHandleW(L"Credui.dll"), "CredUIParseUserNameW");
//if (rupfc && cupun)
//{
BOOL bSave = false;
LPWSTR username = (WCHAR*)malloc(100), password = (WCHAR*)malloc(100), appName = const_cast<WCHAR*>(L"Start.exe");
memset(username, 0, 100);
memset(password, 0, 100);
if (CredUIPromptForCredentialsW(info, appName, NULL, 0, username, 100, password, 100, &bSave, CREDUI_FLAGS_COMPLETE_USERNAME | CREDUI_FLAGS_EXPECT_CONFIRMATION | CREDUI_FLAGS_REQUEST_ADMINISTRATOR | CREDUI_FLAGS_USERNAME_TARGET_CREDENTIALS | CREDUI_FLAGS_VALIDATE_USERNAME | CREDUI_FLAGS_DO_NOT_PERSIST | CREDUI_FLAGS_INCORRECT_PASSWORD | CREDUI_FLAGS_PASSWORD_ONLY_OK) == NO_ERROR) {
//CredUIPromptForCredentialsW(info, appName, NULL, 0, username, 100, password, 100, &saved, CREDUI_FLAGS_COMPLETE_USERNAME | CREDUI_FLAGS_EXPECT_CONFIRMATION | CREDUI_FLAGS_REQUEST_ADMINISTRATOR | CREDUI_FLAGS_USERNAME_TARGET_CREDENTIALS | CREDUI_FLAGS_VALIDATE_USERNAME | CREDUI_FLAGS_DO_NOT_PERSIST| CREDUI_FLAGS_INCORRECT_PASSWORD| CREDUI_FLAGS_PASSWORD_ONLY_OK)
LPWSTR user = (WCHAR*)malloc(100), domain = (WCHAR*)malloc(100);
memset(user, 0, 100);
memset(domain, 0, 100);
CredUIParseUserNameW(username, user, 100, domain, 100);
HANDLE tempToken = NULL;
if (!LogonUser(user, domain, password, LOGON32_LOGON_BATCH, LOGON32_PROVIDER_DEFAULT, &tempToken)) {
MessageBox(NULL, SbieDll_FormatMessage0(3260), L"Sandboxie Start", MB_OK);
SbieApi_Log(3999, L"%d", GetLastError);
return EXIT_FAILURE;
}
CredUIConfirmCredentialsW(appName, FALSE);
CloseHandle(tempToken);
free(user);
free(domain);
}
//}
//else {
// MessageBox(NULL, SbieDll_FormatMessage0(3260), L"Sandboxie Start", MB_OK);
// return EXIT_FAILURE;
//}
}
}
}

skipElevate:
//
// make sure AppHelp.dll is loaded, so third party software like
// EMET which relies on injection through ShimEng/AppHelp can work.
Expand Down
16 changes: 16 additions & 0 deletions Sandboxie/msgs/Sbie-English-1033.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,22 @@ Option is disabled because the Drop Rights setting is enabled for this sandbox
Option is disabled because this program is already running with Administrator privileges
.

3257;txt;01
Sandboxie Start Prompt
.

3258;txt;01
You are starting a program which need to elevate in the box.Please input the administrator account's password.
.

3259;txt;01
Something wrong happened.The program will start with normal privallige.
.

3260;txt;01
Something wrong happened.The program won't start in built-in administrator account.
.

#----------------------------------------------------------------------------
# Sandboxie Control Common
#----------------------------------------------------------------------------
Expand Down