Linux Firewall Rule Creation or Modification
Description
Adversaries may create or modify Linux firewall rules with DROP, ACCEPT, or REJECT actions to affect how a host receives or sends network traffic. This activity may be used to bypass security controls, block defensive tooling, or gain unauthorized access to the network.
Query · eql
process where host.os.type == "linux" and event.type == "start" and
event.action in ("exec", "exec_event", "start", "ProcessRollup2", "executed", "process_started") and
(
(
process.name in (
"iptables", "ip6tables", "iptables-nft", "ip6tables-nft", "iptables-legacy",
"ip6tables-legacy", "xtables-nft-multi", "xtables-legacy-multi"
) and
process.args in ("-A", "--append", "-I", "--insert", "-R", "--replace", "-P", "--policy") and
process.args like~ ("DROP", "ACCEPT", "REJECT")
) or
(
process.name == "nft" and
process.args in ("add", "insert", "replace") and
process.args == "rule" and
process.args like~ ("DROP", "ACCEPT", "REJECT") and
not process.args in ("-c", "--check")
) or
(
process.name == "ufw" and
process.args like~ ("deny", "allow", "reject") and
not process.args in ("delete", "--dry-run")
)
)
Implementation guide
This rule requires data coming in from Elastic Defend.
Elastic Defend Integration Setup
Elastic 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.
Prerequisite Requirements:
- Fleet is required for Elastic Defend.
- To configure Fleet Server refer to the documentation.
The following steps should be executed in order to add the Elastic Defend integration on a Linux System:
- Go to the Kibana home page and click "Add integrations".
- In the query bar, search for "Elastic Defend" and select the integration to see more details about it.
- Click "Add Elastic Defend".
- Configure the integration name and optionally add a description.
- Select the type of environment you want to protect, either "Traditional Endpoints" or "Cloud Workloads".
- 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.
- We suggest selecting "Complete EDR (Endpoint Detection and Response)" as a configuration setting, that provides "All events; all preventions"
- 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. For more details on Elastic Agent configuration settings, refer to the helper guide.
- Click "Save and Continue".
- 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. For more details on Elastic Defend refer to the helper guide.
Additional data sources
This rule also supports ECS-compatible process events from Elastic Endgame and the following integrations:
Analyst notes
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 Linux Firewall Rule Creation or Modification
This rule detects Linux firewall commands that create or modify DROP, ACCEPT, REJECT, deny, allow, or reject rules, which can weaken network controls, conceal malicious traffic, or open unauthorized access paths. An attacker with elevated privileges may add an ACCEPT rule permitting inbound SSH from a controlled address, then add DROP or REJECT rules that block connections to monitoring or management systems.
Possible investigation steps
- Review the full command line, execution user, privilege level, parent process, working directory, and related shell history to determine who initiated the change and whether it followed an approved administrative workflow.
- Reconstruct the resulting firewall policy and identify affected interfaces, protocols, ports, addresses, directions, and rule ordering to assess whether access was opened or security and management traffic was blocked.
- Compare the change with configuration-management activity, maintenance windows, change tickets, administrator baselines, and similar commands on peer hosts to distinguish expected operations from anomalous behavior.
- Correlate nearby authentication, process, file, and network events for suspicious logins, privilege escalation, remote-access tooling, firewall persistence changes, or connections newly enabled by the rule.
- If unauthorized, preserve the active ruleset and relevant telemetry, restore the approved policy through controlled procedures, isolate the host when necessary, and investigate the initiating account and adjacent systems for compromise.
False positive analysis
- An administrator may add or modify DROP, ACCEPT, REJECT, deny, allow, or reject rules during approved firewall maintenance; verify the command scope, initiating user, execution time, and corresponding change record.
- A startup script or configuration-management process may restore the approved firewall baseline after boot or deployment; confirm the parent process, command recurrence, and resulting ruleset match established host and peer baselines.
Response and remediation
- Isolate affected hosts from untrusted networks while preserving approved incident-response access, and block attacker-controlled addresses and newly exposed services at upstream firewalls.
- Preserve the active ruleset and relevant logs, then remove unauthorized DROP, ACCEPT, REJECT, deny, allow, or reject rules and restore the approved policy through configuration management.
- Remove firewall persistence from systemd units, cron jobs, startup scripts, network hooks, nftables configuration, iptables-persistent files, and UFW configuration.
- Revoke compromised credentials and active sessions, inspect for additional malware or privilege escalation, and reimage from a known-good source if root-level integrity cannot be established.
- Escalate immediately to incident response if the rules were created with root privileges, enabled unauthorized remote access, impaired monitoring, or appear on multiple systems.
- Harden the environment by restricting firewall administration through least privilege, enforcing reviewed ruleset baselines, securing configuration files, and alerting on future policy changes.