Rule : MySQL General-Log Poisoning via Process-Visible SQL Strings
Persistence My SQL JSP Log Poisoning
Query
DeviceProcessEvents
| where Timestamp > ago(7d)
| where ProcessCommandLine contains "general_log_file" or ProcessCommandLine contains "SET GLOBAL general_log" or (ProcessCommandLine contains "SELECT" and ProcessCommandLine contains "<%")
| project Timestamp, DeviceId, DeviceName, AccountName, FileName, ProcessCommandLine, InitiatingProcessFileName
| order by Timestamp descAbout this query
Explanation
This query is designed to detect potentially malicious activity involving MySQL databases. Specifically, it looks for SQL commands that might be used to redirect MySQL logs to a file or to insert JSP (JavaServer Pages) tags into the database, which could indicate an attempt to create a webshell—a type of malware that allows remote control over a web server.
Here's a simple breakdown of the query:
-
Purpose: The query aims to identify suspicious SQL commands that could be used to compromise a server by altering MySQL logs or inserting harmful code.
-
What it Looks For:
- SQL commands that change where MySQL logs are stored (
general_log_fileorSET GLOBAL general_log). - SQL
SELECTstatements that include JSP tags (<%), which might be used to inject malicious code.
- SQL commands that change where MySQL logs are stored (
-
Data Source: It searches through the
DeviceProcessEventstable, which contains information about processes running on devices. -
Time Frame: The query examines events from the past 7 days.
-
Output: It lists details such as the time of the event, device information, user account, file names, and the command line that was executed, sorted by the most recent events.
-
False Positives: It acknowledges that legitimate database administrators (DBAs) might trigger these alerts during troubleshooting, so these cases should be excluded from alerts.
-
Investigation Steps:
- Check if the log file was redirected to a web-accessible location, which could indicate an attack.
- Look for any resulting
.jspfiles that might have been created as part of the attack.
-
Context: This detection method is based on documented behavior from a threat group known as ARTEX, which uses these techniques to maintain persistence on compromised systems.
Overall, this query helps security teams identify and investigate potential security incidents involving MySQL log manipulation and webshell deployment.