Hide keyboard shortcuts

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# SECUREAUTH LABS. Copyright 2018 SecureAuth Corporation. All rights reserved. 

2# 

3# This software is provided under under a slightly modified version 

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

5# for more information. 

6# 

7# Author: Alberto Solino (@agsolino) 

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# 

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

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

23from impacket.structure import Structure 

24from impacket import hresult_errors, system_errors 

25from impacket.uuid import uuidtup_to_bin 

26from impacket.dcerpc.v5.rpcrt import DCERPCException 

27 

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

29 

30class DCERPCSessionError(DCERPCException): 

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

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

33 

34 def __str__( self ): 

35 key = self.error_code 

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

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

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

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

40 elif key & 0xffff in system_errors.ERROR_MESSAGES: 

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

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

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

44 else: 

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

46 

47################################################################################ 

48# CONSTANTS 

49################################################################################ 

50# 2.3.1 Constant Values 

51CNLEN = 15 

52DNLEN = CNLEN 

53UNLEN = 256 

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

55 

56# 2.3.7 Flags 

57TASK_FLAG_INTERACTIVE = 0x1 

58TASK_FLAG_DELETE_WHEN_DONE = 0x2 

59TASK_FLAG_DISABLED = 0x4 

60TASK_FLAG_START_ONLY_IF_IDLE = 0x10 

61TASK_FLAG_KILL_ON_IDLE_END = 0x20 

62TASK_FLAG_DONT_START_IF_ON_BATTERIES = 0x40 

63TASK_FLAG_KILL_IF_GOING_ON_BATTERIES = 0x80 

64TASK_FLAG_RUN_ONLY_IF_DOCKED = 0x100 

65TASK_FLAG_HIDDEN = 0x200 

66TASK_FLAG_RUN_IF_CONNECTED_TO_INTERNET = 0x400 

67TASK_FLAG_RESTART_ON_IDLE_RESUME = 0x800 

68TASK_FLAG_SYSTEM_REQUIRED = 0x1000 

69TASK_FLAG_RUN_ONLY_IF_LOGGED_ON = 0x2000 

70 

71# 2.3.9 TASK_LOGON_TYPE 

72TASK_LOGON_NONE = 0 

73TASK_LOGON_PASSWORD = 1 

74TASK_LOGON_S4U = 2 

75TASK_LOGON_INTERACTIVE_TOKEN = 3 

76TASK_LOGON_GROUP = 4 

77TASK_LOGON_SERVICE_ACCOUNT = 5 

78TASK_LOGON_INTERACTIVE_TOKEN_OR_PASSWORD = 6 

79 

80# 2.3.13 TASK_STATE 

81TASK_STATE_UNKNOWN = 0 

82TASK_STATE_DISABLED = 1 

83TASK_STATE_QUEUED = 2 

84TASK_STATE_READY = 3 

85TASK_STATE_RUNNING = 4 

86 

87# 2.4.1 FIXDLEN_DATA 

88SCHED_S_TASK_READY = 0x00041300 

89SCHED_S_TASK_RUNNING = 0x00041301 

90SCHED_S_TASK_NOT_SCHEDULED = 0x00041301 

91 

92# 2.4.2.11 Triggers 

93TASK_TRIGGER_FLAG_HAS_END_DATE = 0 

94TASK_TRIGGER_FLAG_KILL_AT_DURATION_END = 0 

95TASK_TRIGGER_FLAG_DISABLED = 0 

96 

97# ToDo: Change this to enums 

98ONCE = 0 

99DAILY = 1 

100WEEKLY = 2 

101MONTHLYDATE = 3 

102MONTHLYDOW = 4 

103EVENT_ON_IDLE = 5 

104EVENT_AT_SYSTEMSTART = 6 

105EVENT_AT_LOGON = 7 

106 

107SUNDAY = 0 

108MONDAY = 1 

109TUESDAY = 2 

110WEDNESDAY = 3 

111THURSDAY = 4 

112FRIDAY = 5 

113SATURDAY = 6 

114 

115JANUARY = 1 

116FEBRUARY = 2 

117MARCH = 3 

118APRIL = 4 

119MAY = 5 

120JUNE = 6 

121JULY = 7 

122AUGUST = 8 

123SEPTEMBER = 9 

124OCTOBER = 10 

125NOVEMBER = 11 

126DECEMBER = 12 

127 

128# 2.4.2.11.8 MONTHLYDOW Trigger 

129FIRST_WEEK = 1 

130SECOND_WEEK = 2 

131THIRD_WEEK = 3 

132FOURTH_WEEK = 4 

133LAST_WEEK = 5 

134 

135# 2.3.12 TASK_NAMES 

136TASK_NAMES = LPWSTR 

137 

138# 3.2.5.4.2 SchRpcRegisterTask (Opnum 1) 

139TASK_VALIDATE_ONLY = 1<<(31-31) 

140TASK_CREATE = 1<<(31-30) 

141TASK_UPDATE = 1<<(31-29) 

142TASK_DISABLE = 1<<(31-28) 

143TASK_DON_ADD_PRINCIPAL_ACE = 1<<(31-27) 

144TASK_IGNORE_REGISTRATION_TRIGGERS = 1<<(31-26) 

145 

146# 3.2.5.4.5 SchRpcSetSecurity (Opnum 4) 

147TASK_DONT_ADD_PRINCIPAL_ACE = 1<<(31-27) 

148SCH_FLAG_FOLDER = 1<<(31-2) 

149SCH_FLAG_TASK = 1<<(31-1) 

150 

151# 3.2.5.4.7 SchRpcEnumFolders (Opnum 6) 

152TASK_ENUM_HIDDEN = 1 

153 

154# 3.2.5.4.13 SchRpcRun (Opnum 12) 

155TASK_RUN_AS_SELF = 1<<(31-31) 

156TASK_RUN_IGNORE_CONSTRAINTS = 1<<(31-30) 

157TASK_RUN_USE_SESSION_ID = 1<<(31-29) 

158TASK_RUN_USER_SID = 1<<(31-28) 

159 

160# 3.2.5.4.18 SchRpcGetTaskInfo (Opnum 17) 

161SCH_FLAG_STATE = 1<<(31-3) 

162 

163################################################################################ 

164# STRUCTURES 

165################################################################################ 

166# 2.3.12 TASK_NAMES 

167class TASK_NAMES_ARRAY(NDRUniConformantArray): 

168 item = TASK_NAMES 

169 

170class PTASK_NAMES_ARRAY(NDRPOINTER): 

171 referent = ( 

172 ('Data',TASK_NAMES_ARRAY), 

173 ) 

174 

175class WSTR_ARRAY(NDRUniConformantArray): 

176 item = WSTR 

177 

178class PWSTR_ARRAY(NDRPOINTER): 

179 referent = ( 

180 ('Data',WSTR_ARRAY), 

181 ) 

182 

183class GUID_ARRAY(NDRUniConformantArray): 

184 item = GUID 

185 

186class PGUID_ARRAY(NDRPOINTER): 

187 referent = ( 

188 ('Data',GUID_ARRAY), 

189 ) 

190 

191# 3.2.5.4.13 SchRpcRun (Opnum 12) 

192class SYSTEMTIME_ARRAY(NDRUniConformantArray): 

193 item = SYSTEMTIME 

194 

195class PSYSTEMTIME_ARRAY(NDRPOINTER): 

196 referent = ( 

197 ('Data',SYSTEMTIME_ARRAY), 

198 ) 

199 

200# 2.3.8 TASK_USER_CRED 

201class TASK_USER_CRED(NDRSTRUCT): 

202 structure = ( 

203 ('userId',LPWSTR), 

204 ('password',LPWSTR), 

205 ('flags',DWORD), 

206 ) 

207 

208class TASK_USER_CRED_ARRAY(NDRUniConformantArray): 

209 item = TASK_USER_CRED 

210 

211class LPTASK_USER_CRED_ARRAY(NDRPOINTER): 

212 referent = ( 

213 ('Data',TASK_USER_CRED_ARRAY), 

214 ) 

215 

216# 2.3.10 TASK_XML_ERROR_INFO 

217class TASK_XML_ERROR_INFO(NDRSTRUCT): 

218 structure = ( 

219 ('line',DWORD), 

220 ('column',DWORD), 

221 ('node',LPWSTR), 

222 ('value',LPWSTR), 

223 ) 

224 

225class PTASK_XML_ERROR_INFO(NDRPOINTER): 

226 referent = ( 

227 ('Data',TASK_XML_ERROR_INFO), 

228 ) 

229 

230# 2.4.1 FIXDLEN_DATA 

231class FIXDLEN_DATA(Structure): 

232 structure = ( 

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

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

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

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

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

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

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

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

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

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

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

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

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

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

247 ) 

248 

249# 2.4.2.11 Triggers 

250class TRIGGERS(Structure): 

251 structure = ( 

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

272 ) 

273 

274# 2.4.2.11.6 WEEKLY Trigger 

275class WEEKLY(Structure): 

276 structure = ( 

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

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

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

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

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

282 ) 

283 

284# 2.4.2.11.7 MONTHLYDATE Trigger 

285class MONTHLYDATE(Structure): 

286 structure = ( 

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

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

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

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

291 ) 

292 

293# 2.4.2.11.8 MONTHLYDOW Trigger 

294class MONTHLYDOW(Structure): 

295 structure = ( 

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

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

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

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

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

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

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

303 ) 

304 

305# 2.4.2.12 Job Signature 

306class JOB_SIGNATURE(Structure): 

307 structure = ( 

308 ('SignatureVersion','<HH0'), 

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

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

311 ) 

312 

313################################################################################ 

314# RPC CALLS 

315################################################################################ 

316# 3.2.5.4.1 SchRpcHighestVersion (Opnum 0) 

317class SchRpcHighestVersion(NDRCALL): 

318 opnum = 0 

319 structure = ( 

320 ) 

321 

322class SchRpcHighestVersionResponse(NDRCALL): 

323 structure = ( 

324 ('pVersion', DWORD), 

325 ('ErrorCode',ULONG), 

326 ) 

327 

328# 3.2.5.4.2 SchRpcRegisterTask (Opnum 1) 

329class SchRpcRegisterTask(NDRCALL): 

330 opnum = 1 

331 structure = ( 

332 ('path', LPWSTR), 

333 ('xml', WSTR), 

334 ('flags', DWORD), 

335 ('sddl', LPWSTR), 

336 ('logonType', DWORD), 

337 ('cCreds', DWORD), 

338 ('pCreds', LPTASK_USER_CRED_ARRAY), 

339 ) 

340 

341class SchRpcRegisterTaskResponse(NDRCALL): 

342 structure = ( 

343 ('pActualPath', LPWSTR), 

344 ('pErrorInfo', PTASK_XML_ERROR_INFO), 

345 ('ErrorCode',ULONG), 

346 ) 

347 

348# 3.2.5.4.3 SchRpcRetrieveTask (Opnum 2) 

349class SchRpcRetrieveTask(NDRCALL): 

350 opnum = 2 

351 structure = ( 

352 ('path', WSTR), 

353 ('lpcwszLanguagesBuffer', WSTR), 

354 ('pulNumLanguages', DWORD), 

355 ) 

356 

357class SchRpcRetrieveTaskResponse(NDRCALL): 

358 structure = ( 

359 ('pXml', LPWSTR), 

360 ('ErrorCode',ULONG), 

361 ) 

362 

363# 3.2.5.4.4 SchRpcCreateFolder (Opnum 3) 

364class SchRpcCreateFolder(NDRCALL): 

365 opnum = 3 

366 structure = ( 

367 ('path', WSTR), 

368 ('sddl', LPWSTR), 

369 ('flags', DWORD), 

370 ) 

371 

372class SchRpcCreateFolderResponse(NDRCALL): 

373 structure = ( 

374 ('ErrorCode',ULONG), 

375 ) 

376 

377# 3.2.5.4.5 SchRpcSetSecurity (Opnum 4) 

378class SchRpcSetSecurity(NDRCALL): 

379 opnum = 4 

380 structure = ( 

381 ('path', WSTR), 

382 ('sddl', WSTR), 

383 ('flags', DWORD), 

384 ) 

385 

386class SchRpcSetSecurityResponse(NDRCALL): 

387 structure = ( 

388 ('ErrorCode',ULONG), 

389 ) 

390 

391# 3.2.5.4.6 SchRpcGetSecurity (Opnum 5) 

392class SchRpcGetSecurity(NDRCALL): 

393 opnum = 5 

394 structure = ( 

395 ('path', WSTR), 

396 ('securityInformation', DWORD), 

397 ) 

398 

399class SchRpcGetSecurityResponse(NDRCALL): 

400 structure = ( 

401 ('sddl',LPWSTR), 

402 ('ErrorCode',ULONG), 

403 ) 

404 

405# 3.2.5.4.7 SchRpcEnumFolders (Opnum 6) 

406class SchRpcEnumFolders(NDRCALL): 

407 opnum = 6 

408 structure = ( 

409 ('path', WSTR), 

410 ('flags', DWORD), 

411 ('startIndex', DWORD), 

412 ('cRequested', DWORD), 

413 ) 

414 

415class SchRpcEnumFoldersResponse(NDRCALL): 

416 structure = ( 

417 ('startIndex', DWORD), 

418 ('pcNames', DWORD), 

419 ('pNames', PTASK_NAMES_ARRAY), 

420 ('ErrorCode',ULONG), 

421 ) 

422 

423# 3.2.5.4.8 SchRpcEnumTasks (Opnum 7) 

424class SchRpcEnumTasks(NDRCALL): 

425 opnum = 7 

426 structure = ( 

427 ('path', WSTR), 

428 ('flags', DWORD), 

429 ('startIndex', DWORD), 

430 ('cRequested', DWORD), 

431 ) 

432 

433class SchRpcEnumTasksResponse(NDRCALL): 

434 structure = ( 

435 ('startIndex', DWORD), 

436 ('pcNames', DWORD), 

437 ('pNames', PTASK_NAMES_ARRAY), 

438 ('ErrorCode',ULONG), 

439 ) 

440 

441# 3.2.5.4.9 SchRpcEnumInstances (Opnum 8) 

442class SchRpcEnumInstances(NDRCALL): 

443 opnum = 8 

444 structure = ( 

445 ('path', LPWSTR), 

446 ('flags', DWORD), 

447 ) 

448 

449class SchRpcEnumInstancesResponse(NDRCALL): 

450 structure = ( 

451 ('pcGuids', DWORD), 

452 ('pGuids', PGUID_ARRAY), 

453 ('ErrorCode',ULONG), 

454 ) 

455 

456# 3.2.5.4.10 SchRpcGetInstanceInfo (Opnum 9) 

457class SchRpcGetInstanceInfo(NDRCALL): 

458 opnum = 9 

459 structure = ( 

460 ('guid', GUID), 

461 ) 

462 

463class SchRpcGetInstanceInfoResponse(NDRCALL): 

464 structure = ( 

465 ('pPath', LPWSTR), 

466 ('pState', DWORD), 

467 ('pCurrentAction', LPWSTR), 

468 ('pInfo', LPWSTR), 

469 ('pcGroupInstances', DWORD), 

470 ('pGroupInstances', PGUID_ARRAY), 

471 ('pEnginePID', DWORD), 

472 ('ErrorCode',ULONG), 

473 ) 

474 

475# 3.2.5.4.11 SchRpcStopInstance (Opnum 10) 

476class SchRpcStopInstance(NDRCALL): 

477 opnum = 10 

478 structure = ( 

479 ('guid', GUID), 

480 ('flags', DWORD), 

481 ) 

482 

483class SchRpcStopInstanceResponse(NDRCALL): 

484 structure = ( 

485 ('ErrorCode',ULONG), 

486 ) 

487 

488# 3.2.5.4.12 SchRpcStop (Opnum 11) 

489class SchRpcStop(NDRCALL): 

490 opnum = 11 

491 structure = ( 

492 ('path', LPWSTR), 

493 ('flags', DWORD), 

494 ) 

495 

496class SchRpcStopResponse(NDRCALL): 

497 structure = ( 

498 ('ErrorCode',ULONG), 

499 ) 

500 

501# 3.2.5.4.13 SchRpcRun (Opnum 12) 

502class SchRpcRun(NDRCALL): 

503 opnum = 12 

504 structure = ( 

505 ('path', WSTR), 

506 ('cArgs', DWORD), 

507 ('pArgs', PWSTR_ARRAY), 

508 ('flags', DWORD), 

509 ('sessionId', DWORD), 

510 ('user', LPWSTR), 

511 ) 

512 

513class SchRpcRunResponse(NDRCALL): 

514 structure = ( 

515 ('pGuid', GUID), 

516 ('ErrorCode',ULONG), 

517 ) 

518 

519# 3.2.5.4.14 SchRpcDelete (Opnum 13) 

520class SchRpcDelete(NDRCALL): 

521 opnum = 13 

522 structure = ( 

523 ('path', WSTR), 

524 ('flags', DWORD), 

525 ) 

526 

527class SchRpcDeleteResponse(NDRCALL): 

528 structure = ( 

529 ('ErrorCode',ULONG), 

530 ) 

531 

532# 3.2.5.4.15 SchRpcRename (Opnum 14) 

533class SchRpcRename(NDRCALL): 

534 opnum = 14 

535 structure = ( 

536 ('path', WSTR), 

537 ('newName', WSTR), 

538 ('flags', DWORD), 

539 ) 

540 

541class SchRpcRenameResponse(NDRCALL): 

542 structure = ( 

543 ('ErrorCode',ULONG), 

544 ) 

545 

546# 3.2.5.4.16 SchRpcScheduledRuntimes (Opnum 15) 

547class SchRpcScheduledRuntimes(NDRCALL): 

548 opnum = 15 

549 structure = ( 

550 ('path', WSTR), 

551 ('start', PSYSTEMTIME), 

552 ('end', PSYSTEMTIME), 

553 ('flags', DWORD), 

554 ('cRequested', DWORD), 

555 ) 

556 

557class SchRpcScheduledRuntimesResponse(NDRCALL): 

558 structure = ( 

559 ('pcRuntimes',DWORD), 

560 ('pRuntimes',PSYSTEMTIME_ARRAY), 

561 ('ErrorCode',ULONG), 

562 ) 

563 

564# 3.2.5.4.17 SchRpcGetLastRunInfo (Opnum 16) 

565class SchRpcGetLastRunInfo(NDRCALL): 

566 opnum = 16 

567 structure = ( 

568 ('path', WSTR), 

569 ) 

570 

571class SchRpcGetLastRunInfoResponse(NDRCALL): 

572 structure = ( 

573 ('pLastRuntime',SYSTEMTIME), 

574 ('pLastReturnCode',DWORD), 

575 ('ErrorCode',ULONG), 

576 ) 

577 

578# 3.2.5.4.18 SchRpcGetTaskInfo (Opnum 17) 

579class SchRpcGetTaskInfo(NDRCALL): 

580 opnum = 17 

581 structure = ( 

582 ('path', WSTR), 

583 ('flags', DWORD), 

584 ) 

585 

586class SchRpcGetTaskInfoResponse(NDRCALL): 

587 structure = ( 

588 ('pEnabled',DWORD), 

589 ('pState',DWORD), 

590 ('ErrorCode',ULONG), 

591 ) 

592 

593# 3.2.5.4.19 SchRpcGetNumberOfMissedRuns (Opnum 18) 

594class SchRpcGetNumberOfMissedRuns(NDRCALL): 

595 opnum = 18 

596 structure = ( 

597 ('path', WSTR), 

598 ) 

599 

600class SchRpcGetNumberOfMissedRunsResponse(NDRCALL): 

601 structure = ( 

602 ('pNumberOfMissedRuns',DWORD), 

603 ('ErrorCode',ULONG), 

604 ) 

605 

606# 3.2.5.4.20 SchRpcEnableTask (Opnum 19) 

607class SchRpcEnableTask(NDRCALL): 

608 opnum = 19 

609 structure = ( 

610 ('path', WSTR), 

611 ('enabled', DWORD), 

612 ) 

613 

614class SchRpcEnableTaskResponse(NDRCALL): 

615 structure = ( 

616 ('ErrorCode',ULONG), 

617 ) 

618 

619################################################################################ 

620# OPNUMs and their corresponding structures 

621################################################################################ 

622OPNUMS = { 

623 0 : (SchRpcHighestVersion,SchRpcHighestVersionResponse ), 

624 1 : (SchRpcRegisterTask,SchRpcRegisterTaskResponse ), 

625 2 : (SchRpcRetrieveTask,SchRpcRetrieveTaskResponse ), 

626 3 : (SchRpcCreateFolder,SchRpcCreateFolderResponse ), 

627 4 : (SchRpcSetSecurity,SchRpcSetSecurityResponse ), 

628 5 : (SchRpcGetSecurity,SchRpcGetSecurityResponse ), 

629 6 : (SchRpcEnumFolders,SchRpcEnumFoldersResponse ), 

630 7 : (SchRpcEnumTasks,SchRpcEnumTasksResponse ), 

631 8 : (SchRpcEnumInstances,SchRpcEnumInstancesResponse ), 

632 9 : (SchRpcGetInstanceInfo,SchRpcGetInstanceInfoResponse ), 

633 10 : (SchRpcStopInstance,SchRpcStopInstanceResponse ), 

634 11 : (SchRpcStop,SchRpcStopResponse ), 

635 12 : (SchRpcRun,SchRpcRunResponse ), 

636 13 : (SchRpcDelete,SchRpcDeleteResponse ), 

637 14 : (SchRpcRename,SchRpcRenameResponse ), 

638 15 : (SchRpcScheduledRuntimes,SchRpcScheduledRuntimesResponse ), 

639 16 : (SchRpcGetLastRunInfo,SchRpcGetLastRunInfoResponse ), 

640 17 : (SchRpcGetTaskInfo,SchRpcGetTaskInfoResponse ), 

641 18 : (SchRpcGetNumberOfMissedRuns,SchRpcGetNumberOfMissedRunsResponse), 

642 19 : (SchRpcEnableTask,SchRpcEnableTaskResponse), 

643} 

644 

645################################################################################ 

646# HELPER FUNCTIONS 

647################################################################################ 

648def checkNullString(string): 

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

650 return string 

651 

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

653 return string + '\x00' 

654 else: 

655 return string 

656 

657def hSchRpcHighestVersion(dce): 

658 return dce.request(SchRpcHighestVersion()) 

659 

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

661 request = SchRpcRegisterTask() 

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

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

664 request['flags'] = flags 

665 request['sddl'] = sddl 

666 request['logonType'] = logonType 

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

668 if len(pCreds) == 0: 

669 request['pCreds'] = NULL 

670 else: 

671 for cred in pCreds: 

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

673 return dce.request(request) 

674 

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

676 schRpcRetrieveTask = SchRpcRetrieveTask() 

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

678 schRpcRetrieveTask['lpcwszLanguagesBuffer'] = lpcwszLanguagesBuffer 

679 schRpcRetrieveTask['pulNumLanguages'] = pulNumLanguages 

680 return dce.request(schRpcRetrieveTask) 

681 

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

683 schRpcCreateFolder = SchRpcCreateFolder() 

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

685 schRpcCreateFolder['sddl'] = sddl 

686 schRpcCreateFolder['flags'] = 0 

687 return dce.request(schRpcCreateFolder) 

688 

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

690 schRpcSetSecurity = SchRpcSetSecurity() 

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

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

693 schRpcSetSecurity['flags'] = flags 

694 return dce.request(schRpcSetSecurity) 

695 

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

697 schRpcGetSecurity = SchRpcGetSecurity() 

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

699 schRpcGetSecurity['securityInformation'] = securityInformation 

700 return dce.request(schRpcGetSecurity) 

701 

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

703 schRpcEnumFolders = SchRpcEnumFolders() 

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

705 schRpcEnumFolders['flags'] = flags 

706 schRpcEnumFolders['startIndex'] = startIndex 

707 schRpcEnumFolders['cRequested'] = cRequested 

708 return dce.request(schRpcEnumFolders) 

709 

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

711 schRpcEnumTasks = SchRpcEnumTasks() 

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

713 schRpcEnumTasks['flags'] = flags 

714 schRpcEnumTasks['startIndex'] = startIndex 

715 schRpcEnumTasks['cRequested'] = cRequested 

716 return dce.request(schRpcEnumTasks) 

717 

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

719 schRpcEnumInstances = SchRpcEnumInstances() 

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

721 schRpcEnumInstances['flags'] = flags 

722 return dce.request(schRpcEnumInstances) 

723 

724def hSchRpcGetInstanceInfo(dce, guid): 

725 schRpcGetInstanceInfo = SchRpcGetInstanceInfo() 

726 schRpcGetInstanceInfo['guid'] = guid 

727 return dce.request(schRpcGetInstanceInfo) 

728 

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

730 schRpcStopInstance = SchRpcStopInstance() 

731 schRpcStopInstance['guid'] = guid 

732 schRpcStopInstance['flags'] = flags 

733 return dce.request(schRpcStopInstance) 

734 

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

736 schRpcStop= SchRpcStop() 

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

738 schRpcStop['flags'] = flags 

739 return dce.request(schRpcStop) 

740 

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

742 schRpcRun = SchRpcRun() 

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

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

745 for arg in pArgs: 

746 argn = LPWSTR() 

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

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

749 schRpcRun['flags'] = flags 

750 schRpcRun['sessionId'] = sessionId 

751 schRpcRun['user'] = user 

752 return dce.request(schRpcRun) 

753 

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

755 schRpcDelete = SchRpcDelete() 

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

757 schRpcDelete['flags'] = flags 

758 return dce.request(schRpcDelete) 

759 

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

761 schRpcRename = SchRpcRename() 

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

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

764 schRpcRename['flags'] = flags 

765 return dce.request(schRpcRename) 

766 

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

768 schRpcScheduledRuntimes = SchRpcScheduledRuntimes() 

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

770 schRpcScheduledRuntimes['start'] = start 

771 schRpcScheduledRuntimes['end'] = end 

772 schRpcScheduledRuntimes['flags'] = flags 

773 schRpcScheduledRuntimes['cRequested'] = cRequested 

774 return dce.request(schRpcScheduledRuntimes) 

775 

776def hSchRpcGetLastRunInfo(dce, path): 

777 schRpcGetLastRunInfo = SchRpcGetLastRunInfo() 

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

779 return dce.request(schRpcGetLastRunInfo) 

780 

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

782 schRpcGetTaskInfo = SchRpcGetTaskInfo() 

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

784 schRpcGetTaskInfo['flags'] = flags 

785 return dce.request(schRpcGetTaskInfo) 

786 

787def hSchRpcGetNumberOfMissedRuns(dce, path): 

788 schRpcGetNumberOfMissedRuns = SchRpcGetNumberOfMissedRuns() 

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

790 return dce.request(schRpcGetNumberOfMissedRuns) 

791 

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

793 schRpcEnableTask = SchRpcEnableTask() 

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

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

796 schRpcEnableTask['enabled'] = 1 

797 else: 

798 schRpcEnableTask['enabled'] = 0 

799 return dce.request(schRpcEnableTask)