GithubHelp home page GithubHelp logo

falahati / uachelper Goto Github PK

View Code? Open in Web Editor NEW
70.0 8.0 21.0 158 KB

A helper class library to detect, manage and use UAC functionalities in your program.

License: MIT License

C# 100.00%
uac uac-virtualization uac-functionalities elevation uac-shield-icon

uachelper's Introduction

UAC Helper Class Library

A helper class library to detect, manage and use UAC functionalities in your program

How to get

This library is available as a NuGet package at nuget.org.

Help me fund my own Death Star

--OR--

You can always donate your time by contributing to the project or by introducing it to others.

How to use

Currently there are three main classes in this library:

UACHelper.UACHelper

This static class contains properties about the current state of the application as well as providing methods to get information about other processes and starting new ones.

[Static Read Only Properties]
  • UACHelper.IsElevated: A Boolean value indicating if the current process has full administrative rights
  • UACHelper.IsUACSupported: A Boolean value indicating if UAC virtualization is supported on the current machine
  • UACHelper.IsDesktopOwner: A Boolean value indicating if the user that owns this process also owns the desktop session
  • UACHelper.IsVirtualized: A Boolean value indicating if the current process started under UAC virtualization
  • UACHelper.IsAdministrator: A Boolean value indicating if the user that owns this process is a member of the 'Administrators' group
  • UACHelper.IsUACEnable: A Boolean value indicating if the UAC vitalization is enable on this machine
  • UACHelper.DesktopOwner: Returns a NTAccount object containing information about the current desktop owner
  • UACHelper.Owner: Returns a WindowsIdentity object containing information about the current process owner
[Static Methods]
  • UACHelper.GetProcessDesktopOwner(): Returns a NTAccount object containing information about the desktop owner of a specific Process
  • UACHelper.GetProcessOwner(): Returns a WindowsIdentity object containing information about the owner of a specific Process
  • UACHelper.IsProcessElevated(): Indicates if the passed Process started with elevated privileges
  • UACHelper.GetExpectedRunlevel(): Checks a file and retrieve the expected RunLevel for it to start
  • UACHelper.StartElevated(): Starts a new elevated Process with the start info provided
  • UACHelper.StartLimited(): Starts a new Process with the start info provided and with the limited access rights
  • UACHelper.StartLimitedTask(): Starts a new process with the task info provided and with the limited access rights using TaskScheduler service
  • UACHelper.StartWithShell(): Starts a new Process with the start info provided and with the same rights as the current active shell process
  • UACHelper.StartByShell(): Starts a new Process with the start info provided using the current shell desktop IShellDispatch2.ShellExecute() method.
  • UACHelper.StartAndCopyProcessPermission(): Starts a new Process with the start info provided and with the same rights as the mentioned Process

UACHelper.AAMSettings

This static class contains settings of the "Admin Approval Mode"

[Static Properties]
  • AAMSettings.IsEnable: Enables the "administrator in Admin Approval Mode" user type while also enabling all other User Account Control (UAC) policies. Requires restart.
  • AAMSettings.EnforceAdminCodeSignatures: Enforce cryptographic signatures on any interactive application that requests elevation of privilege.
  • AAMSettings.ForceDimPromptScreen: Will force all UAC prompts to happen on the user's secure desktop.
  • AAMSettings.IsVirtualizationEnable: Enables the redirection of legacy application File and Registry writes that would normally fail as standard user to a user-writable data location.
  • AAMSettings.IsInstallerDetectionEnable: Used to heuristically detect applications that require an elevation of privilege to install.
  • AAMSettings.UserPromptBehavior: AAM behaviors regarding users running elevated applications
  • AAMSettings.AdminPromptBehavior: AAM behaviors regarding administrators' changes to system

UACHelper.WinForm

This static class contains multiple methods to add the UAC shield icon to the buttons, forms and native dialogs

[Static Methods]
  • WinForm.ShieldifyNativeDialog: Goes through the controls in the native dialog and adds the UAC shield icon to the desired native button.
  • WinForm.ShieldifyNativeButton: Adds the UAC shield icon to the button
  • WinForm.ShieldifyForm: Goes through the controls in the Form and adds the UAC shield icon to the desired Button. Then calls the Form.ShowDialog to display the form.
  • WinForm.ShieldifyButton: Changes the Button.FlatStyle to FlatStyle.System and adds the UAC shield icon
[Extension Methods]
  • Form.ShowDialog: Alias of WinForm.ShieldifyForm
  • Form.ShieldifyButton: Alias of WinForm.ShieldifyButton

Examples

Check the 'UACHelper.Sample' for tons of examples on how to use the library. Screenshot

  • Restart the current program in Elevated Mode:
UACHelper.StartElevated(
    new ProcessStartInfo(Assembly.GetExecutingAssembly().Location)
);
  • Restart the current program in Limited Mode:
UACHelper.StartLimited(
    new ProcessStartInfo(Assembly.GetExecutingAssembly().Location)
);

To do

License

The MIT License (MIT)

Copyright (c) 2016-2020 Soroush

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

uachelper's People

Contributors

falahati avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

uachelper's Issues

StartLimitedTask will duplicate the instances

Using the function above I ran into the issue that a non elevated task would start a duplicate instance.

Im assuming the issue is that withing the method as it first starts a process and then also starts another task:

image

By removing the code marked as (1) the issue was resolved.

StartElevated throws NotSupportedException.

The full messaegs is:
System.NotSupportedException: 'CreateProcess is not supported for starting an elevated process. Consider using ShellExecute by setting UseShellExecute to true.'

Process owner, Elevation state, and Integrity level do not always ensure the proper permissions

I did a quick look-through of the current code and didn't find any references to the process's ACLs. I'd love it if you prove me wrong because that means there's nothing to fix!

P.S. after a few days of search engines, compiling edits of solutions on StackOverflow, and floundering around, this Issue helped me figure out exactly what I needed to do in my Intern library.

  • The built-in Administrator user account and similar accounts are capable of starting unelevated processes as needed.
  • There's also the rare-case issue of semi-elevated processes created when an elevated process fails to properly create an unelevated child process.
  • An "elevated" process could have its ACLs changed to deny permissions it should normally have.
  • When using Process Hacker 3 to start a process with Elevated status and TrustedInstaller permissions, it first creates a "TrustedInstaller.exe" process which then spawns a subprocess of the specified application.
    The ACLs of the child process in the given situation are...
    Screenshot 2021-06-11 015032

Sources:

Limited Start Bug

Dear friends,
On a Windows 7 OS in a case when there is only Administrator user without assigned password, token can't be linked and token elevation type is default. If you look in class UACHelper,
function Process StartLimited(ProcessStartInfo startInfo), you can see that in a case when an extracted process owner is in Administrator group and its extracted token is default token elevation type, token won't be copied and process won't be started.

if (processIdentity.User?.Equals(sessionOwner) == true) // Same Terminal Session
                    {
                        var elevationType = Tokens.GetTokenElevationType(processIdentity.Token);
                        if (elevationType == TokenElevationType.Limited ||
                            (elevationType == TokenElevationType.Default &&
                             !new WindowsPrincipal(processIdentity).IsInRole(WindowsBuiltInRole.Administrator)))
                        {
                            return StartAndCopyProcessPermission(process, startInfo);
                        }
                    }

Did you have this problem? Why did you used role check in this if? I simply removed it, and solved this problem, but i wanted to check this with you.
Best regards.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.