Files
sigma-rules/rta/disable_windows_fw.py
T

49 lines
1.5 KiB
Python
Raw Normal View History

2020-06-29 23:07:16 -06:00
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
2021-03-03 22:12:11 -09:00
# or more contributor license agreements. Licensed under the Elastic License
# 2.0; you may not use this file except in compliance with the Elastic License
# 2.0.
2020-06-29 23:07:16 -06:00
# Name: Disable Windows Firewall
# RTA: disable_windows_fw.py
# ATT&CK: T1089
# signal.rule.name: Disable Windows Firewall Rules via Netsh
2020-06-29 23:07:16 -06:00
# Description: Uses netsh.exe to backup, disable and restore firewall rules.
from pathlib import Path
2020-06-29 23:07:16 -06:00
from . import RtaMetadata, common
2020-06-29 23:07:16 -06:00
2022-09-08 12:50:39 -04:00
metadata = RtaMetadata(
uuid="75e14e5a-1188-47ea-9b96-2cf6e9443fc2",
platforms=["windows"],
endpoint=[],
siem=[{"rule_id": "4b438734-3793-4fda-bd42-ceeada0be8f9", "rule_name": "Disable Windows Firewall Rules via Netsh"}],
techniques=["T1562"],
)
2023-10-03 10:47:58 -04:00
@common.requires_os(*metadata.platforms)
2020-06-29 23:07:16 -06:00
def main():
common.log("NetSH Advanced Firewall Configuration", log_type="~")
netsh = "netsh.exe"
rules_file = Path("fw.rules").resolve()
2020-06-29 23:07:16 -06:00
# Check to be sure that fw.rules does not already exist from previously running this script
common.remove_file(rules_file)
common.log("Backing up rules")
common.execute([netsh, "advfirewall", "export", rules_file])
common.log("Disabling the firewall")
common.execute([netsh, "advfirewall", "set", "allprofiles", "state", "off"])
common.log("Undoing the firewall change", log_type="-")
common.execute([netsh, "advfirewall", "import", rules_file])
common.remove_file(rules_file)
if __name__ == "__main__":
exit(main())