|
| 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 | +# you may not use this file except in compliance with the Elastic License. |
| 4 | + |
| 5 | +# Name: AT Command Lateral Movement |
| 6 | +# RTA: at_command.py |
| 7 | +# ATT&CK: T1053 |
| 8 | +# Description: Enumerates at tasks on target host, and schedules an at job for one hour in the future. Then checks the |
| 9 | +# status of that task, and deletes the task. |
| 10 | + |
| 11 | +import datetime |
| 12 | +import re |
| 13 | +import sys |
| 14 | + |
| 15 | +from . import common |
| 16 | + |
| 17 | + |
| 18 | +@common.requires_os(common.WINDOWS) |
| 19 | +def main(target_host=None): |
| 20 | + target_host = target_host or common.get_ip() |
| 21 | + host_str = '\\\\%s' % target_host |
| 22 | + |
| 23 | + # Current time at \\localhost is 11/16/2017 11:25:50 AM |
| 24 | + code, output = common.execute(['net', 'time', host_str]) |
| 25 | + match = re.search(r'Current time at .*? is (\d+)/(\d+)/(\d+) (\d+):(\d+):(\d+) (AM|PM)', output) |
| 26 | + groups = match.groups() |
| 27 | + m, d, y, hh, mm, ss, period = groups |
| 28 | + now = datetime.datetime(month=int(m), day=int(d), year=int(y), hour=int(hh), minute=int(mm), second=int(ss)) |
| 29 | + if period == 'PM' and hh != '12': |
| 30 | + now += datetime.timedelta(hours=12) |
| 31 | + |
| 32 | + # Add one hour |
| 33 | + task_time = now + datetime.timedelta(hours=1) |
| 34 | + |
| 35 | + # Round down minutes |
| 36 | + time_string = '%d:%d' % (task_time.hour, task_time.minute) |
| 37 | + |
| 38 | + # Enumerate all remote tasks |
| 39 | + common.execute(['at.exe', host_str]) |
| 40 | + |
| 41 | + # Create a job 1 hour into the future |
| 42 | + code, output = common.execute(['at', host_str, time_string, 'cmd /c echo hello world']) |
| 43 | + |
| 44 | + if code == 1 and 'deprecated' in output: |
| 45 | + common.log("Unable to continue RTA. Not supported in this version of Windows") |
| 46 | + return common.UNSUPPORTED_RTA |
| 47 | + |
| 48 | + if code == 0: |
| 49 | + job_id = re.search('ID = (\d+)', output).group(1) |
| 50 | + |
| 51 | + # Check status and delete |
| 52 | + common.execute(['at.exe', host_str, job_id]) |
| 53 | + common.execute(['at.exe', host_str, job_id, '/delete']) |
| 54 | + |
| 55 | + |
| 56 | +if __name__ == "__main__": |
| 57 | + exit(main(*sys.argv[1:])) |
0 commit comments