Query Details
**Potential commands executed by a powerShell.exe renamed** PowerShell is a trusted Microsoft tool that attackers can misuse by renaming its executable file to hide their actions and deliver threats. The following query, detect cli common commands to identify the mentioned executions by a renamed Powershell. ``` DeviceProcessEvents | where ProcessCommandLine !contains "powershell" | where ProcessCommandLine !contains "pwsh" | where ProcessCommandLine contains "-NoProfile" or ProcessCommandLine contains "-ExecutionPolicy" or ProcessCommandLine contains "Invoke-Expression" | project DeviceName, FileName,ActionType, ProcessVersionInfoOriginalFileName, ProcessCommandLine, ProcessRemoteSessionIP ```
This query is designed to detect potentially malicious activities involving the use of PowerShell when its executable has been renamed to avoid detection. Here's a simple breakdown of what the query does:
Data Source: It looks at events related to processes on devices (DeviceProcessEvents).
Filtering:
-NoProfile: This option starts PowerShell without loading the user's profile, which can be used to avoid detection.-ExecutionPolicy: This option changes the execution policy, potentially allowing scripts to run that would otherwise be blocked.Invoke-Expression: This command is often used to execute strings as commands, which can be a sign of malicious activity.Output:
DeviceName: The name of the device where the process was executed.FileName: The name of the file that was executed.ActionType: The type of action that was performed.ProcessVersionInfoOriginalFileName: The original file name of the process, which can help identify if it was renamed.ProcessCommandLine: The full command line that was executed, providing context on what the process was doing.ProcessRemoteSessionIP: The IP address of any remote session associated with the process, which can indicate remote control or access.Overall, this query helps identify suspicious PowerShell activities that might be attempts to evade detection by renaming the executable and using specific command-line options associated with malicious behavior.

Sergio Albea
Released: June 12, 2025
Tables
Keywords
Operators