forderud / runinsandbox Goto Github PK
View Code? Open in Web Editor NEWLaunch Windows executables & COM servers in a sandboxed or elevated environment.
License: MIT License
Launch Windows executables & COM servers in a sandboxed or elevated environment.
License: MIT License
Steps to reproduce:
"C:\Dev\RunInSandbox\x64\Debug\TestControl.exe" -Embedding
x64\Debug\RunInSandbox.exe TestControl.TestControl
Docs: https://learn.microsoft.com/en-us/windows/win32/com/the-com-elevation-moniker
HKEY_LOCAL_MACHINE\Software\Classes\AppID\{APPID}\ROTFlags = 0x01
: Didn't help (need to switch to ROT to make it work)HKEY_LOCAL_MACHINE\Software\Classes\AppID\{APPID}\RunAs = "Interactive User"
: Did help 👍.Net wpf-test problem report: DuplicateTokenEx ImpersonationLevel type mismatches
Steps to reproduce:
MyAdmin
account that is member of the "Administrators" group.ComRunAs.exe {264FBADA-8FEF-44B7-801E-B728A1749B5A} MyAdmin <pw>
RunInSandbox.exe TestControl.TestControl
.ERROR: The server process could not be started because the configured identity is incorrect. Check the username and password.
Component Services
configure "TestControl object" to run with MyAdmin
as identityRunInSandbox.exe TestControl.TestControl
.mi_token_from_uac.txt
mi_proc_from_elevated.txt
mi_proc_from_uac.txt
mi_token_from_elevated.txt
A hint from me: plz add an OutputDebugString before SetCursorPos and log the GetForegroundWindow() to ensure the foreground window is the expected one. Why OutputDebugString? It calls the underlying DbgPrint in kernel level and has minimal impact to possible shift of windows focus. BTW it is my favorite debugging log func since Windows 95, where it was first publicly available.
Are the relevant UIPI rules documented somewhere, so that I can study them carefully? I’m especially interested in the precise definition of “foreground window” for nested window hierarchies spanning processes running at different integrity levels.
the foreground window is the window, which a) receives the user input at this moment and b) is processed by thread processing current input windows messages - aka foreground thread. Foreground window doesn't belong necessary to the currently running app (it isn't the active window of the app).
If Word activates an embedded Visio drawing for editing by user, the foreground window is not the word window but the visio.
Any tips on how I can get more detailed diagnostics on the failing SetCursorPos call? Is there a system log somewhere that reveal more clues about the precise reason for the failure?
yes, you can try kernel debugger int win32k.sys and set breakpoint to
win32kfull!zzzSetCursorPos
ba0 e 1 win32kfull!zzzSetCursorPos "dx -r0 win32kbase!gpqForeground->uipiInfo->dwIntegrityLevel;dx ((win32kbase!THREADINFO*)(((win32kbase!W32THREADNONPAGED*)((nt!ETHREAD*)@$thread)->Tcb.Win32Thread)->pW32Thread))->ppi->uipiInfo->dwIntegrityLevel"
Hey, thanks for this project and helping me to get started with AppContainers. Few system apps work fine. I've been trying to containerize an electron app but almost all of them fail to launch in less than medium integrity level even with broad set of permissions.
Lets take Signal messenger as an example here. Can you please have a look and let me know if I'm missing some key minor aspects. It would be very helpful if I can get a demo electron app working inside the AppContainer.
.Net bug report: dotnet/runtime#96397
IMPACT: It's currently not possible to implement startup of apps in sandboxed processes due to this bug.
https://github.com/search?q=repo%3Adotnet%2Fruntime%20DuplicateTokenEx&type=code
Make a tool for configuring AppID RunAs
credentials from the command-line. Use https://github.com/forderud/RunInSandbox/blob/master/RunInSandbox/RunAs.hpp as starting point.
Attempting to run "RunInSandbox.exe TestControl.TestControl <username> <password>
" works fine when impersonating an admin user. However, it fails with with: hr = 0x80080005 : Server execution failed
when attempting to impersonate a non-admin user.
The following event is also logged in the Windows System event log:
The server {F0DFBE77-1697-428E-A895-EFEE202B9333} did not register with DCOM within the required timeout.
Enable TestControl Object
DCOM local "launch" and "activation" permissions for the impersonated user. Failure to do so will lead to CoCreateInstance failing with E_ACCESSDENIED
.
This can also be enabled globally through the default DCOM launch & activation permissions:
RunInSandbox.exe TestControl.TestControl <username> <password>
" fails with CO_E_SERVER_EXEC_FAILURERunInSandbox.exe TestControl.TestControl <username> <password>
" now succeed.Revert effbe35 that uses LogonUser
Observed problem: SetCursorPos
calls fail in a medium IL COM/OLE control when running as child window within an elevated (high IL) host process.
The reason for this failure seem to be that UIPI silently blocks SetForegroundWindow
calls in the medium IL COM/OLE control after setting WS_CHILD
window style and connecting it to the host window through SetParent
. This happens despite the host having called CoAllowSetForegroundWindow
first.
RunInSandbox.exe mi TestControl.TestControl
Moving mouse cursor to top-left corner...
[FAILED] Access is denied.
This problem does not occur if running RunInSandbox.exe mi TestControl.TestControl
from a non-elevated command prompt.
Applying any one of the changes below will make the problem go away:
1, Stop setting the WS_CHILD
window style.
2. Stop calling SetParent(child_wnd, wnd)
.
3. Run SetCursorPos
from a non-main thread in the COM/OLE process (change the first MoveMouseCursor
argument to true).
Tweak 1. and 2. does not seem attractive, since they would undermine the child window UI integration. Tweak 3. is furthermore not attractive, since it would require invasive changes to the COM/OLE control to make it "parent IL aware".
I'm therefore seeking a non-invasive way of "granting" the COM/OLE control permission to SetForegroundWindow
or being allowed to send SetCursorPos
events to the high IL parent window also after being attached as a child window.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.