Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Rule Tuning] Potential Shell via Web Server #2585

Merged
merged 29 commits into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
28bda94
tuned web shell logic, and converted to EQL
Aegrah Feb 21, 2023
e994b62
Removed old, created new rule to bypass "type" bug
Aegrah Feb 22, 2023
851931c
Merge branch 'main' into rule-tuning-web-shells
Aegrah Feb 22, 2023
4169e0a
Revert "Removed old, created new rule to bypass "type" bug"
Aegrah Mar 4, 2023
94b28a8
Revert "tuned web shell logic, and converted to EQL"
Aegrah Mar 4, 2023
cefe391
Deprecated old rule, added new
Aegrah Mar 4, 2023
65647ac
formatting fix
Aegrah Mar 4, 2023
22809da
Merge branch 'main' into rule-tuning-web-shells
Aegrah Mar 4, 2023
5fea265
removed endgame index
Aegrah Mar 4, 2023
34691a3
Merge branch 'rule-tuning-web-shells' of https://github.com/elastic/d…
Aegrah Mar 4, 2023
b7befb0
Fixed changes captured as edited, not created
Aegrah Mar 4, 2023
25acafd
Update rules/linux/persistence_shell_activity_through_web_server.toml
Aegrah Mar 6, 2023
cda28f5
fix conflict
Aegrah Mar 8, 2023
9dbb1a5
added host.os.type==linux for unit testing
Aegrah Mar 8, 2023
7b382e4
removed wildcards in process.args
Aegrah Mar 10, 2023
56d1c8e
Update rules/linux/persistence_shell_activity_via_web_server.toml
Aegrah Mar 20, 2023
7f98a95
fixed conflict by changing file name and changes
Aegrah Mar 20, 2023
988ce42
Trying to resolve the GH conflict
Aegrah Mar 20, 2023
7e5f038
attempt to fix GH conflict #2
Aegrah Mar 20, 2023
1e97c8c
attempt to fix GH conflict nr 3
Aegrah Mar 20, 2023
93e5d7d
Update persistence_shell_activity_by_web_server.toml
Aegrah Mar 20, 2023
27f91cf
Added endgame support
Aegrah Mar 21, 2023
f03c5b7
Merge branch 'main' into rule-tuning-web-shells
Aegrah Mar 21, 2023
32d446d
Added OSQuery to investigation guide
Aegrah Mar 22, 2023
226eaa6
Merge branch 'main' into rule-tuning-web-shells
Aegrah Apr 2, 2023
a73af53
Update rules/linux/persistence_linux_shell_activity_via_web_server.toml
Aegrah Apr 19, 2023
8a04ab7
Update rules/linux/persistence_linux_shell_activity_via_web_server.toml
Aegrah Apr 19, 2023
0d5fe17
removed investigation guide to add in future PR
Aegrah May 3, 2023
1560ef4
Merge branch 'main' into rule-tuning-web-shells
Aegrah May 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
[metadata]
creation_date = "2020/02/18"
deprecation_date = "2023/03/04"
integration = ["endpoint"]
maturity = "production"
maturity = "deprecated"
min_stack_comments = "New fields added: required_fields, related_integrations, setup"
min_stack_version = "8.3.0"
updated_date = "2022/12/20"
updated_date = "2023/03/04"

[rule]
author = ["Elastic"]
Expand Down
111 changes: 111 additions & 0 deletions rules/linux/persistence_shell_activity_via_web_server.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
[metadata]
creation_date = "2023/03/04"
integration = ["endpoint"]
maturity = "production"
min_stack_comments = "New fields added: required_fields, related_integrations, setup"
min_stack_version = "8.3.0"
updated_date = "2023/03/04"

[rule]
author = ["Elastic"]
description = "Identifies suspicious commands executed via a web server, which may suggest a vulnerability and remote shell access."
false_positives = [
"""
Network monitoring or management products may have a web server component that runs shell commands as part of normal
behavior.
""",
]
from = "now-9m"
index = ["auditbeat-*", "logs-endpoint.events.*"]
Aegrah marked this conversation as resolved.
Show resolved Hide resolved
language = "eql"
license = "Elastic License v2"
name = "Potential Remote Code Execution via Web Server"
note = """## Triage and analysis

### Investigating Potential Remote Code Execution via Web Server

Adversaries may backdoor web servers with web shells to establish persistent access to systems. A web shell is a web script that is placed on an openly accessible web server to allow an adversary to use the web server as a gateway into a network. A web shell may provide a set of functions to execute or a command line interface on the system that hosts the web server.

This rule detects a web server process spawning script and command line interface programs, potentially indicating attackers executing commands using the web shell.

#### Possible investigation steps

- Investigate abnormal behaviors observed by the subject process such as network connections, file modifications, and
any other spawned child processes.
- Examine the command line to determine which commands or scripts were executed.
- Investigate other alerts associated with the user/host during the past 48 hours.
- If scripts or executables were dropped, retrieve the files and determine if they are malicious:
- Use a private sandboxed malware analysis system to perform analysis.
- Observe and collect information about the following activities:
- Attempts to contact external domains and addresses.
- Check if the domain is newly registered or unexpected.
- Check the reputation of the domain or IP address.
- File access, modification, and creation activities.
- Cron jobs, services and other persistence mechanisms.

### False positive analysis

- This activity is unlikely to happen legitimately. Any activity that triggered the alert and is not inherently malicious must be monitored by the security team.

### Response and remediation

- Initiate the incident response process based on the outcome of the triage.
- Isolate the involved host to prevent further post-compromise behavior.
- If the triage identified malware, search the environment for additional compromised hosts.
- Implement temporary network rules, procedures, and segmentation to contain the malware.
- Stop suspicious processes.
- Immediately block the identified indicators of compromise (IoCs).
- Inspect the affected systems for additional malware backdoors like reverse shells, reverse proxies, or droppers that attackers could use to reinfect the system.
- Remove and block malicious artifacts identified during triage.
- Investigate credential exposure on systems compromised or used by the attacker to ensure all compromised accounts are identified. Reset passwords for these accounts and other potentially compromised credentials, such as email, business systems, and web services.
- Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and malware components.
- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
- Using the incident response data, update logging and audit policies to improve the mean time to detect (MTTD) and the mean time to respond (MTTR).
"""
references = [
"https://pentestlab.blog/tag/web-shell/",
"https://www.elastic.co/security-labs/elastic-response-to-the-the-spring4shell-vulnerability-cve-2022-22965",
]
risk_score = 47
rule_id = "c895e1f6-376c-466c-b86a-9846da002919"
severity = "medium"
tags = ["Elastic", "Host", "Linux", "Threat Detection", "Persistence", "Investigation Guide", "Elastic Endgame"]
timestamp_override = "event.ingested"
type = "eql"

query = '''
process where event.type == "start" and host.os.type == "linux" and
Aegrah marked this conversation as resolved.
Show resolved Hide resolved
process.parent.executable : (
"/usr/sbin/nginx", "/usr/local/sbin/nginx",
"/usr/sbin/apache", "/usr/local/sbin/apache",
"/usr/sbin/apache2", "/usr/local/sbin/apache2",
"/usr/sbin/php*", "/usr/local/sbin/php*",
"/usr/sbin/lighttpd", "/usr/local/sbin/lighttpd",
"/usr/sbin/hiawatha", "/usr/local/sbin/hiawatha",
"/usr/local/bin/caddy",
"/usr/local/lsws/bin/lswsctrl",
"*/bin/catalina.sh"
) and
process.name : ("*sh", "python*", "perl", "php*", "tmux") and
process.args : ("whoami", "id", "uname", "cat", "hostname", "ip", "curl", "wget", "pwd")
'''


[[rule.threat]]
framework = "MITRE ATT&CK"
[[rule.threat.technique]]
id = "T1505"
name = "Server Software Component"
reference = "https://attack.mitre.org/techniques/T1505/"
[[rule.threat.technique.subtechnique]]
id = "T1505.003"
name = "Web Shell"
reference = "https://attack.mitre.org/techniques/T1505/003/"



[rule.threat.tactic]
id = "TA0003"
name = "Persistence"
reference = "https://attack.mitre.org/tactics/TA0003/"