Coverage for /private/tmp/im/impacket/impacket/dcerpc/v5/tsch.py : 84%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# SECUREAUTH LABS. Copyright 2018 SecureAuth Corporation. All rights reserved. # # This software is provided under under a slightly modified version # of the Apache Software License. See the accompanying LICENSE file # for more information. # # Author: Alberto Solino (@agsolino) # # Description: # [MS-TSCH] ITaskSchedulerService Interface implementation # # Best way to learn how to use these calls is to grab the protocol standard # so you understand what the call does, and then read the test case located # at https://github.com/SecureAuthCorp/impacket/tree/master/tests/SMB_RPC # # Some calls have helper functions, which makes it even easier to use. # They are located at the end of this file. # Helper functions start with "h"<name of the call>. # There are test cases for them too. #
elif key & 0xffff in system_errors.ERROR_MESSAGES: error_msg_short = system_errors.ERROR_MESSAGES[key & 0xffff][0] error_msg_verbose = system_errors.ERROR_MESSAGES[key & 0xffff][1] return 'TSCH SessionError: code: 0x%x - %s - %s' % (self.error_code, error_msg_short, error_msg_verbose) else: return 'TSCH SessionError: unknown error code: 0x%x' % self.error_code
################################################################################ # CONSTANTS ################################################################################ # 2.3.1 Constant Values
# 2.3.7 Flags
# 2.3.9 TASK_LOGON_TYPE
# 2.3.13 TASK_STATE
# 2.4.1 FIXDLEN_DATA
# 2.4.2.11 Triggers
# ToDo: Change this to enums
# 2.4.2.11.8 MONTHLYDOW Trigger
# 2.3.12 TASK_NAMES
# 3.2.5.4.2 SchRpcRegisterTask (Opnum 1)
# 3.2.5.4.7 SchRpcEnumFolders (Opnum 6)
# 3.2.5.4.13 SchRpcRun (Opnum 12)
# 3.2.5.4.18 SchRpcGetTaskInfo (Opnum 17)
################################################################################ # STRUCTURES ################################################################################ # 2.3.12 TASK_NAMES
('Data',TASK_NAMES_ARRAY), )
('Data',WSTR_ARRAY), )
('Data',TASK_NAMES_ARRAY), )
# 3.2.5.4.13 SchRpcRun (Opnum 12)
('Data',SYSTEMTIME_ARRAY), )
# 2.3.8 TASK_USER_CRED ('userId',LPWSTR), ('password',LPWSTR), ('flags',DWORD), )
('Data',TASK_USER_CRED_ARRAY), )
# 2.3.10 TASK_XML_ERROR_INFO ('line',DWORD), ('column',DWORD), ('node',LPWSTR), ('value',LPWSTR), )
('Data',TASK_XML_ERROR_INFO), )
# 2.4.1 FIXDLEN_DATA ('Product Version','<H=0'), ('File Version','<H=0'), ('Job uuid','16s="'), ('App Name Len Offset','<H=0'), ('Trigger Offset','<H=0'), ('Error Retry Count','<H=0'), ('Error Retry Interval','<H=0'), ('Idle Deadline','<H=0'), ('Idle Wait','<H=0'), ('Priority','<L=0'), ('Maximum Run Time','<L=0'), ('Exit Code','<L=0'), ('Status','<L=0'), ('Flags','<L=0'), )
# 2.4.2.11 Triggers ('Trigger Size','<H=0'), ('Reserved1','<H=0'), ('Begin Year','<H=0'), ('Begin Month','<H=0'), ('Begin Day','<H=0'), ('End Year','<H=0'), ('End Month','<H=0'), ('End Day','<H=0'), ('Start Hour','<H=0'), ('Start Minute','<H=0'), ('Minutes Duration','<L=0'), ('Minutes Interval','<L=0'), ('Flags','<L=0'), ('Trigger Type','<L=0'), ('TriggerSpecific0','<H=0'), ('TriggerSpecific1','<H=0'), ('TriggerSpecific2','<H=0'), ('Padding','<H=0'), ('Reserved2','<H=0'), ('Reserved3','<H=0'), )
# 2.4.2.11.6 WEEKLY Trigger ('Trigger Type','<L=0'), ('Weeks Interval','<H=0'), ('DaysOfTheWeek','<H=0'), ('Unused','<H=0'), ('Padding','<H=0'), )
# 2.4.2.11.7 MONTHLYDATE Trigger ('Trigger Type','<L=0'), ('Days','<L=0'), ('Months','<H=0'), ('Padding','<H=0'), )
# 2.4.2.11.8 MONTHLYDOW Trigger ('Trigger Type','<L=0'), ('WhichWeek','<H=0'), ('DaysOfTheWeek','<H=0'), ('Months','<H=0'), ('Padding','<H=0'), ('Reserved2','<H=0'), ('Reserved3','<H=0'), )
# 2.4.2.12 Job Signature ('SignatureVersion','<HH0'), ('MinClientVersion','<H=0'), ('Signature','64s="'), )
################################################################################ # RPC CALLS ################################################################################ # 3.2.5.4.1 SchRpcHighestVersion (Opnum 0) )
('pVersion', DWORD), ('ErrorCode',ULONG), )
# 3.2.5.4.2 SchRpcRegisterTask (Opnum 1) ('path', LPWSTR), ('xml', WSTR), ('flags', DWORD), ('sddl', LPWSTR), ('logonType', DWORD), ('cCreds', DWORD), ('pCreds', LPTASK_USER_CRED_ARRAY), )
('pActualPath', LPWSTR), ('pErrorInfo', PTASK_XML_ERROR_INFO), ('ErrorCode',ULONG), )
# 3.2.5.4.3 SchRpcRetrieveTask (Opnum 2) ('path', WSTR), ('lpcwszLanguagesBuffer', WSTR), ('pulNumLanguages', DWORD), )
('pXml', LPWSTR), ('ErrorCode',ULONG), )
# 3.2.5.4.4 SchRpcCreateFolder (Opnum 3) ('path', WSTR), ('sddl', LPWSTR), ('flags', DWORD), )
('ErrorCode',ULONG), )
# 3.2.5.4.7 SchRpcEnumFolders (Opnum 6) ('path', WSTR), ('flags', DWORD), ('startIndex', DWORD), ('cRequested', DWORD), )
('startIndex', DWORD), ('pcNames', DWORD), ('pNames', PTASK_NAMES_ARRAY), ('ErrorCode',ULONG), )
# 3.2.5.4.8 SchRpcEnumTasks (Opnum 7) ('path', WSTR), ('flags', DWORD), ('startIndex', DWORD), ('cRequested', DWORD), )
('startIndex', DWORD), ('pcNames', DWORD), ('pNames', PTASK_NAMES_ARRAY), ('ErrorCode',ULONG), )
# 3.2.5.4.9 SchRpcEnumInstances (Opnum 8) ('path', LPWSTR), ('flags', DWORD), )
('pcGuids', DWORD), ('pGuids', PGUID_ARRAY), ('ErrorCode',ULONG), )
# 3.2.5.4.10 SchRpcGetInstanceInfo (Opnum 9) ('guid', GUID), )
('pPath', LPWSTR), ('pState', DWORD), ('pCurrentAction', LPWSTR), ('pInfo', LPWSTR), ('pcGroupInstances', DWORD), ('pGroupInstances', PGUID_ARRAY), ('pEnginePID', DWORD), ('ErrorCode',ULONG), )
# 3.2.5.4.11 SchRpcStopInstance (Opnum 10) ('guid', GUID), ('flags', DWORD), )
('ErrorCode',ULONG), )
# 3.2.5.4.12 SchRpcStop (Opnum 11) ('path', LPWSTR), ('flags', DWORD), )
('ErrorCode',ULONG), )
# 3.2.5.4.13 SchRpcRun (Opnum 12) ('path', WSTR), ('cArgs', DWORD), ('pArgs', PWSTR_ARRAY), ('flags', DWORD), ('sessionId', DWORD), ('user', LPWSTR), )
('pGuid', GUID), ('ErrorCode',ULONG), )
# 3.2.5.4.14 SchRpcDelete (Opnum 13) ('path', WSTR), ('flags', DWORD), )
('ErrorCode',ULONG), )
# 3.2.5.4.15 SchRpcRename (Opnum 14) ('path', WSTR), ('newName', WSTR), ('flags', DWORD), )
('ErrorCode',ULONG), )
# 3.2.5.4.16 SchRpcScheduledRuntimes (Opnum 15) ('path', WSTR), ('start', PSYSTEMTIME), ('end', PSYSTEMTIME), ('flags', DWORD), ('cRequested', DWORD), )
('pcRuntimes',DWORD), ('pRuntimes',PSYSTEMTIME_ARRAY), ('ErrorCode',ULONG), )
# 3.2.5.4.17 SchRpcGetLastRunInfo (Opnum 16) ('path', WSTR), )
('pLastRuntime',SYSTEMTIME), ('pLastReturnCode',DWORD), ('ErrorCode',ULONG), )
# 3.2.5.4.18 SchRpcGetTaskInfo (Opnum 17) ('path', WSTR), ('flags', DWORD), )
('pEnabled',DWORD), ('pState',DWORD), ('ErrorCode',ULONG), )
# 3.2.5.4.19 SchRpcGetNumberOfMissedRuns (Opnum 18) ('path', WSTR), )
('pNumberOfMissedRuns',DWORD), ('ErrorCode',ULONG), )
# 3.2.5.4.20 SchRpcEnableTask (Opnum 19) ('path', WSTR), ('enabled', DWORD), )
('ErrorCode',ULONG), )
################################################################################ # OPNUMs and their corresponding structures ################################################################################ 0 : (SchRpcHighestVersion,SchRpcHighestVersionResponse ), 1 : (SchRpcRegisterTask,SchRpcRegisterTaskResponse ), 2 : (SchRpcRetrieveTask,SchRpcRetrieveTaskResponse ), 3 : (SchRpcCreateFolder,SchRpcCreateFolderResponse ), 6 : (SchRpcEnumFolders,SchRpcEnumFoldersResponse ), 7 : (SchRpcEnumTasks,SchRpcEnumTasksResponse ), 8 : (SchRpcEnumInstances,SchRpcEnumInstancesResponse ), 9 : (SchRpcGetInstanceInfo,SchRpcGetInstanceInfoResponse ), 10 : (SchRpcStopInstance,SchRpcStopInstanceResponse ), 11 : (SchRpcStop,SchRpcStopResponse ), 12 : (SchRpcRun,SchRpcRunResponse ), 13 : (SchRpcDelete,SchRpcDeleteResponse ), 14 : (SchRpcRename,SchRpcRenameResponse ), 15 : (SchRpcScheduledRuntimes,SchRpcScheduledRuntimesResponse ), 16 : (SchRpcGetLastRunInfo,SchRpcGetLastRunInfoResponse ), 17 : (SchRpcGetTaskInfo,SchRpcGetTaskInfoResponse ), 18 : (SchRpcGetNumberOfMissedRuns,SchRpcGetNumberOfMissedRunsResponse), }
################################################################################ # HELPER FUNCTIONS ################################################################################ return string
else:
request = SchRpcRegisterTask() request['path'] = checkNullString(path) request['xml'] = checkNullString(xml) request['flags'] = flags request['sddl'] = sddl request['logonType'] = logonType request['cCreds'] = len(pCreds) if len(pCreds) == 0: request['pCreds'] = NULL else: for cred in pCreds: request['pCreds'].append(cred) return dce.request(request)
schRpcEnumTasks = SchRpcEnumTasks() schRpcEnumTasks['path'] = checkNullString(path) schRpcEnumTasks['flags'] = flags schRpcEnumTasks['startIndex'] = startIndex schRpcEnumTasks['cRequested'] = cRequested return dce.request(schRpcEnumTasks)
schRpcGetInstanceInfo = SchRpcGetInstanceInfo() schRpcGetInstanceInfo['guid'] = guid return dce.request(schRpcGetInstanceInfo)
schRpcStopInstance = SchRpcStopInstance() schRpcStopInstance['guid'] = guid schRpcStopInstance['flags'] = flags return dce.request(schRpcStopInstance)
schRpcStop= SchRpcStop() schRpcStop['path'] = path schRpcStop['flags'] = flags return dce.request(schRpcStop)
schRpcRun = SchRpcRun() schRpcRun['path'] = checkNullString(path) schRpcRun['cArgs'] = len(pArgs) for arg in pArgs: argn = LPWSTR() argn['Data'] = checkNullString(arg) schRpcRun['pArgs'].append(argn) schRpcRun['flags'] = flags schRpcRun['sessionId'] = sessionId schRpcRun['user'] = user return dce.request(schRpcRun)
else: schRpcEnableTask['enabled'] = 0 |