Potential Suspicious File Edit

This rule monitors for the potential edit of a suspicious file. In Linux, when editing a file through an editor, a temporary .swp file is created. By monitoring for the creation of this .swp file, we can detect potential file edits of suspicious files. The execution of this rule is not a clear sign of the file being edited, as just opening the file through an editor will trigger this event. Attackers may alter any of the files added in this rule to establish persistence, escalate privileges or perform reconnaisance on the system.

Elastic rule (View on GitHub)

  1[metadata]
  2creation_date = "2023/07/25"
  3integration = ["endpoint"]
  4maturity = "production"
  5updated_date = "2024/05/21"
  6
  7[rule]
  8author = ["Elastic"]
  9description = """
 10This rule monitors for the potential edit of a suspicious file. In Linux, when editing a file through an editor, a
 11temporary .swp file is created. By monitoring for the creation of this .swp file, we can detect potential file edits of
 12suspicious files. The execution of this rule is not a clear sign of the file being edited, as just opening the file
 13through an editor will trigger this event. Attackers may alter any of the files added in this rule to establish
 14persistence, escalate privileges or perform reconnaisance on the system.
 15"""
 16from = "now-9m"
 17index = ["logs-endpoint.events.*", "endgame-*"]
 18language = "eql"
 19license = "Elastic License v2"
 20max_signals = 1
 21name = "Potential Suspicious File Edit"
 22risk_score = 21
 23rule_id = "3728c08d-9b70-456b-b6b8-007c7d246128"
 24severity = "low"
 25tags = [
 26    "Domain: Endpoint",
 27    "OS: Linux",
 28    "Use Case: Threat Detection",
 29    "Tactic: Persistence",
 30    "Tactic: Privilege Escalation",
 31    "Data Source: Elastic Endgame",
 32    "Data Source: Elastic Defend",
 33]
 34timestamp_override = "event.ingested"
 35type = "eql"
 36
 37query = '''
 38file where host.os.type == "linux" and event.action in ("creation", "file_create_event") and file.extension == "swp" and
 39file.path : (
 40  /* common interesting files and locations */
 41  "/etc/.shadow.swp", "/etc/.shadow-.swp", "/etc/.shadow~.swp", "/etc/.gshadow.swp", "/etc/.gshadow-.swp",
 42  "/etc/.passwd.swp", "/etc/.pwd.db.swp", "/etc/.master.passwd.swp", "/etc/.spwd.db.swp", "/etc/security/.opasswd.swp",
 43  "/etc/.environment.swp", "/etc/.profile.swp", "/etc/sudoers.d/.*.swp", "/etc/ld.so.conf.d/.*.swp",
 44  "/etc/init.d/.*.swp", "/etc/.rc.local.swp", "/etc/rc*.d/.*.swp", "/dev/shm/.*.swp", "/etc/update-motd.d/.*.swp",
 45  "/usr/lib/update-notifier/.*.swp",
 46
 47  /* service, timer, want, socket and lock files */
 48  "/etc/systemd/system/.*.swp", "/usr/local/lib/systemd/system/.*.swp", "/lib/systemd/system/.*.swp",
 49  "/usr/lib/systemd/system/.*.swp","/home/*/.config/systemd/user/.*.swp", "/run/.*.swp", "/var/run/.*.swp/",
 50
 51  /* profile and shell configuration files */  
 52  "/home/*.profile.swp", "/home/*.bash_profile.swp", "/home/*.bash_login.swp", "/home/*.bashrc.swp", "/home/*.bash_logout.swp",
 53  "/home/*.zshrc.swp", "/home/*.zlogin.swp", "/home/*.tcshrc.swp", "/home/*.kshrc.swp", "/home/*.config.fish.swp",
 54  "/root/*.profile.swp", "/root/*.bash_profile.swp", "/root/*.bash_login.swp", "/root/*.bashrc.swp", "/root/*.bash_logout.swp",
 55  "/root/*.zshrc.swp", "/root/*.zlogin.swp", "/root/*.tcshrc.swp", "/root/*.kshrc.swp", "/root/*.config.fish.swp"
 56)
 57'''
 58
 59
 60[[rule.threat]]
 61framework = "MITRE ATT&CK"
 62[[rule.threat.technique]]
 63id = "T1037"
 64name = "Boot or Logon Initialization Scripts"
 65reference = "https://attack.mitre.org/techniques/T1037/"
 66[[rule.threat.technique.subtechnique]]
 67id = "T1037.004"
 68name = "RC Scripts"
 69reference = "https://attack.mitre.org/techniques/T1037/004/"
 70
 71
 72[[rule.threat.technique]]
 73id = "T1543"
 74name = "Create or Modify System Process"
 75reference = "https://attack.mitre.org/techniques/T1543/"
 76[[rule.threat.technique.subtechnique]]
 77id = "T1543.002"
 78name = "Systemd Service"
 79reference = "https://attack.mitre.org/techniques/T1543/002/"
 80
 81
 82[[rule.threat.technique]]
 83id = "T1574"
 84name = "Hijack Execution Flow"
 85reference = "https://attack.mitre.org/techniques/T1574/"
 86[[rule.threat.technique.subtechnique]]
 87id = "T1574.006"
 88name = "Dynamic Linker Hijacking"
 89reference = "https://attack.mitre.org/techniques/T1574/006/"
 90
 91
 92
 93[rule.threat.tactic]
 94id = "TA0003"
 95name = "Persistence"
 96reference = "https://attack.mitre.org/tactics/TA0003/"
 97[[rule.threat]]
 98framework = "MITRE ATT&CK"
 99[[rule.threat.technique]]
100id = "T1548"
101name = "Abuse Elevation Control Mechanism"
102reference = "https://attack.mitre.org/techniques/T1548/"
103[[rule.threat.technique.subtechnique]]
104id = "T1548.003"
105name = "Sudo and Sudo Caching"
106reference = "https://attack.mitre.org/techniques/T1548/003/"
107
108
109
110[rule.threat.tactic]
111id = "TA0004"
112name = "Privilege Escalation"
113reference = "https://attack.mitre.org/tactics/TA0004/"

Related rules

to-top