This code is a malicious PowerShell script that functions as...
September 3, 2025 at 01:13 AM
This code is a malicious PowerShell script that functions as a keylogger. Here's what the script does step by step:
-
Imports User32 DLL Functions:
- The script uses
Add-Type
to define and import API calls from the Windowsuser32.dll
, such as:GetAsyncKeyState
: Captures key presses asynchronously for specified keys.GetKeyboardState
: Retrieves the state of all keys on the physical keyboard.MapVirtualKey
: Maps a virtual-key code to a scan code or character type.ToUnicode
: Converts keystroke data into Unicode characters, essentially interpreting the key pressed.
- The script uses
-
Alters Error Handling:
- It suppresses error messages with
$ErrorActionPreference = SilentlyContinue
.
- It suppresses error messages with
-
Creates a Scheduled Task:
- A scheduled task named
MomMonitor
is created to run with administrator permissions, pointing topowershell.exe
in hidden mode (-w h
). This ensures persistence of the script across reboots.
- A scheduled task named
-
Modifies the User Profile:
- It writes the script's code to the user's PowerShell profile (
profile.ps1
), ensuring that the keylogger executes each time PowerShell is started.
- It writes the script's code to the user's PowerShell profile (
-
Sets Up Logging:
- It defines a log file in the system's temporary folder (
$env:temp\mat-debug-6F936CD.log
) to store captured keystrokes.
- It defines a log file in the system's temporary folder (
-
Initiates Keylogging:
- In a while loop:
- It continuously checks for keystrokes using
GetAsyncKeyState
. - Converts these keystrokes into human-readable characters using the imported APIs (
MapVirtualKey
andToUnicode
). - Appends the captured characters (in Unicode format) to the log file.
- It continuously checks for keystrokes using
- In a while loop:
-
Data Exfiltration:
- Every hour, the script sends the captured log data to a remote malicious server (
http://{COMPUTERNAME}.malicious.12moms21.com
) viaInvoke-RestMethod
. This effectively leaks the captured keystrokes (potential sensitive information) to the attacker.
- Every hour, the script sends the captured log data to a remote malicious server (
-
Avoids Detection:
- The script attempts to stay undetected by suppressing outputs and errors, scheduling itself to run stealthily, writing the log file in a temporary directory, and disguising key sections.
Summary:
This script is designed to:
- Monitor and log keystrokes typed by the user (keylogger functionality).
- Exfiltrate the logged data periodically to an attacker-controlled server.
- Establish persistence by creating a scheduled task and modifying the user's PowerShell profile.
Such a script is often used for unauthorized monitoring, data theft, or other malicious activities. It poses a significant security risk and should be identified and removed immediately.
Generate your own explanations
Download our vscode extension
Read other generated explanations
Built by @thebuilderjr
Sponsored by beam analytics
Read our terms and privacy policy
Forked from openai-quickstart-node