From 4d41496e1dff01757efaf6d87d255ed493635f01 Mon Sep 17 00:00:00 2001 From: protections machine <72879786+protectionsmachine@users.noreply.github.com> Date: Fri, 25 Oct 2024 02:05:15 +1100 Subject: [PATCH] Sync RTA Linux Powershell Egress Network Connection (#4202) Co-authored-by: shashank-elastic <91139415+shashank-elastic@users.noreply.github.com> --- ..._powershell_outbound_network_connection.py | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 rta/linux_execution_linux_powershell_outbound_network_connection.py diff --git a/rta/linux_execution_linux_powershell_outbound_network_connection.py b/rta/linux_execution_linux_powershell_outbound_network_connection.py new file mode 100644 index 000000000..9a1a1d4e6 --- /dev/null +++ b/rta/linux_execution_linux_powershell_outbound_network_connection.py @@ -0,0 +1,59 @@ +# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +# 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. + +import sys +import subprocess +import time + +from . import RtaMetadata, common + +metadata = RtaMetadata( + uuid="65978ab7-37d2-4542-8e03-50b3d408ff42", + platforms=["linux"], + endpoint=[ + { + "rule_name": "Linux Powershell Egress Network Connection", + "rule_id": "1471cf36-7e5c-47cc-bf39-2234df0e676a", + }, + ], + techniques=["T1203"], +) + + +@common.requires_os(*metadata.platforms) +def main() -> None: + parent_process_path = "/tmp/pwsh" + child_script_path = "/tmp/sh" + network_command = "exec 3<>/dev/tcp/8.8.8.8/53" + + # Create the fake parent process script + with open(parent_process_path, "w") as parent_script: + parent_script.write("#!/bin/bash\n") + parent_script.write(f"{child_script_path}\n") + + # Create the child script that will make the network connection + with open(child_script_path, "w") as child_script: + child_script.write("#!/bin/bash\n") + child_script.write(f"{network_command}\n") + + # Make the scripts executable + common.execute(['chmod', '+x', parent_process_path]) + common.execute(['chmod', '+x', child_script_path]) + + # Execute the parent process script + common.log("Executing the fake parent process script") + subprocess.Popen([parent_process_path]) + + # Allow some time for the network connection to be attempted + time.sleep(5) + common.log("RTA execution completed.") + + # Cleanup + common.remove_file(parent_process_path) + common.remove_file(child_script_path) + + +if __name__ == "__main__": + sys.exit(main())