Impacket -> atexec.py

Original research credit: u0041

In this report we will learn about the “atexec” tool of Impacket, about what artifacts it generates, and what detection rules can be created based on those artifacts. As always, I recommend reading the entire original research at the top of the page.

TL;DR Summary

  • atexec.py can be used to create and run an immediate scheduled task on a remote target via SMB in order to execute commands on a target system. It works only on version of Windows higher than Vista.
  • Running “atexec.py” creates a task, runs it, and then deletes it immediately. The task name follows the regex pattern: \\[a-zA-Z]{8}
  • We also get a good command execution pattern for “Process created” events on Windows which we can utilize for rule creation.

Windows Event Logs Artifacts

Event IDChannelDetails
106Microsoft-Windows-TaskScheduler/OperationalNew Task Creation. in this log you will find the task name and the username used to create the task.
110Microsoft-Windows-TaskScheduler/OperationalTask triggered by user. After the task creation the task will be trigger manually.
141Microsoft-Windows-TaskScheduler/OperationalTask Deleted.
4624SecurityLogon type 3 and NTLM protocol used – 2 logins one for the task creation and the second is for retrieving the results.
4634SecurityLogoff with the same login ID as the login event above. The time between the first login and it’s logoff indicates the time taken to run the command.
4698SecurityNew Task Creation. in this log you will find the task name and the username used to create the task.
4699SecurityTask Deleted.
1015Microsoft-Windows-SMBServer/SecurityContains the attacking IP

Detection Rules

Rule NameDescriptionDetection Logic
ATExec Task Creation/Deletion within a short periodDetects ATExec task creation and deletion within a short timeframe, which is a confirmed artifact of ATExec.“Task Created”:   
IF “Task Name” MATCH “\\[a-zA-Z]{8}”
AND
“Task Deleted”:    
IF “Task Name” MATCH “\\[a-zA-Z]{8}”
WITHIN 1 MINUTE WITH SAME TASK NAME
ATExec Detected Output RedirectionThis detection analytic identifies Impacket’s atexec.py script on a target host. atexec.py is remotely run on an adversary’s machine to execute commands on the victim via scheduled task. The command is commonly executed by a non-interactive cmd.exe with the output redirected to an eight-character TMP file.“Task Created”:    
IF “Command” INCLUDES ALL OF:        
(“cmd” && “/c” && “temp” && “>” && “2>&1”)