Creation of Hidden Files and Directories via CommandLine

Users can mark specific files as hidden simply by putting a "." as the first character in the file or folder name. Adversaries can use this to their advantage to hide files and folders on the system for persistence and defense evasion. This rule looks for hidden files or folders in common writable directories.

Elastic rule (View on GitHub)

  1[metadata]
  2creation_date = "2020/04/29"
  3integration = ["endpoint"]
  4maturity = "production"
  5updated_date = "2025/01/15"
  6
  7[rule]
  8author = ["Elastic"]
  9description = """
 10Users can mark specific files as hidden simply by putting a "." as the first character in the file or folder name.
 11Adversaries can use this to their advantage to hide files and folders on the system for persistence and defense evasion.
 12This rule looks for hidden files or folders in common writable directories.
 13"""
 14false_positives = [
 15    """
 16    Certain tools may create hidden temporary files or directories upon installation or as part of their normal
 17    behavior. These events can be filtered by the process arguments, username, or process name values.
 18    """,
 19]
 20from = "now-9m"
 21index = ["logs-endpoint.events.*"]
 22language = "eql"
 23license = "Elastic License v2"
 24max_signals = 33
 25name = "Creation of Hidden Files and Directories via CommandLine"
 26risk_score = 47
 27rule_id = "b9666521-4742-49ce-9ddc-b8e84c35acae"
 28setup = """## Setup
 29
 30This rule requires data coming in from one of the following integrations:
 31- Elastic Defend
 32- Auditbeat
 33
 34### Elastic Defend Integration Setup
 35Elastic Defend is integrated into the Elastic Agent using Fleet. Upon configuration, the integration allows the Elastic Agent to monitor events on your host and send data to the Elastic Security app.
 36
 37#### Prerequisite Requirements:
 38- Fleet is required for Elastic Defend.
 39- To configure Fleet Server refer to the [documentation](https://www.elastic.co/guide/en/fleet/current/fleet-server.html).
 40
 41#### The following steps should be executed in order to add the Elastic Defend integration on a Linux System:
 42- Go to the Kibana home page and click "Add integrations".
 43- In the query bar, search for "Elastic Defend" and select the integration to see more details about it.
 44- Click "Add Elastic Defend".
 45- Configure the integration name and optionally add a description.
 46- Select the type of environment you want to protect, either "Traditional Endpoints" or "Cloud Workloads".
 47- Select a configuration preset. Each preset comes with different default settings for Elastic Agent, you can further customize these later by configuring the Elastic Defend integration policy. [Helper guide](https://www.elastic.co/guide/en/security/current/configure-endpoint-integration-policy.html).
 48- We suggest selecting "Complete EDR (Endpoint Detection and Response)" as a configuration setting, that provides "All events; all preventions"
 49- Enter a name for the agent policy in "New agent policy name". If other agent policies already exist, you can click the "Existing hosts" tab and select an existing policy instead.
 50For more details on Elastic Agent configuration settings, refer to the [helper guide](https://www.elastic.co/guide/en/fleet/8.10/agent-policy.html).
 51- Click "Save and Continue".
 52- To complete the integration, select "Add Elastic Agent to your hosts" and continue to the next section to install the Elastic Agent on your hosts.
 53For more details on Elastic Defend refer to the [helper guide](https://www.elastic.co/guide/en/security/current/install-endpoint.html).
 54
 55### Auditbeat Setup
 56Auditbeat is a lightweight shipper that you can install on your servers to audit the activities of users and processes on your systems. For example, you can use Auditbeat to collect and centralize audit events from the Linux Audit Framework. You can also use Auditbeat to detect changes to critical files, like binaries and configuration files, and identify potential security policy violations.
 57
 58#### The following steps should be executed in order to add the Auditbeat on a Linux System:
 59- Elastic provides repositories available for APT and YUM-based distributions. Note that we provide binary packages, but no source packages.
 60- To install the APT and YUM repositories follow the setup instructions in this [helper guide](https://www.elastic.co/guide/en/beats/auditbeat/current/setup-repositories.html).
 61- To run Auditbeat on Docker follow the setup instructions in the [helper guide](https://www.elastic.co/guide/en/beats/auditbeat/current/running-on-docker.html).
 62- To run Auditbeat on Kubernetes follow the setup instructions in the [helper guide](https://www.elastic.co/guide/en/beats/auditbeat/current/running-on-kubernetes.html).
 63- For complete “Setup and Run Auditbeat” information refer to the [helper guide](https://www.elastic.co/guide/en/beats/auditbeat/current/setting-up-and-running.html).
 64
 65#### Custom Ingest Pipeline
 66For versions <8.2, you need to add a custom ingest pipeline to populate `event.ingested` with @timestamp for non-elastic-agent indexes, like auditbeats/filebeat/winlogbeat etc. For more details to add a custom ingest pipeline refer to the [guide](https://www.elastic.co/guide/en/fleet/current/data-streams-pipeline-tutorial.html).
 67"""
 68severity = "medium"
 69tags = [
 70    "Domain: Endpoint",
 71    "OS: Linux",
 72    "Use Case: Threat Detection",
 73    "Tactic: Defense Evasion",
 74    "Data Source: Elastic Defend",
 75    "Resources: Investigation Guide",
 76]
 77timestamp_override = "event.ingested"
 78type = "eql"
 79query = '''
 80process where host.os.type == "linux" and event.type == "start" and event.action == "exec" and
 81process.working_directory in ("/tmp", "/var/tmp", "/dev/shm") and
 82process.args regex~ """\.[a-z0-9_\-][a-z0-9_\-\.]{1,254}""" and
 83not process.name in (
 84  "ls", "find", "grep", "git", "jq", "basename", "check_snmp", "snmpget", "snmpwalk", "cc1plus", "snap",
 85  "command-not-found"
 86)
 87'''
 88note = """## Triage and analysis
 89
 90> **Disclaimer**:
 91> This investigation guide was created using generative AI technology and has been reviewed to improve its accuracy and relevance. While every effort has been made to ensure its quality, we recommend validating the content and adapting it to suit your specific environment and operational needs.
 92
 93### Investigating Creation of Hidden Files and Directories via CommandLine
 94
 95In Linux environments, files and directories prefixed with a dot (.) are hidden by default, a feature often exploited by adversaries to conceal malicious activities. Attackers may create hidden files in writable directories like /tmp to evade detection. The detection rule identifies suspicious processes creating such hidden files, excluding benign commands, to flag potential threats. This helps in uncovering stealthy persistence and defense evasion tactics.
 96
 97### Possible investigation steps
 98
 99- Review the process details to identify the command executed, focusing on the process.working_directory field to confirm if the hidden file was created in a common writable directory like /tmp, /var/tmp, or /dev/shm.
100- Examine the process.args field to determine the specific hidden file or directory name created, and assess if it matches known malicious patterns or naming conventions.
101- Check the process lineage by investigating the parent process to understand the context of how the hidden file creation was initiated and identify any potential malicious parent processes.
102- Investigate the user account associated with the process to determine if it is a legitimate user or potentially compromised, and review recent activities by this user for any anomalies.
103- Search for any additional hidden files or directories created around the same time or by the same process to identify further suspicious activities or artifacts.
104- Correlate this event with other security alerts or logs from the same host to identify any related suspicious activities or patterns that could indicate a broader attack or compromise.
105
106### False positive analysis
107
108- System maintenance scripts may create hidden files in directories like /tmp for temporary storage. Review these scripts and consider excluding them if they are verified as non-threatening.
109- Development tools and processes, such as version control systems or build scripts, might generate hidden files for configuration or state tracking. Identify these tools and add them to the exclusion list if they are part of regular operations.
110- Monitoring and logging tools may use hidden files to store temporary data or logs. Verify these tools and exclude them if they are essential for system monitoring.
111- User-specific applications or scripts might create hidden files for legitimate purposes. Conduct a review of user activities and exclude known benign applications to reduce noise.
112- Automated backup or synchronization services could generate hidden files as part of their operation. Confirm these services and exclude them if they are part of the expected environment setup.
113
114### Response and remediation
115
116- Immediately isolate the affected system from the network to prevent further malicious activity or lateral movement.
117- Terminate any suspicious processes identified by the detection rule that are creating hidden files in the specified directories.
118- Remove any hidden files or directories created by unauthorized processes in the /tmp, /var/tmp, and /dev/shm directories to eliminate potential persistence mechanisms.
119- Conduct a thorough review of system logs and process execution history to identify any additional indicators of compromise or related malicious activities.
120- Restore any affected files or system components from a known good backup to ensure system integrity.
121- Escalate the incident to the security operations team for further analysis and to determine if additional systems are affected.
122- Implement enhanced monitoring and alerting for similar activities to improve detection and response capabilities for future incidents."""
123
124[[rule.threat]]
125framework = "MITRE ATT&CK"
126
127[[rule.threat.technique]]
128id = "T1564"
129name = "Hide Artifacts"
130reference = "https://attack.mitre.org/techniques/T1564/"
131
132[[rule.threat.technique.subtechnique]]
133id = "T1564.001"
134name = "Hidden Files and Directories"
135reference = "https://attack.mitre.org/techniques/T1564/001/"
136
137[rule.threat.tactic]
138id = "TA0005"
139name = "Defense Evasion"
140reference = "https://attack.mitre.org/tactics/TA0005/"
141
142[[rule.threat]]
143framework = "MITRE ATT&CK"
144
145[rule.threat.tactic]
146id = "TA0003"
147name = "Persistence"
148reference = "https://attack.mitre.org/tactics/TA0003/"

Triage and analysis

Disclaimer: This investigation guide was created using generative AI technology and has been reviewed to improve its accuracy and relevance. While every effort has been made to ensure its quality, we recommend validating the content and adapting it to suit your specific environment and operational needs.

Investigating Creation of Hidden Files and Directories via CommandLine

In Linux environments, files and directories prefixed with a dot (.) are hidden by default, a feature often exploited by adversaries to conceal malicious activities. Attackers may create hidden files in writable directories like /tmp to evade detection. The detection rule identifies suspicious processes creating such hidden files, excluding benign commands, to flag potential threats. This helps in uncovering stealthy persistence and defense evasion tactics.

Possible investigation steps

  • Review the process details to identify the command executed, focusing on the process.working_directory field to confirm if the hidden file was created in a common writable directory like /tmp, /var/tmp, or /dev/shm.
  • Examine the process.args field to determine the specific hidden file or directory name created, and assess if it matches known malicious patterns or naming conventions.
  • Check the process lineage by investigating the parent process to understand the context of how the hidden file creation was initiated and identify any potential malicious parent processes.
  • Investigate the user account associated with the process to determine if it is a legitimate user or potentially compromised, and review recent activities by this user for any anomalies.
  • Search for any additional hidden files or directories created around the same time or by the same process to identify further suspicious activities or artifacts.
  • Correlate this event with other security alerts or logs from the same host to identify any related suspicious activities or patterns that could indicate a broader attack or compromise.

False positive analysis

  • System maintenance scripts may create hidden files in directories like /tmp for temporary storage. Review these scripts and consider excluding them if they are verified as non-threatening.
  • Development tools and processes, such as version control systems or build scripts, might generate hidden files for configuration or state tracking. Identify these tools and add them to the exclusion list if they are part of regular operations.
  • Monitoring and logging tools may use hidden files to store temporary data or logs. Verify these tools and exclude them if they are essential for system monitoring.
  • User-specific applications or scripts might create hidden files for legitimate purposes. Conduct a review of user activities and exclude known benign applications to reduce noise.
  • Automated backup or synchronization services could generate hidden files as part of their operation. Confirm these services and exclude them if they are part of the expected environment setup.

Response and remediation

  • Immediately isolate the affected system from the network to prevent further malicious activity or lateral movement.
  • Terminate any suspicious processes identified by the detection rule that are creating hidden files in the specified directories.
  • Remove any hidden files or directories created by unauthorized processes in the /tmp, /var/tmp, and /dev/shm directories to eliminate potential persistence mechanisms.
  • Conduct a thorough review of system logs and process execution history to identify any additional indicators of compromise or related malicious activities.
  • Restore any affected files or system components from a known good backup to ensure system integrity.
  • Escalate the incident to the security operations team for further analysis and to determine if additional systems are affected.
  • Implement enhanced monitoring and alerting for similar activities to improve detection and response capabilities for future incidents.

Related rules

to-top