Sync RTA Linux Powershell Egress Network Connection (#4202)
Co-authored-by: shashank-elastic <91139415+shashank-elastic@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
933020a5c1
commit
4d41496e1d
@@ -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())
|
||||
Reference in New Issue
Block a user