{"id":25561,"date":"2022-07-09T00:06:00","date_gmt":"2022-07-08T22:06:00","guid":{"rendered":"http:\/\/159.69.82.204\/win\/?p=25561"},"modified":"2022-07-08T22:34:23","modified_gmt":"2022-07-08T20:34:23","slug":"abwehr-windows-aufgabenplanung-als-einfallstor-fr-angriffe","status":"publish","type":"post","link":"https:\/\/borncity.com\/win\/2022\/07\/09\/abwehr-windows-aufgabenplanung-als-einfallstor-fr-angriffe\/","title":{"rendered":"Defense: Windows task scheduling as an attack vector"},"content":{"rendered":"<p><img decoding=\"async\" title=\"Windows\" style=\"float: left; margin: 0px 10px 0px 0px; display: inline\" alt=\"Windows\" src=\"https:\/\/www.borncity.com\/blog\/wp-content\/uploads\/2021\/04\/Windows-klein.jpg\" width=\"200\">[<a href=\"https:\/\/www.borncity.com\/blog\/?p=270321\" target=\"_blank\" rel=\"noopener\">German<\/a>]Attackers use Windows task scheduling as a technique and create tasks (scheduled tasks) there to infiltrate a victim's machine. The Qualys research team has investigated a number of ways attackers can hide such scheduled tasks. This paper describes three new techniques for hiding and deleting scheduled tasks in a Microsoft Windows environment. This is not theoretical work \"in a vacuum,\" as the technique has been used by suspected Chinese attacker (APT) Hafnium. <\/p>\n<p><!--more--><\/p>\n<p>Attackers abuse the task scheduling (task scheduler) in Microsoft Windows environments to enable the initial or repeated execution of malicious code at system startup or at a scheduled time. The MITRE ATT&amp;CK framework even <a href=\"https:\/\/attack.mitre.org\/techniques\/T1053\/\" target=\"_blank\" rel=\"noopener\">cites this<\/a> as one of the most popular techniques used by attackers, as the ability to schedule programs or scripts is a common service in various operating systems.&nbsp; <\/p>\n<h2>Hafnium uses this technique<\/h2>\n<p>Recently, Microsoft security researchers <a href=\"https:\/\/www.microsoft.com\/security\/blog\/2022\/04\/12\/tarrask-malware-uses-scheduled-tasks-for-defense-evasion\/\" target=\"_blank\" rel=\"noopener\">published an article<\/a> describing how hackers from the state-sponsored Chinese group Hafnium hide scheduled tasks by deleting the Security Descriptor (SD) value in the Windows registry path: :<\/p>\n<pre><code>HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Schedule\\TaskCache\\Tree\\TASK_NAME<\/code><\/pre>\n<p>After Microsoft publicly disclosed this attack technique, the Qualys research team wondered if there were other ways to hide scheduled tasks and decided to investigate further. <\/p>\n<h2>Hide scheduled task<\/h2>\n<p>This blog post explains the results. The most important finding of the analysis is that the index value in the Windows registry path <\/p>\n<pre><code>HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Schedule\\TaskCache\\Tree\\TASK_NAME<\/code><\/pre>\n<p>may be misused to hide or delete a scheduled task. Below, we briefly describe the technique that Hafnium and other actors use to hide a scheduled task. We then detail new techniques that can be used to hide a scheduled task in Microsoft environments. <\/p>\n<h3>How attackers hide scheduled tasks <\/h3>\n<p>According to the Microsoft post, when each scheduled task is created, the following two registry subkeys are generated, one in the Tree path and the other in the Tasks path. <\/p>\n<pre><code>HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Schedule\\TaskCache\\Tree\\TASK_NAME \nHKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Schedule\\TaskCache\\Tasks\\{GUID} <\/code><\/pre>\n<p>The first subkey <em>TASK_NAME<\/em> generated in the tree path corresponds to the name of the scheduled task. The values generated in it (i.e. Id, Index and SD) contain metadata for task registration in the system.&nbsp; <\/p>\n<p>The second subkey {GUID} generated in the Tasks path corresponds to the Id value in the <em>Tree<\/em> subkey. The values created in it (i.e. actions, path, triggers, etc.) contain the basic parameters required to execute the task. <\/p>\n<p>In Hafnium's case, the attackers created a scheduled task called <em>WinUpdate<\/em> to restore broken connections to their Command &amp; Control infrastructure. As a result, subkeys were created in the <em>Tree<\/em> path and the <em>Tasks<\/em> path. The attackers then gained SYSTEM privileges (through token theft) and deleted the <em>SD<\/em> value in the <em>Tree<\/em> subkey.  <\/p>\n<p>Removing the SD value caused the task to \"disappear\" from the task scheduler and from the output of the <em>schtasks \/query<\/em> command, which meant that the scheduled task could no longer be found using any of the traditional identification methods. <\/p>\n<p>The investigation by Qualsys security researchers now revealed that changing or deleting the index value in the tree subkey also causes scheduled tasks to be hidden. The security researchers will explain their findings below, but first a brief description of the investigation conditions.  <\/p>\n<h3>The Qualys research team's investigation setup <\/h3>\n<p>The security researchers conducted their investigations on Windows 10 Pro (v10.0.19043), Windows 10 Enterprise (v10.0.19044) and Windows 2016 Server. On each machine, they first performed the following two steps<\/p>\n<ul>\n<li>Configuring object monitoring in the advanced monitoring settings of the local security policy to display entries for creation (4698), deletion (4699) and update (4702) of scheduled tasks in the Windows security event log.\n<li>Creation of a scheduled task named ImpTask that runs after user logon.<\/li>\n<\/ul>\n<p><i>schtasks \/create \/tn ImpTask \/tr cmd.exe \/sc onlogon \/rl highest <\/i><\/p>\n<p>As soon as the schtasks \/create command is executed, the following three subkeys are created for the newly created <em>ImpTask<\/em> task (see Fig. 1). <\/p>\n<pre><code>HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Schedule\\TaskCache\\Tree\\ImpTask \nHKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Schedule\\TaskCache\\Tasks\\{GUID} \nHKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Schedule\\TaskCache\\Logon\\{GUID}<\/code><\/pre>\n<p>The index value in the <em>ImpTask<\/em> subkey is set to 0x2 (see Fig. 1) because the <em>{GUID}<\/em> subkey for this task is created in the login path (because the task is scheduled to run after user login). <\/p>\n<p><a href=\"https:\/\/i.imgur.com\/h7BAwAF.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i.imgur.com\/h7BAwAF.png\" width=\"620\" height=\"316\"><\/a>&nbsp;<br \/><em>Fig. 1. Three registration keys to the scheduled task ImpTask. . <\/em><\/p>\n<h3>New methods of hiding a scheduled task <\/h3>\n<p>The security researchers found that when a scheduled task is created, another subkey is generated in addition to the Tree and Tasks subkeys. This third subkey is generated depending on when the scheduled task is to be executed:<\/p>\n<ul>\n<li>At startup, specified by the <em>\/sc onstart<\/em> parameter in <em>schtasks \/create<\/em>.\n<li>During user logon, specified by the <em>\/sc onlogon<\/em> parameter in <em>schtasks \/create<\/em>\n<li>At a time other than startup or logon (for example, <em>\/sc daily \/st 09:00<\/em>). <\/li>\n<\/ul>\n<p>The third subkey is created under one of the following paths:  <\/p>\n<pre><code>HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Schedule\\TaskCache\\Boot\\{GUID} \nHKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Schedule\\TaskCache\\Logon\\{GUID} \nHKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Schedule\\TaskCache\\Plain\\{GUID}<\/code><\/pre>\n<p>The name of the third subkey {GUID} matches the Id value in the <em>Tree<\/em> subkey. In addition, we observed that the index value in the Tree subkey is also associated with this third subkey for the scheduled task. As the security researchers noted, the index value is set to either 0x1 or 0x2 or 0x3. Specifically: : <\/p>\n<ul>\n<li>All tasks registered in the path <em>HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Schedule\\TaskCache\\ Boot<\/em> have an index value of 0x1.\n<li>All tasks registered in the path <em>HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Schedule\\TaskCache\\Logon<\/em> have an index value of 0x2.\n<li>All tasks registered in the path <em>HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Schedule\\TaskCache<\/em>\\(Plain or Maintenance) have an index value of 0x3. <\/li>\n<\/ul>\n<p>The Qualys research team wrote a Python script and ran it on several Windows machines to confirm this behavior. Since each scheduled task is part of either Boot or Logon or Plain or Maintenance, there appear to be only three possible values for Index: 0x1, 0x2 or 0x3. <\/p>\n<p>During the research, the security researchers did not find any online documentation describing the purpose of the index value in the context of the scheduled task. However, the researchers managed to manipulate the index value to achieve the following results: mit der geplanten Aufgabe beschreibt. Jedoch gelang es den Forscher, den Indexwert zu manipulieren, um die folgenden Ergebnisse zu erzielen: <\/p>\n<ul>\n<li><b>Hide a specific scheduled task: <\/b>The researchers found that the task is hidden from the task scheduler and the output of the <em>schtasks \/query<\/em> command when the index value in the <em>tree<\/em> subkey is set to 0x0. Nevertheless, the task continues to execute at the scheduled time, even if the system is restarted. This results in behavior that is exactly the same as what the hafnium attackers achieved by deleting the <em>SD<\/em> value. In addition, the researchers found that the task was deleted when they tried to change it after its index value was set to 0x0 with the <em>schtasks \/change<\/em> command. However, no event with ID 4699 for deleting a scheduled task appears in the Windows security event log.\n<li><b>Hide all scheduled tasks: <\/b>Further, we found that clearing the index value causes the task scheduler and<em> schtasks \/query<\/em> to print the error message \"An internal error has occurred,\" effectively hiding all scheduled tasks. However, the existing tasks will continue to run, and new tasks may also be created.&nbsp; <\/li>\n<\/ul>\n<p>If the index is set to a different value (0x4, 0xffff, etc.), the scheduled task will not be hidden, and the task will continue to execute as scheduled. Now let's take a closer look at the two results of manipulating the index value. <\/p>\n<h3>Hiding a scheduled task <\/h3>\n<p>In this first scenario, the security researchers create another scheduled task called <em>ModifyIndexTask<\/em>, which is executed once with SYSTEM privileges-after <em>ImpTask<\/em> is created-and set its index value to 0x0. The command is as follows:<\/p>\n<pre><code>schtasks \/create \/tn ModifyIndexTask \/tr \"reg.exe add&nbsp; \\\"HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Schedule\\TaskCache\\Tree\\ImpTask\\\" \/v Index \/d 0x0 \/t REG_DWORD \/f\" \/ru \"NT AUTHORITY\\SYSTEM\" \/rl highest \/sc once \/st &lt;time later than creation time of ImpTask&gt;<\/code><\/pre>\n<p><a href=\"https:\/\/i.imgur.com\/cgO3tP7.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i.imgur.com\/cgO3tP7.png\" width=\"642\" height=\"190\"><\/a>&nbsp; <br \/><em>Fig. 2. The index value of ImpTask is changed to 0x0.<\/em> <\/p>\n<p>As soon as the <em>ModifyIndexTask<\/em> task is executed, it sets the index value of <em>ImpTask<\/em> to 0 (Fig. 2). As a result, <em>ImpTask<\/em> disappears from both the task scheduler (Fig. 3) and the output of the <em>schtasks \/query<\/em> command (Fig. 4). <\/p>\n<p>However, <em>ImpTask<\/em> continues to run, even after a system reboot (Fig. 5). Although<em> ImpTask<\/em> does not appear in the output of <em>schtasks \/query<\/em>, Fig. 5 shows that it is possible to retrieve the task's status with the <em>schtasks \/query<\/em> command by specifying the task's name with the<em> \/tn<\/em> parameter. <\/p>\n<p><a href=\"https:\/\/i.imgur.com\/aLCW5jN.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i.imgur.com\/aLCW5jN.png\" width=\"636\" height=\"321\"><\/a><br \/><em><\/em><\/p>\n<p><em>Fig. 3. ImpTask disappears from the task scheduler as soon as the index value is changed to 0x0.<\/em><\/p>\n<p>&nbsp;<a href=\"https:\/\/i.imgur.com\/h14zUNV.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i.imgur.com\/h14zUNV.png\" width=\"634\" height=\"250\"><\/a><br \/><em><\/em><\/p>\n<p><em>Fig. 4. ImpTask disappears from the output of schtasks \/query as soon as the index value is changed to 0x0.<\/em>&nbsp;<em> <\/em><\/p>\n<p><a href=\"https:\/\/borncity.com\/win\/wp-content\/uploads\/2022\/07\/clip_image010.jpg\"><em><a href=\"https:\/\/i.imgur.com\/uvd1WWl.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i.imgur.com\/uvd1WWl.png\" width=\"631\" height=\"151\"><\/a><\/em><\/a><br \/><em>Figure 5. ImpTask continues to run even after the index value is set to 0x0. <\/em><\/p>\n<p>The Qualys research team was able to reproduce this issue on every Windows 10 machine experimented with &#8211; testing was done on a total of five machines. <\/p>\n<p>Another interesting observation was the following: When we try to change the program name in <em>ImpTask<\/em> (with index value 0x0) with the <em>schtasks \/change \/tr<\/em> command, the task is deleted, as shown in Fig. 6. This is done without showing event ID 4699 (A scheduled task was deleted) or event ID 4702 (A scheduled task was updated) in the Windows security event log. In contrast, event ID 4699 is displayed when the researcher use the <em>schtasks \/delete<\/em> command to delete <em>ImpTask<\/em>. <\/p>\n<p><a href=\"https:\/\/i.imgur.com\/0PhJjtK.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i.imgur.com\/0PhJjtK.png\" width=\"632\" height=\"233\"><\/a><br \/><em>Figure 6: When ImpTask is deleted with schtasks \/change \/tr, it leaves no trace in the Windows security log. <\/em><\/p>\n<h3>Hide all scheduled tasks <\/h3>\n<p>In this second scenario, security researchers create another scheduled task that runs with SYSTEM privileges and deletes the index value in the <em>ImpTask<\/em> subkey. The command to do this is: <\/p>\n<pre><code>schtasks \/create \/tn ModifyIndexTask \/tr \"reg.exe delete \\\"HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Schedule\\TaskCache\\Tree\\ImpTask\\\" \/v Index \/f\" \/ru \"NT AUTHORITY\\SYSTEM\" \/rl highest \/sc once \/st &lt;time later than creation time of ImpTask&gt;<\/code><\/pre>\n<p>As soon as the index value in the <em>ImpTask<\/em> subkey is deleted (Fig. 7), all scheduled tasks disappear from the task scheduler (Fig. 8) and the output of the <em>schtasks \/query <\/em>command (Fig. 9). Instead, we get the error message \"An internal error has occurred\". Also, specifying the task name <em>ImpTask<\/em> with the <em>\/tn<\/em> parameter does not work. <\/p>\n<p><a href=\"https:\/\/i.imgur.com\/0ANJGD1.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i.imgur.com\/0ANJGD1.png\" width=\"649\" height=\"154\"><\/a><br \/><em>Fig. 7. index value deleted from ImpTask subkey. <\/em><\/p>\n<p><a href=\"https:\/\/i.imgur.com\/lXlYqTi.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i.imgur.com\/lXlYqTi.png\" width=\"645\" height=\"228\"><\/a><br \/><em>Fig. 8. after deleting the index value, all scheduled tasks disappear from the task scheduler and an error message is displayed.&nbsp; <\/em><a href=\"https:\/\/i.imgur.com\/67Nj6oE.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i.imgur.com\/67Nj6oE.png\" width=\"638\" height=\"162\"><\/a><br \/><em>Fig. 9. Specifying the name of the task with the schtasks \/query \/tn command does not work either.&nbsp; <\/em><\/p>\n<p>Although the scheduled tasks are not displayed, they are executed at the scheduled time. Even after rebooting the system, the scheduled tasks cannot be displayed. If <em>ImpTask<\/em> is changed with the <em>schtasks \/change<\/em> command, the index value is generated again, and then the <em>schtasks \/query<\/em> command is then executed successfully (Fig. 10). <\/p>\n<p><a href=\"https:\/\/i.imgur.com\/JLxmC5p.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i.imgur.com\/JLxmC5p.png\" width=\"640\" height=\"426\"><\/a><br \/><em>Fig. 10. Changing ImpTask with the schtasks \/change command causes the index value to be generated again, after which the schtasks \/query command is executed successfully. <\/em> <\/p>\n<p>After deleting the index value, the researchers attempted to delete <em>ImpTask<\/em> with <em>schtasks \/delete<\/em>. Interestingly, this command failed and an error message was issued. When we subsequently tried to change ImpTask with the schtasks \/change command, the index value in the <em>ImpTask<\/em> subkey was restored. All tasks now reappeared in the task scheduler, and running <em>schtasks \/query<\/em> was also successful. Note that the index value is restored only if<em> schtasks \/delete<\/em> is executed before <em>schtasks \/change<\/em>. If we ran <em>schtasks \/change<\/em> without running <em>schtasks \/delete<\/em> first, the index value was not restored, and we still received an error message when running <em>schtasks \/query<\/em>. <\/p>\n<h2>Summary <\/h2>\n<p>An investigation by the Qualys research team found that in addition to the SD value, the index value in the Tree subkey of a scheduled task also plays an important role and both can be abused by attackers. In this blog, we described three new techniques to hide and delete scheduled tasks: <\/p>\n<ul>\n<li>Hide a scheduled task from the task scheduler and the output of the <em>schtasks \/query<\/em> command by setting its index value to 0x0.\n<li>Delete a scheduled task by first setting its index value to 0x0 and then using the <em>schtasks \/change \/tr<\/em> command, which effectively deletes the task without leaving a trace in the Windows security event log.\n<li>Hide all scheduled tasks from the task scheduler and the output of the schtasks \/query command by deleting the index value of any scheduled task. <\/li>\n<\/ul>\n<p>Any of these new techniques can be used to hide a scheduled task in Microsoft environments. Therefore, it is important to monitor changes to the index and SD values of scheduled tasks. Such changes could indicate that an attacker is attempting to execute malicious code-either at system startup or at a scheduled time-to gain persistence.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>[German]Attackers use Windows task scheduling as a technique and create tasks (scheduled tasks) there to infiltrate a victim's machine. The Qualys research team has investigated a number of ways attackers can hide such scheduled tasks. This paper describes three new &hellip; <a href=\"https:\/\/borncity.com\/win\/2022\/07\/09\/abwehr-windows-aufgabenplanung-als-einfallstor-fr-angriffe\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[580,2],"tags":[69,194],"class_list":["post-25561","post","type-post","status-publish","format-standard","hentry","category-security","category-windows","tag-security","tag-windows"],"_links":{"self":[{"href":"https:\/\/borncity.com\/win\/wp-json\/wp\/v2\/posts\/25561","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/borncity.com\/win\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/borncity.com\/win\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/borncity.com\/win\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/borncity.com\/win\/wp-json\/wp\/v2\/comments?post=25561"}],"version-history":[{"count":0,"href":"https:\/\/borncity.com\/win\/wp-json\/wp\/v2\/posts\/25561\/revisions"}],"wp:attachment":[{"href":"https:\/\/borncity.com\/win\/wp-json\/wp\/v2\/media?parent=25561"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/borncity.com\/win\/wp-json\/wp\/v2\/categories?post=25561"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/borncity.com\/win\/wp-json\/wp\/v2\/tags?post=25561"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}