PowerShell Execution Checks - OS Test
PowerShell execution policies are security mechanisms that control the conditions under which PowerShell scripts and configuration files can run on a Windows system. The policies help reduce the risk of executing malicious or untrusted scripts by enforcing different levels of script execution restrictions. PowerShell supports the following execution policies:
AllSigned - Allows only scripts and configuration files that are digitally signed by a trusted publisher to run. Scripts from untrusted publishers require user approval.
RemoteSigned - Requires a trusted digital signature only for scripts downloaded from the internet, while locally created scripts can run without a signature.
Restricted - Prevents the execution of all PowerShell scripts, allowing only interactive PowerShell commands.
Unrestricted - Allows all scripts to run, but warns users before executing scripts downloaded from outside the local intranet.
Bypass - Allows all scripts to run without restrictions, prompts, or warnings. This policy is typically intended for applications that host PowerShell and implement their own security model.
These execution policies are however not absolute. Administrators can override the system-level execution policy by configuring a different policy for the current user or the current PowerShell session. They can also bypass an execution policy by running script commands directly from the PowerShell command line.
Even when a secure execution policy such as AllSigned or RemoteSigned is configured at the system level, PowerShell scripts can still be executed by overriding or bypassing the policy. As a result, unsigned scripts or scripts running with Unrestricted or Bypass policies may execute, increasing the risk of malicious scripts gaining unauthorized access to sensitive data and compromising system security.
To mitigate these risks, administrators should verify the execution policy configured on each system, identify PowerShell scripts that override the configured policy, and review such scripts for potential security threats. The PowerShell Execution Checks test helps administrators accomplish these tasks by providing visibility into execution policies and identifying scripts that may compromise system security.
This test monitors PowerShell scripts running on the each Windows system in the target Windows Systems Group and reports the number of scripts executing with risky execution policies. The test It also reports the configured PowerShell execution policy for each system, enabling administrators to quickly identify scripts that override the configured policy. Detailed diagnostics provide the name and location of these scripts, allowing administrators to review them and determine whether they pose a potential security risk.
Note:
This test retrieves metrics from the Windows PowerShell logs. To enable the test to collect the required data, ensure that Module Logging, Script Execution Logging, and PowerShell Script Block Logging are enabled on each monitored Windows system. To configure these settings, refer to Configuring Logging Settings.
This test is disabled by default. To enable the test, go to the enable / disable tests page using the menu sequence : Agents -> Tests -> Enable/Disable, pick the desired Component type, set Performance as the Test type, choose the test from the disabled tests list, and click on the < button to move the test to the ENABLED TESTS list. Finally, click the Update button.
Target of the test :A Windows Systems Group
Agent deploying the test : A remote agent
Output of the test : One set of results will be reported for every Windows system
| Parameter | Description |
|---|---|
|
Test Period |
How often should the test be executed. |
|
Host |
The host for which the test is to be configured. |
|
Port |
Specify the port at which the target component listens to. The default port is NULL. |
|
Inside View Using |
To obtain the 'inside view' of performance of the systems - i.e., to measure the internal performance of the systems - this test uses a light-weight eG VM Agent software deployed on each of the systems. Accordingly, this parameter is by default set to eG VM Agent. |
|
Report By User |
This flag is set to No by default. This implies that the Windows systems in environments will always be identified using the system name. In other words, this test will, by default, report measures for every systemname. On the other hand, if you want this test to report the measures for every user on a system, then set this flag to Yes. In such a case, this test will report the measures for every username_on_systemname. |
|
Report Powered OS |
By default, this flag is set to Yes, then the 'inside view' tests will report measures for even those Windows systems that do not have any users logged in currently. The systems will be identified by their name and not by the username_on_systemname. On the other hand, if this flag is set to No, then this test will not report measures for those systems to which no users are logged in currently. |
|
Is Cloud VMs? |
This flag is set to Yes by default. The value of this flag cannot be changed. This implies that the cloud-based Windows systems in environments will always be identified using the login name of the user. In other words, in cloud environments, this test will, by default, report measures for every username_on_systemname. |
|
Ignored Paths |
Provide a comma-separated list of paths that needs to be excluded from monitoring in the Ignored Paths text box. Wild card characters can be used to indicate file paths- for eg., to ignore all file paths that contains the word 'agent', your specification can be: *agent*. By default, this parameter is set to *egurkha* indicating that all file paths that contains egurkha are excluded from monitoring. You can change this default setting if you need. |
|
Detailed Diagnosis |
To make diagnosis more efficient and accurate, the eG Enterprise embeds an optional detailed diagnostic capability. With this capability, the eG agents can be configured to run detailed, more elaborate tests as and when specific problems are detected. To enable the detailed diagnosis capability of this test for a particular server, choose the On option. To disable the capability, click on the Off option. The option to selectively enable/disable the detailed diagnosis capability will be available only if the following conditions are fulfilled:
|
| Measurement | Description | Measurement Unit | Interpretation | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Unsigned executed scripts count |
Indicates the number of unsigned PowerShell scripts that are currently executing on this system. |
Number |
Ideally, the value of this measure should be low. A high value of this measure means that many unsigned scripts are being executed on the monitored Windows system. This increases the probability of malicious scripts being executed, which can be detrimental to the safety and overall health of your system. In such a case therefore, use the detailed diagnosis of this measure to know which unsigned scripts were executed, how frequently, and from which folder. With the help of this information, administrators can quickly identify the potentially 'unsafe' scripts, and review those scripts to see if they can be allowed to run going forward. |
||||||||||||||||
|
Scripts executed with unrestricted execution policy |
Indicates the number of scripts that are running with the Unrestricted execution policy. |
Number |
The Unrestricted execution policy allows unsigned scripts to be run, which in turn can be a potential security risk to your systems. This is why, a low value is desired for this measure. If this measure reports a high value, you are advised to use the detailed diagnosis of this measure to identify the scripts that are running with this policy, and where they are located. You may want to scrutinize the scripts to look for security holes. |
||||||||||||||||
|
Scripts executed with remote signed execution policy |
Indicates the number of scripts that are running currently with the RemoteSigned execution policy. |
Number |
The RemoteSigned policy allows scripts downloaded from the internet to run only if they are signed by a trusted publisher. Though this policy is more secure, it allows unsigned scripts to run, if they are written on the local computer. Likewise, unblocked scripts are allowed to run under this policy, even if they are unsigned and downloaded from the internet. So, this policy does introduce an element of 'risk' to your mission-critical systems/servers. Therefore, if the value of this measure reports a non-zero value, its best to use the detailed diagnosis of the measure to know which scripts are using the RemoteSigned policy, and where these scripts are stored. Using this information, you can quickly pull up these scripts for a closer look, so you can confirm that they are safe to run. |
||||||||||||||||
|
Scripts executed with bypass execution policy |
Indicates the number of scripts that are running currently with the Bypass execution policy. |
Number |
Bypass is one of the 'less-safe' execution policies as it allows script execution without putting up a fight - i.e., without any blocks, warnings, or prompts. Ideally therefore, the value of this measure should be low. If a high value is reported, then use the detailed diagnosis of the measure to know which scripts are running with the Bypass policy, how frequently, and where are the scripts located. These details will help you look into such scripts and corroborate their safety and authenticity. |
||||||||||||||||
|
System PowerShell execution policy |
Indicates the PowerShell execution policy that is currently set at this system. |
Number |
The values that this measure reports and the execution policies they represent are tabulated below:
You may want to compare the value of this measure with that of the measures to know if the system's policy was overridden during script execution. |
Configuring Logging Settings
To enable the Module Logging, Script Execution Logging, and PowerShell Script Block Logging, follow the steps given below:
-
Login to the target Windows system.
-
With the Windows icon on the key board pressed, press the R key, to open the Run prompt. At the prompt, type gpmc.msc, see Figure 1
-
This will open the Group Policy Management Console.
-
Then open the Group Policy Management Editor and edit or create a new GPO. For that, right-click Group Policy Objects in the domain where the GPO is to be created and select New. This will invoke Figure 2, in the New GPO dialog box in Figure 2, specify a name for the new GPO, and then click OK . (or) Open the Group Policy Objects node. Right-click the appropriate GPO, and click Edit.
-
To configure policies, expand the Computer Configuration node in the left panel of Figure 3 and select its Policies sub-node and then navigate to Administrative Templates ->Windows Components . Select Windows Powershell setting from the right panel of Figure 3.
Figure 3 : Selecting Windows Powershell setting from Windows Components
-
This will invoke Figure 4 .Right-click Turn on Module Logging in the Windows Power Shell Setting, then select Edit.
-
In the window that appears, click the Enabled radio button. Click on the Apply and OK buttons. Next, click on the Show button in the Optionsand Show contents section will appear. Double-click on the first cell under the Value column to make it editable. Then, specify Microsoft.Powershell.* therein, so that logging is enabled for all PowerShell modules. Then, click the OK button in Show contentssection to save the changes.
Figure 4 : Selecting and enabling the Turn on Module Logging option
-
Similarly, Turn on PowerShell Script Block Logging in the Windows Power Shell Setting. See Figure 5
Figure 5 : Selecting and enabling Turn on Powershell Script Block Logging option
-
Now to enable Turn on Script Execution setting, right-click Turn on Script Execution in the Windows Power Shell Setting, then select Edit. This will invoke Figure 6. Then, select Allow local scripts and remote signed scripts from the Execution policy drop-down in Figure 6. Then, click the OK button.
-
This will take you back to Windows Power Shell Setting, where you can see that the Turn on Module Logging, Turn on Script Execution, and Turn on PowerShell Script Block Loggingsettings now displays Enabled as the State.
-
Apply the GPO to the appropriate organizational unit (OU) or computer.