Files
sigma-rules/rta/at_command.py
T

76 lines
2.2 KiB
Python
Raw Normal View History

2020-06-29 23:07:16 -06:00
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
2021-03-03 22:12:11 -09:00
# 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.
2020-06-29 23:07:16 -06:00
# Name: AT Command Lateral Movement
# RTA: at_command.py
# ATT&CK: T1053
# Description: Enumerates at tasks on target host, and schedules an at job for one hour in the future. Then checks the
# status of that task, and deletes the task.
import datetime
import re
import sys
from . import common
2022-09-08 12:50:39 -04:00
from . import RtaMetadata
2020-06-29 23:07:16 -06:00
metadata = RtaMetadata(
uuid="961d7a1f-7bad-41d5-a3d9-8e8a2f59a824",
platforms=["windows"],
endpoint=[],
siem=[],
techniques=[]
)
2022-09-08 12:50:39 -04:00
@common.requires_os(metadata.platforms)
2020-06-29 23:07:16 -06:00
def main(target_host=None):
target_host = target_host or common.get_ip()
2022-09-08 12:50:39 -04:00
host_str = "\\\\%s" % target_host
2020-06-29 23:07:16 -06:00
# Current time at \\localhost is 11/16/2017 11:25:50 AM
2022-09-08 12:50:39 -04:00
code, output = common.execute(["net", "time", host_str])
match = re.search(r"Current time at .*? is (\d+)/(\d+)/(\d+) (\d+):(\d+):(\d+) (AM|PM)", output)
2020-06-29 23:07:16 -06:00
groups = match.groups()
m, d, y, hh, mm, ss, period = groups
2022-09-08 12:50:39 -04:00
now = datetime.datetime(
month=int(m),
day=int(d),
year=int(y),
hour=int(hh),
minute=int(mm),
second=int(ss),
)
if period == "PM" and hh != "12":
2020-06-29 23:07:16 -06:00
now += datetime.timedelta(hours=12)
# Add one hour
task_time = now + datetime.timedelta(hours=1)
# Round down minutes
2022-09-08 12:50:39 -04:00
time_string = "%d:%d" % (task_time.hour, task_time.minute)
2020-06-29 23:07:16 -06:00
# Enumerate all remote tasks
2022-09-08 12:50:39 -04:00
common.execute(["at.exe", host_str])
2020-06-29 23:07:16 -06:00
# Create a job 1 hour into the future
2022-09-08 12:50:39 -04:00
code, output = common.execute(["at", host_str, time_string, "cmd /c echo hello world"])
2020-06-29 23:07:16 -06:00
2022-09-08 12:50:39 -04:00
if code == 1 and "deprecated" in output:
2020-06-29 23:07:16 -06:00
common.log("Unable to continue RTA. Not supported in this version of Windows")
return common.UNSUPPORTED_RTA
if code == 0:
2022-09-08 12:50:39 -04:00
job_id = re.search("ID = (\d+)", output).group(1)
2020-06-29 23:07:16 -06:00
# Check status and delete
2022-09-08 12:50:39 -04:00
common.execute(["at.exe", host_str, job_id])
common.execute(["at.exe", host_str, job_id, "/delete"])
2020-06-29 23:07:16 -06:00
if __name__ == "__main__":
exit(main(*sys.argv[1:]))