Coverage for /root/GitHubProjects/impacket/impacket/dcerpc/v5/tsch.py: 83%

# Coverage for /root/GitHubProjects/impacket/impacket/dcerpc/v5/tsch.py : 83%

## 371 statements

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

1# Impacket - Collection of Python classes for working with network protocols.

2#

3# SECUREAUTH LABS. Copyright (C) 2020 SecureAuth Corporation. All rights reserved.

4#

5# This software is provided under a slightly modified version

6# of the Apache Software License. See the accompanying LICENSE file

7# for more information.

8#

9# Description:

10# [MS-TSCH] ITaskSchedulerService Interface implementation

11#

12# Best way to learn how to use these calls is to grab the protocol standard

13# so you understand what the call does, and then read the test case located

14# at https://github.com/SecureAuthCorp/impacket/tree/master/tests/SMB_RPC

15#

16# Some calls have helper functions, which makes it even easier to use.

17# They are located at the end of this file.

18# Helper functions start with "h"<name of the call>.

19# There are test cases for them too.

20#

21# Author:

22# Alberto Solino (@agsolino)

23#

24 from impacket.dcerpc.v5.ndr import NDRCALL, NDRSTRUCT, NDRPOINTER, NDRUniConformantArray

25 from impacket.dcerpc.v5.dtypes import DWORD, LPWSTR, ULONG, WSTR, NULL, GUID, PSYSTEMTIME, SYSTEMTIME

26 from impacket.structure import Structure

27 from impacket import hresult_errors, system_errors

28 from impacket.uuid import uuidtup_to_bin

29 from impacket.dcerpc.v5.rpcrt import DCERPCException

30

31 MSRPC_UUID_TSCHS = uuidtup_to_bin(('86D35949-83C9-4044-B424-DB363231FD0C','1.0'))

32

33 class DCERPCSessionError(DCERPCException):

34 def __init__(self, error_string=None, error_code=None, packet=None):

35 DCERPCException.__init__(self, error_string, error_code, packet)

36

37 def __str__( self ):

38 key = self.error_code

39 if key in hresult_errors.ERROR_MESSAGES: 39 ↛ 43line 39 didn't jump to line 43, because the condition on line 39 was never false

40 error_msg_short = hresult_errors.ERROR_MESSAGES[key][0]

41 error_msg_verbose = hresult_errors.ERROR_MESSAGES[key][1]

42 return 'TSCH SessionError: code: 0x%x - %s - %s' % (self.error_code, error_msg_short, error_msg_verbose)

43 elif key & 0xffff in system_errors.ERROR_MESSAGES:

44 error_msg_short = system_errors.ERROR_MESSAGES[key & 0xffff][0]

45 error_msg_verbose = system_errors.ERROR_MESSAGES[key & 0xffff][1]

46 return 'TSCH SessionError: code: 0x%x - %s - %s' % (self.error_code, error_msg_short, error_msg_verbose)

47 else:

48 return 'TSCH SessionError: unknown error code: 0x%x' % self.error_code

49

50################################################################################

51# CONSTANTS

52################################################################################

53# 2.3.1 Constant Values

54 CNLEN = 15

55 DNLEN = CNLEN

56 UNLEN = 256

57 MAX_BUFFER_SIZE = (DNLEN+UNLEN+1+1)

58

59# 2.3.7 Flags

60 TASK_FLAG_INTERACTIVE = 0x1

61 TASK_FLAG_DELETE_WHEN_DONE = 0x2

62 TASK_FLAG_DISABLED = 0x4

63 TASK_FLAG_START_ONLY_IF_IDLE = 0x10

64 TASK_FLAG_KILL_ON_IDLE_END = 0x20

65 TASK_FLAG_DONT_START_IF_ON_BATTERIES = 0x40

66 TASK_FLAG_KILL_IF_GOING_ON_BATTERIES = 0x80

67 TASK_FLAG_RUN_ONLY_IF_DOCKED = 0x100

68 TASK_FLAG_HIDDEN = 0x200

69 TASK_FLAG_RUN_IF_CONNECTED_TO_INTERNET = 0x400

70 TASK_FLAG_RESTART_ON_IDLE_RESUME = 0x800

71 TASK_FLAG_SYSTEM_REQUIRED = 0x1000

72 TASK_FLAG_RUN_ONLY_IF_LOGGED_ON = 0x2000

73

74# 2.3.9 TASK_LOGON_TYPE

75 TASK_LOGON_NONE = 0

76 TASK_LOGON_PASSWORD = 1

77 TASK_LOGON_S4U = 2

78 TASK_LOGON_INTERACTIVE_TOKEN = 3

79 TASK_LOGON_GROUP = 4

80 TASK_LOGON_SERVICE_ACCOUNT = 5

81 TASK_LOGON_INTERACTIVE_TOKEN_OR_PASSWORD = 6

82

83# 2.3.13 TASK_STATE

84 TASK_STATE_UNKNOWN = 0

85 TASK_STATE_DISABLED = 1

86 TASK_STATE_QUEUED = 2

87 TASK_STATE_READY = 3

88 TASK_STATE_RUNNING = 4

89

90# 2.4.1 FIXDLEN_DATA

91 SCHED_S_TASK_READY = 0x00041300

92 SCHED_S_TASK_RUNNING = 0x00041301

93 SCHED_S_TASK_NOT_SCHEDULED = 0x00041301

94

95# 2.4.2.11 Triggers

96 TASK_TRIGGER_FLAG_HAS_END_DATE = 0

97 TASK_TRIGGER_FLAG_KILL_AT_DURATION_END = 0

98 TASK_TRIGGER_FLAG_DISABLED = 0

99

100# ToDo: Change this to enums

101 ONCE = 0

102 DAILY = 1

103 WEEKLY = 2

104 MONTHLYDATE = 3

105 MONTHLYDOW = 4

106 EVENT_ON_IDLE = 5

107 EVENT_AT_SYSTEMSTART = 6

108 EVENT_AT_LOGON = 7

109

110 SUNDAY = 0

111 MONDAY = 1

112 TUESDAY = 2

113 WEDNESDAY = 3

114 THURSDAY = 4

115 FRIDAY = 5

116 SATURDAY = 6

117

118 JANUARY = 1

119 FEBRUARY = 2

120 MARCH = 3

121 APRIL = 4

122 MAY = 5

123 JUNE = 6

124 JULY = 7

125 AUGUST = 8

126 SEPTEMBER = 9

127 OCTOBER = 10

128 NOVEMBER = 11

129 DECEMBER = 12

130

131# 2.4.2.11.8 MONTHLYDOW Trigger

132 FIRST_WEEK = 1

133 SECOND_WEEK = 2

134 THIRD_WEEK = 3

135 FOURTH_WEEK = 4

136 LAST_WEEK = 5

137

138# 2.3.12 TASK_NAMES

139 TASK_NAMES = LPWSTR

140

141# 3.2.5.4.2 SchRpcRegisterTask (Opnum 1)

142 TASK_VALIDATE_ONLY = 1<<(31-31)

143 TASK_CREATE = 1<<(31-30)

144 TASK_UPDATE = 1<<(31-29)

145 TASK_DISABLE = 1<<(31-28)

146 TASK_DON_ADD_PRINCIPAL_ACE = 1<<(31-27)

147 TASK_IGNORE_REGISTRATION_TRIGGERS = 1<<(31-26)

148

149# 3.2.5.4.5 SchRpcSetSecurity (Opnum 4)

150 TASK_DONT_ADD_PRINCIPAL_ACE = 1<<(31-27)

151 SCH_FLAG_FOLDER = 1<<(31-2)

152 SCH_FLAG_TASK = 1<<(31-1)

153

154# 3.2.5.4.7 SchRpcEnumFolders (Opnum 6)

155 TASK_ENUM_HIDDEN = 1

156

157# 3.2.5.4.13 SchRpcRun (Opnum 12)

158 TASK_RUN_AS_SELF = 1<<(31-31)

159 TASK_RUN_IGNORE_CONSTRAINTS = 1<<(31-30)

160 TASK_RUN_USE_SESSION_ID = 1<<(31-29)

161 TASK_RUN_USER_SID = 1<<(31-28)

162

163# 3.2.5.4.18 SchRpcGetTaskInfo (Opnum 17)

164 SCH_FLAG_STATE = 1<<(31-3)

165

166################################################################################

167# STRUCTURES

168################################################################################

169# 2.3.12 TASK_NAMES

170 class TASK_NAMES_ARRAY(NDRUniConformantArray):

171 item = TASK_NAMES

172

173 class PTASK_NAMES_ARRAY(NDRPOINTER):

174 referent = (

175 ('Data',TASK_NAMES_ARRAY),

176 )

177

178 class WSTR_ARRAY(NDRUniConformantArray):

179 item = WSTR

180

181 class PWSTR_ARRAY(NDRPOINTER):

182 referent = (

183 ('Data',WSTR_ARRAY),

184 )

185

186 class GUID_ARRAY(NDRUniConformantArray):

187 item = GUID

188

189 class PGUID_ARRAY(NDRPOINTER):

190 referent = (

191 ('Data',GUID_ARRAY),

192 )

193

194# 3.2.5.4.13 SchRpcRun (Opnum 12)

195 class SYSTEMTIME_ARRAY(NDRUniConformantArray):

196 item = SYSTEMTIME

197

198 class PSYSTEMTIME_ARRAY(NDRPOINTER):

199 referent = (

200 ('Data',SYSTEMTIME_ARRAY),

201 )

202

203# 2.3.8 TASK_USER_CRED

204 class TASK_USER_CRED(NDRSTRUCT):

205 structure = (

206 ('userId',LPWSTR),

207 ('password',LPWSTR),

208 ('flags',DWORD),

209 )

210

211 class TASK_USER_CRED_ARRAY(NDRUniConformantArray):

212 item = TASK_USER_CRED

213

214 class LPTASK_USER_CRED_ARRAY(NDRPOINTER):

215 referent = (

216 ('Data',TASK_USER_CRED_ARRAY),

217 )

218

219# 2.3.10 TASK_XML_ERROR_INFO

220 class TASK_XML_ERROR_INFO(NDRSTRUCT):

221 structure = (

222 ('line',DWORD),

223 ('column',DWORD),

224 ('node',LPWSTR),

225 ('value',LPWSTR),

226 )

227

228 class PTASK_XML_ERROR_INFO(NDRPOINTER):

229 referent = (

230 ('Data',TASK_XML_ERROR_INFO),

231 )

232

233# 2.4.1 FIXDLEN_DATA

234 class FIXDLEN_DATA(Structure):

235 structure = (

236 ('Product Version','<H=0'),

237 ('File Version','<H=0'),

238 ('Job uuid','16s="'),

239 ('App Name Len Offset','<H=0'),

240 ('Trigger Offset','<H=0'),

241 ('Error Retry Count','<H=0'),

242 ('Error Retry Interval','<H=0'),

243 ('Idle Deadline','<H=0'),

244 ('Idle Wait','<H=0'),

245 ('Priority','<L=0'),

246 ('Maximum Run Time','<L=0'),

247 ('Exit Code','<L=0'),

248 ('Status','<L=0'),

249 ('Flags','<L=0'),

250 )

251

252# 2.4.2.11 Triggers

253 class TRIGGERS(Structure):

254 structure = (

255 ('Trigger Size','<H=0'),

256 ('Reserved1','<H=0'),

257 ('Begin Year','<H=0'),

258 ('Begin Month','<H=0'),

259 ('Begin Day','<H=0'),

260 ('End Year','<H=0'),

261 ('End Month','<H=0'),

262 ('End Day','<H=0'),

263 ('Start Hour','<H=0'),

264 ('Start Minute','<H=0'),

265 ('Minutes Duration','<L=0'),

266 ('Minutes Interval','<L=0'),

267 ('Flags','<L=0'),

268 ('Trigger Type','<L=0'),

269 ('TriggerSpecific0','<H=0'),

270 ('TriggerSpecific1','<H=0'),

271 ('TriggerSpecific2','<H=0'),

272 ('Padding','<H=0'),

273 ('Reserved2','<H=0'),

274 ('Reserved3','<H=0'),

275 )

276

277# 2.4.2.11.6 WEEKLY Trigger

278 class WEEKLY(Structure):

279 structure = (

280 ('Trigger Type','<L=0'),

281 ('Weeks Interval','<H=0'),

282 ('DaysOfTheWeek','<H=0'),

283 ('Unused','<H=0'),

284 ('Padding','<H=0'),

285 )

286

287# 2.4.2.11.7 MONTHLYDATE Trigger

288 class MONTHLYDATE(Structure):

289 structure = (

290 ('Trigger Type','<L=0'),

291 ('Days','<L=0'),

292 ('Months','<H=0'),

293 ('Padding','<H=0'),

294 )

295

296# 2.4.2.11.8 MONTHLYDOW Trigger

297 class MONTHLYDOW(Structure):

298 structure = (

299 ('Trigger Type','<L=0'),

300 ('WhichWeek','<H=0'),

301 ('DaysOfTheWeek','<H=0'),

302 ('Months','<H=0'),

303 ('Padding','<H=0'),

304 ('Reserved2','<H=0'),

305 ('Reserved3','<H=0'),

306 )

307

308# 2.4.2.12 Job Signature

309 class JOB_SIGNATURE(Structure):

310 structure = (

311 ('SignatureVersion','<HH0'),

312 ('MinClientVersion','<H=0'),

313 ('Signature','64s="'),

314 )

315

316################################################################################

317# RPC CALLS

318################################################################################

319# 3.2.5.4.1 SchRpcHighestVersion (Opnum 0)

320 class SchRpcHighestVersion(NDRCALL):

321 opnum = 0

322 structure = (

323 )

324

325 class SchRpcHighestVersionResponse(NDRCALL):

326 structure = (

327 ('pVersion', DWORD),

328 ('ErrorCode',ULONG),

329 )

330

331# 3.2.5.4.2 SchRpcRegisterTask (Opnum 1)

332 class SchRpcRegisterTask(NDRCALL):

333 opnum = 1

334 structure = (

335 ('path', LPWSTR),

336 ('xml', WSTR),

337 ('flags', DWORD),

338 ('sddl', LPWSTR),

339 ('logonType', DWORD),

340 ('cCreds', DWORD),

341 ('pCreds', LPTASK_USER_CRED_ARRAY),

342 )

343

344 class SchRpcRegisterTaskResponse(NDRCALL):

345 structure = (

346 ('pActualPath', LPWSTR),

347 ('pErrorInfo', PTASK_XML_ERROR_INFO),

348 ('ErrorCode',ULONG),

349 )

350

351# 3.2.5.4.3 SchRpcRetrieveTask (Opnum 2)

352 class SchRpcRetrieveTask(NDRCALL):

353 opnum = 2

354 structure = (

355 ('path', WSTR),

356 ('lpcwszLanguagesBuffer', WSTR),

357 ('pulNumLanguages', DWORD),

358 )

359

360 class SchRpcRetrieveTaskResponse(NDRCALL):

361 structure = (

362 ('pXml', LPWSTR),

363 ('ErrorCode',ULONG),

364 )

365

366# 3.2.5.4.4 SchRpcCreateFolder (Opnum 3)

367 class SchRpcCreateFolder(NDRCALL):

368 opnum = 3

369 structure = (

370 ('path', WSTR),

371 ('sddl', LPWSTR),

372 ('flags', DWORD),

373 )

374

375 class SchRpcCreateFolderResponse(NDRCALL):

376 structure = (

377 ('ErrorCode',ULONG),

378 )

379

380# 3.2.5.4.5 SchRpcSetSecurity (Opnum 4)

381 class SchRpcSetSecurity(NDRCALL):

382 opnum = 4

383 structure = (

384 ('path', WSTR),

385 ('sddl', WSTR),

386 ('flags', DWORD),

387 )

388

389 class SchRpcSetSecurityResponse(NDRCALL):

390 structure = (

391 ('ErrorCode',ULONG),

392 )

393

394# 3.2.5.4.6 SchRpcGetSecurity (Opnum 5)

395 class SchRpcGetSecurity(NDRCALL):

396 opnum = 5

397 structure = (

398 ('path', WSTR),

399 ('securityInformation', DWORD),

400 )

401

402 class SchRpcGetSecurityResponse(NDRCALL):

403 structure = (

404 ('sddl',LPWSTR),

405 ('ErrorCode',ULONG),

406 )

407

408# 3.2.5.4.7 SchRpcEnumFolders (Opnum 6)

409 class SchRpcEnumFolders(NDRCALL):

410 opnum = 6

411 structure = (

412 ('path', WSTR),

413 ('flags', DWORD),

414 ('startIndex', DWORD),

415 ('cRequested', DWORD),

416 )

417

418 class SchRpcEnumFoldersResponse(NDRCALL):

419 structure = (

420 ('startIndex', DWORD),

421 ('pcNames', DWORD),

422 ('pNames', PTASK_NAMES_ARRAY),

423 ('ErrorCode',ULONG),

424 )

425

426# 3.2.5.4.8 SchRpcEnumTasks (Opnum 7)

427 class SchRpcEnumTasks(NDRCALL):

428 opnum = 7

429 structure = (

430 ('path', WSTR),

431 ('flags', DWORD),

432 ('startIndex', DWORD),

433 ('cRequested', DWORD),

434 )

435

436 class SchRpcEnumTasksResponse(NDRCALL):

437 structure = (

438 ('startIndex', DWORD),

439 ('pcNames', DWORD),

440 ('pNames', PTASK_NAMES_ARRAY),

441 ('ErrorCode',ULONG),

442 )

443

444# 3.2.5.4.9 SchRpcEnumInstances (Opnum 8)

445 class SchRpcEnumInstances(NDRCALL):

446 opnum = 8

447 structure = (

448 ('path', LPWSTR),

449 ('flags', DWORD),

450 )

451

452 class SchRpcEnumInstancesResponse(NDRCALL):

453 structure = (

454 ('pcGuids', DWORD),

455 ('pGuids', PGUID_ARRAY),

456 ('ErrorCode',ULONG),

457 )

458

459# 3.2.5.4.10 SchRpcGetInstanceInfo (Opnum 9)

460 class SchRpcGetInstanceInfo(NDRCALL):

461 opnum = 9

462 structure = (

463 ('guid', GUID),

464 )

465

466 class SchRpcGetInstanceInfoResponse(NDRCALL):

467 structure = (

468 ('pPath', LPWSTR),

469 ('pState', DWORD),

470 ('pCurrentAction', LPWSTR),

471 ('pInfo', LPWSTR),

472 ('pcGroupInstances', DWORD),

473 ('pGroupInstances', PGUID_ARRAY),

474 ('pEnginePID', DWORD),

475 ('ErrorCode',ULONG),

476 )

477

478# 3.2.5.4.11 SchRpcStopInstance (Opnum 10)

479 class SchRpcStopInstance(NDRCALL):

480 opnum = 10

481 structure = (

482 ('guid', GUID),

483 ('flags', DWORD),

484 )

485

486 class SchRpcStopInstanceResponse(NDRCALL):

487 structure = (

488 ('ErrorCode',ULONG),

489 )

490

491# 3.2.5.4.12 SchRpcStop (Opnum 11)

492 class SchRpcStop(NDRCALL):

493 opnum = 11

494 structure = (

495 ('path', LPWSTR),

496 ('flags', DWORD),

497 )

498

499 class SchRpcStopResponse(NDRCALL):

500 structure = (

501 ('ErrorCode',ULONG),

502 )

503

504# 3.2.5.4.13 SchRpcRun (Opnum 12)

505 class SchRpcRun(NDRCALL):

506 opnum = 12

507 structure = (

508 ('path', WSTR),

509 ('cArgs', DWORD),

510 ('pArgs', PWSTR_ARRAY),

511 ('flags', DWORD),

512 ('sessionId', DWORD),

513 ('user', LPWSTR),

514 )

515

516 class SchRpcRunResponse(NDRCALL):

517 structure = (

518 ('pGuid', GUID),

519 ('ErrorCode',ULONG),

520 )

521

522# 3.2.5.4.14 SchRpcDelete (Opnum 13)

523 class SchRpcDelete(NDRCALL):

524 opnum = 13

525 structure = (

526 ('path', WSTR),

527 ('flags', DWORD),

528 )

529

530 class SchRpcDeleteResponse(NDRCALL):

531 structure = (

532 ('ErrorCode',ULONG),

533 )

534

535# 3.2.5.4.15 SchRpcRename (Opnum 14)

536 class SchRpcRename(NDRCALL):

537 opnum = 14

538 structure = (

539 ('path', WSTR),

540 ('newName', WSTR),

541 ('flags', DWORD),

542 )

543

544 class SchRpcRenameResponse(NDRCALL):

545 structure = (

546 ('ErrorCode',ULONG),

547 )

548

549# 3.2.5.4.16 SchRpcScheduledRuntimes (Opnum 15)

550 class SchRpcScheduledRuntimes(NDRCALL):

551 opnum = 15

552 structure = (

553 ('path', WSTR),

554 ('start', PSYSTEMTIME),

555 ('end', PSYSTEMTIME),

556 ('flags', DWORD),

557 ('cRequested', DWORD),

558 )

559

560 class SchRpcScheduledRuntimesResponse(NDRCALL):

561 structure = (

562 ('pcRuntimes',DWORD),

563 ('pRuntimes',PSYSTEMTIME_ARRAY),

564 ('ErrorCode',ULONG),

565 )

566

567# 3.2.5.4.17 SchRpcGetLastRunInfo (Opnum 16)

568 class SchRpcGetLastRunInfo(NDRCALL):

569 opnum = 16

570 structure = (

571 ('path', WSTR),

572 )

573

574 class SchRpcGetLastRunInfoResponse(NDRCALL):

575 structure = (

576 ('pLastRuntime',SYSTEMTIME),

577 ('pLastReturnCode',DWORD),

578 ('ErrorCode',ULONG),

579 )

580

581# 3.2.5.4.18 SchRpcGetTaskInfo (Opnum 17)

582 class SchRpcGetTaskInfo(NDRCALL):

583 opnum = 17

584 structure = (

585 ('path', WSTR),

586 ('flags', DWORD),

587 )

588

589 class SchRpcGetTaskInfoResponse(NDRCALL):

590 structure = (

591 ('pEnabled',DWORD),

592 ('pState',DWORD),

593 ('ErrorCode',ULONG),

594 )

595

596# 3.2.5.4.19 SchRpcGetNumberOfMissedRuns (Opnum 18)

597 class SchRpcGetNumberOfMissedRuns(NDRCALL):

598 opnum = 18

599 structure = (

600 ('path', WSTR),

601 )

602

603 class SchRpcGetNumberOfMissedRunsResponse(NDRCALL):

604 structure = (

605 ('pNumberOfMissedRuns',DWORD),

606 ('ErrorCode',ULONG),

607 )

608

609# 3.2.5.4.20 SchRpcEnableTask (Opnum 19)

610 class SchRpcEnableTask(NDRCALL):

611 opnum = 19

612 structure = (

613 ('path', WSTR),

614 ('enabled', DWORD),

615 )

616

617 class SchRpcEnableTaskResponse(NDRCALL):

618 structure = (

619 ('ErrorCode',ULONG),

620 )

621

622################################################################################

623# OPNUMs and their corresponding structures

624################################################################################

625 OPNUMS = {

626 0 : (SchRpcHighestVersion,SchRpcHighestVersionResponse ),

627 1 : (SchRpcRegisterTask,SchRpcRegisterTaskResponse ),

628 2 : (SchRpcRetrieveTask,SchRpcRetrieveTaskResponse ),

629 3 : (SchRpcCreateFolder,SchRpcCreateFolderResponse ),

630 4 : (SchRpcSetSecurity,SchRpcSetSecurityResponse ),

631 5 : (SchRpcGetSecurity,SchRpcGetSecurityResponse ),

632 6 : (SchRpcEnumFolders,SchRpcEnumFoldersResponse ),

633 7 : (SchRpcEnumTasks,SchRpcEnumTasksResponse ),

634 8 : (SchRpcEnumInstances,SchRpcEnumInstancesResponse ),

635 9 : (SchRpcGetInstanceInfo,SchRpcGetInstanceInfoResponse ),

636 10 : (SchRpcStopInstance,SchRpcStopInstanceResponse ),

637 11 : (SchRpcStop,SchRpcStopResponse ),

638 12 : (SchRpcRun,SchRpcRunResponse ),

639 13 : (SchRpcDelete,SchRpcDeleteResponse ),

640 14 : (SchRpcRename,SchRpcRenameResponse ),

641 15 : (SchRpcScheduledRuntimes,SchRpcScheduledRuntimesResponse ),

642 16 : (SchRpcGetLastRunInfo,SchRpcGetLastRunInfoResponse ),

643 17 : (SchRpcGetTaskInfo,SchRpcGetTaskInfoResponse ),

644 18 : (SchRpcGetNumberOfMissedRuns,SchRpcGetNumberOfMissedRunsResponse),

645 19 : (SchRpcEnableTask,SchRpcEnableTaskResponse),

646}

647

648################################################################################

649# HELPER FUNCTIONS

650################################################################################

651 def checkNullString(string):

652 if string == NULL: 652 ↛ 653line 652 didn't jump to line 653, because the condition on line 652 was never true

653 return string

654

655 if string[-1:] != '\x00':

656 return string + '\x00'

657 else:

658 return string

659

660 def hSchRpcHighestVersion(dce):

661 return dce.request(SchRpcHighestVersion())

662

663 def hSchRpcRegisterTask(dce, path, xml, flags, sddl, logonType, pCreds = ()):

664 request = SchRpcRegisterTask()

665 request['path'] = checkNullString(path)

666 request['xml'] = checkNullString(xml)

667 request['flags'] = flags

668 request['sddl'] = sddl

669 request['logonType'] = logonType

670 request['cCreds'] = len(pCreds)

671 if len(pCreds) == 0:

672 request['pCreds'] = NULL

673 else:

674 for cred in pCreds:

675 request['pCreds'].append(cred)

676 return dce.request(request)

677

678 def hSchRpcRetrieveTask(dce, path, lpcwszLanguagesBuffer = '\x00', pulNumLanguages=0 ):

679 schRpcRetrieveTask = SchRpcRetrieveTask()

680 schRpcRetrieveTask['path'] = checkNullString(path)

681 schRpcRetrieveTask['lpcwszLanguagesBuffer'] = lpcwszLanguagesBuffer

682 schRpcRetrieveTask['pulNumLanguages'] = pulNumLanguages

683 return dce.request(schRpcRetrieveTask)

684

685 def hSchRpcCreateFolder(dce, path, sddl = NULL):

686 schRpcCreateFolder = SchRpcCreateFolder()

687 schRpcCreateFolder['path'] = checkNullString(path)

688 schRpcCreateFolder['sddl'] = sddl

689 schRpcCreateFolder['flags'] = 0

690 return dce.request(schRpcCreateFolder)

691

692 def hSchRpcSetSecurity(dce, path, sddl, flags):

693 schRpcSetSecurity = SchRpcSetSecurity()

694 schRpcSetSecurity['path'] = checkNullString(path)

695 schRpcSetSecurity['sddl'] = checkNullString(sddl)

696 schRpcSetSecurity['flags'] = flags

697 return dce.request(schRpcSetSecurity)

698

699 def hSchRpcGetSecurity(dce, path, securityInformation=0xffffffff):

700 schRpcGetSecurity = SchRpcGetSecurity()

701 schRpcGetSecurity['path'] = checkNullString(path)

702 schRpcGetSecurity['securityInformation'] = securityInformation

703 return dce.request(schRpcGetSecurity)

704

705 def hSchRpcEnumFolders(dce, path, flags=TASK_ENUM_HIDDEN, startIndex=0, cRequested=0xffffffff):

706 schRpcEnumFolders = SchRpcEnumFolders()

707 schRpcEnumFolders['path'] = checkNullString(path)

708 schRpcEnumFolders['flags'] = flags

709 schRpcEnumFolders['startIndex'] = startIndex

710 schRpcEnumFolders['cRequested'] = cRequested

711 return dce.request(schRpcEnumFolders)

712

713 def hSchRpcEnumTasks(dce, path, flags=TASK_ENUM_HIDDEN, startIndex=0, cRequested=0xffffffff):

714 schRpcEnumTasks = SchRpcEnumTasks()

715 schRpcEnumTasks['path'] = checkNullString(path)

716 schRpcEnumTasks['flags'] = flags

717 schRpcEnumTasks['startIndex'] = startIndex

718 schRpcEnumTasks['cRequested'] = cRequested

719 return dce.request(schRpcEnumTasks)

720

721 def hSchRpcEnumInstances(dce, path, flags=TASK_ENUM_HIDDEN):

722 schRpcEnumInstances = SchRpcEnumInstances()

723 schRpcEnumInstances['path'] = checkNullString(path)

724 schRpcEnumInstances['flags'] = flags

725 return dce.request(schRpcEnumInstances)

726

727 def hSchRpcGetInstanceInfo(dce, guid):

728 schRpcGetInstanceInfo = SchRpcGetInstanceInfo()

729 schRpcGetInstanceInfo['guid'] = guid

730 return dce.request(schRpcGetInstanceInfo)

731

732 def hSchRpcStopInstance(dce, guid, flags = 0):

733 schRpcStopInstance = SchRpcStopInstance()

734 schRpcStopInstance['guid'] = guid

735 schRpcStopInstance['flags'] = flags

736 return dce.request(schRpcStopInstance)

737

738 def hSchRpcStop(dce, path, flags = 0):

739 schRpcStop= SchRpcStop()

740 schRpcStop['path'] = checkNullString(path)

741 schRpcStop['flags'] = flags

742 return dce.request(schRpcStop)

743

744 def hSchRpcRun(dce, path, pArgs=(), flags=0, sessionId=0, user = NULL):

745 schRpcRun = SchRpcRun()

746 schRpcRun['path'] = checkNullString(path)

747 schRpcRun['cArgs'] = len(pArgs)

748 for arg in pArgs:

749 argn = LPWSTR()

750 argn['Data'] = checkNullString(arg)

751 schRpcRun['pArgs'].append(argn)

752 schRpcRun['flags'] = flags

753 schRpcRun['sessionId'] = sessionId

754 schRpcRun['user'] = user

755 return dce.request(schRpcRun)

756

757 def hSchRpcDelete(dce, path, flags = 0):

758 schRpcDelete = SchRpcDelete()

759 schRpcDelete['path'] = checkNullString(path)

760 schRpcDelete['flags'] = flags

761 return dce.request(schRpcDelete)

762

763 def hSchRpcRename(dce, path, newName, flags = 0):

764 schRpcRename = SchRpcRename()

765 schRpcRename['path'] = checkNullString(path)

766 schRpcRename['newName'] = checkNullString(newName)

767 schRpcRename['flags'] = flags

768 return dce.request(schRpcRename)

769

770 def hSchRpcScheduledRuntimes(dce, path, start = NULL, end = NULL, flags = 0, cRequested = 10):

771 schRpcScheduledRuntimes = SchRpcScheduledRuntimes()

772 schRpcScheduledRuntimes['path'] = checkNullString(path)

773 schRpcScheduledRuntimes['start'] = start

774 schRpcScheduledRuntimes['end'] = end

775 schRpcScheduledRuntimes['flags'] = flags

776 schRpcScheduledRuntimes['cRequested'] = cRequested

777 return dce.request(schRpcScheduledRuntimes)

778

779 def hSchRpcGetLastRunInfo(dce, path):

780 schRpcGetLastRunInfo = SchRpcGetLastRunInfo()

781 schRpcGetLastRunInfo['path'] = checkNullString(path)

782 return dce.request(schRpcGetLastRunInfo)

783

784 def hSchRpcGetTaskInfo(dce, path, flags = 0):

785 schRpcGetTaskInfo = SchRpcGetTaskInfo()

786 schRpcGetTaskInfo['path'] = checkNullString(path)

787 schRpcGetTaskInfo['flags'] = flags

788 return dce.request(schRpcGetTaskInfo)

789

790 def hSchRpcGetNumberOfMissedRuns(dce, path):

791 schRpcGetNumberOfMissedRuns = SchRpcGetNumberOfMissedRuns()

792 schRpcGetNumberOfMissedRuns['path'] = checkNullString(path)

793 return dce.request(schRpcGetNumberOfMissedRuns)

794

795 def hSchRpcEnableTask(dce, path, enabled = True):

796 schRpcEnableTask = SchRpcEnableTask()

797 schRpcEnableTask['path'] = checkNullString(path)

798 if enabled is True: 798 ↛ 801line 798 didn't jump to line 801, because the condition on line 798 was never false

799 schRpcEnableTask['enabled'] = 1

800 else:

801 schRpcEnableTask['enabled'] = 0

802 return dce.request(schRpcEnableTask)