forked from elastic/detection-rules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
recycle_bin_process.py
54 lines (42 loc) · 1.61 KB
/
recycle_bin_process.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# 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.
# Name: Run Process from the Recycle Bin
# RTA: recycle_bin_process.py
# ATT&CK: T1158
# Description: Executes mock malware from the "C:\Recycler\" and "C:\$RECYCLE.BIN\" subdirectories.
import os
import time
from . import common
RECYCLE_PATHS = ["C:\\$Recycle.Bin", "C:\\Recycler"]
TARGET_APP = common.get_path("bin", "myapp.exe")
@common.requires_os(common.WINDOWS)
@common.dependencies(TARGET_APP, common.CMD_PATH)
def main():
common.log("Execute files from the Recycle Bin")
target_dir = None
for recycle_path in RECYCLE_PATHS:
if os.path.exists(recycle_path):
target_dir = common.find_writeable_directory(recycle_path)
if target_dir:
break
else:
common.log("Could not find a writeable directory in the recycle bin")
exit(1)
commands = [
[TARGET_APP],
[common.CMD_PATH, "/c", "echo hello world"],
]
common.log("Running commands from recycle bin in %s" % target_dir)
for command in commands: # type: list[str]
source_path = command[0]
arguments = command[1:]
target_path = os.path.join(target_dir, "recycled_process.exe")
common.copy_file(source_path, target_path)
arguments.insert(0, target_path)
common.execute(arguments)
time.sleep(0.5)
common.remove_file(target_path)
if __name__ == "__main__":
exit(main())