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

update ::user privilege to access powershell #21544

Open
AbishekPonmudi opened this issue Apr 27, 2024 · 9 comments
Open

update ::user privilege to access powershell #21544

AbishekPonmudi opened this issue Apr 27, 2024 · 9 comments
Labels
Issue-Enhancement the issue is more of a feature request than a bug

Comments

@AbishekPonmudi
Copy link

Summary of the new feature / enhancement

Command Privilege Management Feature for PowerShell

Overview

I introduces a new feature for PowerShell, focusing on Command Privilege Management. The feature enhances security by allowing authorized users to run admin commands and access PowerShell. It functions in both admin and non-admin PowerShell environments, safeguarding against unauthorized activity by requiring credentials, including both username and password, to access PowerShell.

Script Details

The PowerShell script included in this request checks whether it is running with administrative privileges and prompts the user for credentials if necessary. It also sets registry values to enable command prompt and PowerShell with user authentication, ensuring a secure environment for script execution.

How It Works

  1. The script first checks if it is running with administrative privileges.
  2. If not, and if the specified choice is to apply only for admin PowerShell sessions, the script exits.
  3. The script defines variables for registry key and value names.
  4. Functions are provided to set registry values, close the PowerShell window, and prompt for credentials.
  5. When executed, the script prompts the user for credentials, allowing access only to authorized users with correct credentials.
  6. Additional operations can be performed after successful authentication.

Explained

  • Command Privilege Management: A security feature that controls access to administrative commands and PowerShell functionality.
  • Registry Values: Configuration settings stored in the Windows registry.
  • Administrative Privileges: Elevated permissions required to perform certain actions on a system.
  • Credentials: User authentication information, including username and password, used to verify identity and access rights.

Contribution Assistance Needed

I have developed this extension but am encountering difficulties contributing. Any assistance regarding this issue would be greatly appreciated.

Reference

GitHub Repository

Proposed technical implementation details (optional)

No response

@AbishekPonmudi AbishekPonmudi added Issue-Enhancement the issue is more of a feature request than a bug Needs-Triage The issue is new and needs to be triaged by a work group. labels Apr 27, 2024
@rhubarb-geek-nz
Copy link

rhubarb-geek-nz commented Apr 27, 2024

Windows already has a system of User Access Control, I am not sure what this project is trying to achieve.

Are you trying to protect individual scripts or resources or allow only a specific set of users run pwsh.exe ?

If you want to prevent access to pwsh.exe then a better approach would be a custom build and installation of pwsh.exe with the UAC requirements in the application manifest.

If you want to protect access to specific scripts then put the scripts in directories with file permissions that allow only specific users access, but that does not protect whatever it was the scripts accessed. Eg if you can still access those resources without a specific powershell script then you have not actually achieved anything.

And press Y to apply the changes Don't worry about the script it is just a enable command

Just to confirm, your first step in securing the system is to disable existing security measures?

You are granting access by a plain text credentials.xml file. I suggest a system of requiring that the current user belongs to a specific group within the existing security system would be better than rolling your own password authentication.

@microsoft-github-policy-service microsoft-github-policy-service bot removed the Needs-Triage The issue is new and needs to be triaged by a work group. label Apr 27, 2024
@AbishekPonmudi
Copy link
Author

Thank you for your feedback and for taking the time to review the Command Privilege Management feature for PowerShell.

While Windows does indeed have User Access Control (UAC) mechanisms in place, the intention behind this project is to provide an additional layer of granular control over access and command execution within PowerShell. The goal is not to replace existing security measures but to complement them by offering administrators the ability to tailor access permissions to PowerShell and scripts based on their specific organizational requirements.

Indeed, one of the primary objectives of this script is to mitigate potential security risks by adding an additional layer of authentication to PowerShell access. By requiring users to provide a username and password before gaining access to PowerShell, we aim to prevent unauthorized individuals from exploiting system vulnerabilities or executing malicious payloads and some type of shellcode injection.

To address your points:

Protecting Individual Scripts or Resources: The project aims to provide normal users and administrators with the capability to control access PowerShell, ensuring that only authorized users can access and execute them. By requiring credentials for access, it adds an extra layer of security to sensitive operations.

Custom Build and Installation of pwsh.exe: While a custom build of pwsh.exe with UAC(USER ACCESS CONTROL) requirements in the application manifest could be an option, it may not offer the same level of flexibility and granularity as our proposed solution. Our approach allows for fine-grained control over powershell and command execution without the need for extensive modifications to the PowerShell executable.

Protection of Access to Specific Scripts: By understand the importance of securing access to powershell, and my project complements this by providing an additional layer of authentication and authorization. By controlling access to PowerShell and command execution, it helps ensure that only authorized users can interact with sensitive resources.

We believe that by empowering administrators with tools to manage privileges within PowerShell, organizations can enhance their overall security posture and mitigate the risk of unauthorized access , misuse of system resources and exploiting system vulnerabilities or executing malicious payloads and some type of shellcode injection .

I think that you are satisfied with my answers .If you have any further questions or concerns, we would be happy to discuss them and address any specific use cases or scenarios you may have in mind.

shell_script_bl
shell_script_bl2
shell_script_bl3

@rhubarb-geek-nz
Copy link

Thanks for that. Just so you know what is already available, I wrote rhubarb-geek-nz.LocalSecurityAuthority with its repository at github

This lets you manage privileges for local users using PowerShell. I used it for managing accounts that need rights to use services. It might be useful.

I encourage you to also think about how your solution will be packaged, say either as a PowerShell module from PSGallery or installed via MSI.

@AbishekPonmudi AbishekPonmudi changed the title update::user privilege to access powershell update ::user privilege to access powershell Apr 27, 2024
@AbishekPonmudi
Copy link
Author

Thank you for sharing the information and providing insights into alternative solutions like rhubarb-geek-nz.LocalSecurityAuthority. I'll definitely explore your tool further to see how it aligns with our project requirements.

Regarding packaging our solution, your suggestions are valuable. We'll consider both options - publishing our solution as a PowerShell module on PS Gallery and creating an MSI installer for distribution.

And I appreciate your guidance and will keep you updated on our progress. If you have any additional feedback or suggestions as we move forward, and suggest me a way to contribute in the open source project like PowerShell, because I am a 2 year student which will help me to improve my knowledge and experience , Your expertise is more valuable to me.

@rhubarb-geek-nz
Copy link

When executed, the script prompts the user for credentials, allowing access only to authorized users with correct credentials.
Additional operations can be performed after successful authentication.

A script by itself can't protect anything. Unless entering credentials runs a new process with new permissions or returns a token that would have otherwise been unavailable then the user has exactly the same permissions as before the credential check. Scripts are plain text files. All a user has to do is open the text file and remove the credential check.
The best defence that PowerShell scripts have is when they are required to be signed before they run. However even with signed scripts the user is still in control and can use -ExecutionPolicy ByPass to literally bypass that defence.

@AbishekPonmudi
Copy link
Author

AbishekPonmudi commented Apr 28, 2024

Yeah you are correct, about the security of the script is valid . while the script prompt the user credentials the actual execution of the script does not change the user permission or restrict access , this just run when the powershell is triggered but the user still view and modify the script , and potentially bypassing the authentication mechanism is true by our point , but i am wokring toward to secure this flaws.that the current script has limitations in terms of protecting against tampering or bypassing the credential check. To enhance security, I'll explore options like executing critical operations in restricted environments, applying least privilege principles, and implementing stronger authentication mechanisms. I appreciate

your feedback and will work towards improving the script's security posture.

Yes, the concern about bypassing the script using the -ExecutionPolicy Bypass option is valid. The -ExecutionPolicy Bypass parameter allows users to run PowerShell scripts regardless of the execution policy configured on the system. This means that even if the script is signed or if a restrictive execution policy is enforced, users can still bypass these protections by explicitly specifying the -ExecutionPolicy Bypass parameter when running the script.

you valuable reply will help me to improve well

@krzydoug
Copy link

Maybe I'm misunderstanding, but wouldn't this be a perfect time to use JEA? (just enough administration)

JEA allows you to specify what commands a user can run and can even restrict what parameters of a specific cmdlet can be used.

@AbishekPonmudi
Copy link
Author

Just Enough Administration (JEA) provides role-based access control, allowing authorized users to execute specific commands. However, it differs from traditional role-based access control by requiring an additional authentication method for if the account is belong to either of admin and non-admin users to access PowerShell. This extra layer of security prevents malicious actors from exploiting any security flaws or payloads to gain unauthorized access to another account with compromised accounts. Additionally, I've developed a proof of concept (POC) demonstrating the effectiveness of blocking malicious activities.

@dwtaber
Copy link
Contributor

dwtaber commented Apr 30, 2024

At a glance, it looks like the credentials prompt is triggered by a command added to the user's profile script. Setting aside the user's ability to edit the file, it looks like powershell -noprofile would also bypass your script entirely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Enhancement the issue is more of a feature request than a bug
Projects
None yet
Development

No branches or pull requests

4 participants