Skip to content

Commit adb6075

Browse files
Sync RTA Linux Powershell Egress Network Connection (#4202)
Co-authored-by: shashank-elastic <[email protected]> (cherry picked from commit 4d41496)
1 parent 52eb22d commit adb6075

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
2+
# or more contributor license agreements. Licensed under the Elastic License
3+
# 2.0; you may not use this file except in compliance with the Elastic License
4+
# 2.0.
5+
6+
import sys
7+
import subprocess
8+
import time
9+
10+
from . import RtaMetadata, common
11+
12+
metadata = RtaMetadata(
13+
uuid="65978ab7-37d2-4542-8e03-50b3d408ff42",
14+
platforms=["linux"],
15+
endpoint=[
16+
{
17+
"rule_name": "Linux Powershell Egress Network Connection",
18+
"rule_id": "1471cf36-7e5c-47cc-bf39-2234df0e676a",
19+
},
20+
],
21+
techniques=["T1203"],
22+
)
23+
24+
25+
@common.requires_os(*metadata.platforms)
26+
def main() -> None:
27+
parent_process_path = "/tmp/pwsh"
28+
child_script_path = "/tmp/sh"
29+
network_command = "exec 3<>/dev/tcp/8.8.8.8/53"
30+
31+
# Create the fake parent process script
32+
with open(parent_process_path, "w") as parent_script:
33+
parent_script.write("#!/bin/bash\n")
34+
parent_script.write(f"{child_script_path}\n")
35+
36+
# Create the child script that will make the network connection
37+
with open(child_script_path, "w") as child_script:
38+
child_script.write("#!/bin/bash\n")
39+
child_script.write(f"{network_command}\n")
40+
41+
# Make the scripts executable
42+
common.execute(['chmod', '+x', parent_process_path])
43+
common.execute(['chmod', '+x', child_script_path])
44+
45+
# Execute the parent process script
46+
common.log("Executing the fake parent process script")
47+
subprocess.Popen([parent_process_path])
48+
49+
# Allow some time for the network connection to be attempted
50+
time.sleep(5)
51+
common.log("RTA execution completed.")
52+
53+
# Cleanup
54+
common.remove_file(parent_process_path)
55+
common.remove_file(child_script_path)
56+
57+
58+
if __name__ == "__main__":
59+
sys.exit(main())

0 commit comments

Comments
 (0)