forked from elastic/detection-rules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpowershell_args.py
43 lines (30 loc) · 1.13 KB
/
powershell_args.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
# 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: Powershell with Suspicious Arguments
# RTA: powershell_args.py
# ATT&CK: T1140
# Description: Calls PowerShell with suspicious command line arguments.
import base64
import os
from . import common
def encode(command):
return base64.b64encode(command.encode('utf-16le'))
@common.requires_os(common.WINDOWS)
def main():
common.log("PowerShell Suspicious Commands")
temp_script = os.path.abspath("tmp.ps1")
# Create an empty script
with open(temp_script, "w") as f:
f.write("whoami.exe\nexit\n")
powershell_commands = [
['powershell.exe', '-ExecutionPol', 'Bypass', temp_script],
['powershell.exe', 'iex', 'Get-Process'],
['powershell.exe', '-ec', encode('Get-Process' + ' ' * 1000)],
]
for command in powershell_commands:
common.execute(command)
common.remove_file(temp_script)
if __name__ == "__main__":
exit(main())