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# 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# 

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

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

26from impacket.structure import Structure 

27from impacket import hresult_errors, system_errors 

28from impacket.uuid import uuidtup_to_bin 

29from impacket.dcerpc.v5.rpcrt import DCERPCException 

30 

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

32 

33class 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 

54CNLEN = 15 

55DNLEN = CNLEN 

56UNLEN = 256 

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

58 

59# 2.3.7 Flags 

60TASK_FLAG_INTERACTIVE = 0x1 

61TASK_FLAG_DELETE_WHEN_DONE = 0x2 

62TASK_FLAG_DISABLED = 0x4 

63TASK_FLAG_START_ONLY_IF_IDLE = 0x10 

64TASK_FLAG_KILL_ON_IDLE_END = 0x20 

65TASK_FLAG_DONT_START_IF_ON_BATTERIES = 0x40 

66TASK_FLAG_KILL_IF_GOING_ON_BATTERIES = 0x80 

67TASK_FLAG_RUN_ONLY_IF_DOCKED = 0x100 

68TASK_FLAG_HIDDEN = 0x200 

69TASK_FLAG_RUN_IF_CONNECTED_TO_INTERNET = 0x400 

70TASK_FLAG_RESTART_ON_IDLE_RESUME = 0x800 

71TASK_FLAG_SYSTEM_REQUIRED = 0x1000 

72TASK_FLAG_RUN_ONLY_IF_LOGGED_ON = 0x2000 

73 

74# 2.3.9 TASK_LOGON_TYPE 

75TASK_LOGON_NONE = 0 

76TASK_LOGON_PASSWORD = 1 

77TASK_LOGON_S4U = 2 

78TASK_LOGON_INTERACTIVE_TOKEN = 3 

79TASK_LOGON_GROUP = 4 

80TASK_LOGON_SERVICE_ACCOUNT = 5 

81TASK_LOGON_INTERACTIVE_TOKEN_OR_PASSWORD = 6 

82 

83# 2.3.13 TASK_STATE 

84TASK_STATE_UNKNOWN = 0 

85TASK_STATE_DISABLED = 1 

86TASK_STATE_QUEUED = 2 

87TASK_STATE_READY = 3 

88TASK_STATE_RUNNING = 4 

89 

90# 2.4.1 FIXDLEN_DATA 

91SCHED_S_TASK_READY = 0x00041300 

92SCHED_S_TASK_RUNNING = 0x00041301 

93SCHED_S_TASK_NOT_SCHEDULED = 0x00041301 

94 

95# 2.4.2.11 Triggers 

96TASK_TRIGGER_FLAG_HAS_END_DATE = 0 

97TASK_TRIGGER_FLAG_KILL_AT_DURATION_END = 0 

98TASK_TRIGGER_FLAG_DISABLED = 0 

99 

100# ToDo: Change this to enums 

101ONCE = 0 

102DAILY = 1 

103WEEKLY = 2 

104MONTHLYDATE = 3 

105MONTHLYDOW = 4 

106EVENT_ON_IDLE = 5 

107EVENT_AT_SYSTEMSTART = 6 

108EVENT_AT_LOGON = 7 

109 

110SUNDAY = 0 

111MONDAY = 1 

112TUESDAY = 2 

113WEDNESDAY = 3 

114THURSDAY = 4 

115FRIDAY = 5 

116SATURDAY = 6 

117 

118JANUARY = 1 

119FEBRUARY = 2 

120MARCH = 3 

121APRIL = 4 

122MAY = 5 

123JUNE = 6 

124JULY = 7 

125AUGUST = 8 

126SEPTEMBER = 9 

127OCTOBER = 10 

128NOVEMBER = 11 

129DECEMBER = 12 

130 

131# 2.4.2.11.8 MONTHLYDOW Trigger 

132FIRST_WEEK = 1 

133SECOND_WEEK = 2 

134THIRD_WEEK = 3 

135FOURTH_WEEK = 4 

136LAST_WEEK = 5 

137 

138# 2.3.12 TASK_NAMES 

139TASK_NAMES = LPWSTR 

140 

141# 3.2.5.4.2 SchRpcRegisterTask (Opnum 1) 

142TASK_VALIDATE_ONLY = 1<<(31-31) 

143TASK_CREATE = 1<<(31-30) 

144TASK_UPDATE = 1<<(31-29) 

145TASK_DISABLE = 1<<(31-28) 

146TASK_DON_ADD_PRINCIPAL_ACE = 1<<(31-27) 

147TASK_IGNORE_REGISTRATION_TRIGGERS = 1<<(31-26) 

148 

149# 3.2.5.4.5 SchRpcSetSecurity (Opnum 4) 

150TASK_DONT_ADD_PRINCIPAL_ACE = 1<<(31-27) 

151SCH_FLAG_FOLDER = 1<<(31-2) 

152SCH_FLAG_TASK = 1<<(31-1) 

153 

154# 3.2.5.4.7 SchRpcEnumFolders (Opnum 6) 

155TASK_ENUM_HIDDEN = 1 

156 

157# 3.2.5.4.13 SchRpcRun (Opnum 12) 

158TASK_RUN_AS_SELF = 1<<(31-31) 

159TASK_RUN_IGNORE_CONSTRAINTS = 1<<(31-30) 

160TASK_RUN_USE_SESSION_ID = 1<<(31-29) 

161TASK_RUN_USER_SID = 1<<(31-28) 

162 

163# 3.2.5.4.18 SchRpcGetTaskInfo (Opnum 17) 

164SCH_FLAG_STATE = 1<<(31-3) 

165 

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

167# STRUCTURES 

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

169# 2.3.12 TASK_NAMES 

170class TASK_NAMES_ARRAY(NDRUniConformantArray): 

171 item = TASK_NAMES 

172 

173class PTASK_NAMES_ARRAY(NDRPOINTER): 

174 referent = ( 

175 ('Data',TASK_NAMES_ARRAY), 

176 ) 

177 

178class WSTR_ARRAY(NDRUniConformantArray): 

179 item = WSTR 

180 

181class PWSTR_ARRAY(NDRPOINTER): 

182 referent = ( 

183 ('Data',WSTR_ARRAY), 

184 ) 

185 

186class GUID_ARRAY(NDRUniConformantArray): 

187 item = GUID 

188 

189class PGUID_ARRAY(NDRPOINTER): 

190 referent = ( 

191 ('Data',GUID_ARRAY), 

192 ) 

193 

194# 3.2.5.4.13 SchRpcRun (Opnum 12) 

195class SYSTEMTIME_ARRAY(NDRUniConformantArray): 

196 item = SYSTEMTIME 

197 

198class PSYSTEMTIME_ARRAY(NDRPOINTER): 

199 referent = ( 

200 ('Data',SYSTEMTIME_ARRAY), 

201 ) 

202 

203# 2.3.8 TASK_USER_CRED 

204class TASK_USER_CRED(NDRSTRUCT): 

205 structure = ( 

206 ('userId',LPWSTR), 

207 ('password',LPWSTR), 

208 ('flags',DWORD), 

209 ) 

210 

211class TASK_USER_CRED_ARRAY(NDRUniConformantArray): 

212 item = TASK_USER_CRED 

213 

214class LPTASK_USER_CRED_ARRAY(NDRPOINTER): 

215 referent = ( 

216 ('Data',TASK_USER_CRED_ARRAY), 

217 ) 

218 

219# 2.3.10 TASK_XML_ERROR_INFO 

220class TASK_XML_ERROR_INFO(NDRSTRUCT): 

221 structure = ( 

222 ('line',DWORD), 

223 ('column',DWORD), 

224 ('node',LPWSTR), 

225 ('value',LPWSTR), 

226 ) 

227 

228class PTASK_XML_ERROR_INFO(NDRPOINTER): 

229 referent = ( 

230 ('Data',TASK_XML_ERROR_INFO), 

231 ) 

232 

233# 2.4.1 FIXDLEN_DATA 

234class 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 

253class 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 

278class 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 

288class 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 

297class 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 

309class 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) 

320class SchRpcHighestVersion(NDRCALL): 

321 opnum = 0 

322 structure = ( 

323 ) 

324 

325class SchRpcHighestVersionResponse(NDRCALL): 

326 structure = ( 

327 ('pVersion', DWORD), 

328 ('ErrorCode',ULONG), 

329 ) 

330 

331# 3.2.5.4.2 SchRpcRegisterTask (Opnum 1) 

332class 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 

344class 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) 

352class SchRpcRetrieveTask(NDRCALL): 

353 opnum = 2 

354 structure = ( 

355 ('path', WSTR), 

356 ('lpcwszLanguagesBuffer', WSTR), 

357 ('pulNumLanguages', DWORD), 

358 ) 

359 

360class SchRpcRetrieveTaskResponse(NDRCALL): 

361 structure = ( 

362 ('pXml', LPWSTR), 

363 ('ErrorCode',ULONG), 

364 ) 

365 

366# 3.2.5.4.4 SchRpcCreateFolder (Opnum 3) 

367class SchRpcCreateFolder(NDRCALL): 

368 opnum = 3 

369 structure = ( 

370 ('path', WSTR), 

371 ('sddl', LPWSTR), 

372 ('flags', DWORD), 

373 ) 

374 

375class SchRpcCreateFolderResponse(NDRCALL): 

376 structure = ( 

377 ('ErrorCode',ULONG), 

378 ) 

379 

380# 3.2.5.4.5 SchRpcSetSecurity (Opnum 4) 

381class SchRpcSetSecurity(NDRCALL): 

382 opnum = 4 

383 structure = ( 

384 ('path', WSTR), 

385 ('sddl', WSTR), 

386 ('flags', DWORD), 

387 ) 

388 

389class SchRpcSetSecurityResponse(NDRCALL): 

390 structure = ( 

391 ('ErrorCode',ULONG), 

392 ) 

393 

394# 3.2.5.4.6 SchRpcGetSecurity (Opnum 5) 

395class SchRpcGetSecurity(NDRCALL): 

396 opnum = 5 

397 structure = ( 

398 ('path', WSTR), 

399 ('securityInformation', DWORD), 

400 ) 

401 

402class SchRpcGetSecurityResponse(NDRCALL): 

403 structure = ( 

404 ('sddl',LPWSTR), 

405 ('ErrorCode',ULONG), 

406 ) 

407 

408# 3.2.5.4.7 SchRpcEnumFolders (Opnum 6) 

409class SchRpcEnumFolders(NDRCALL): 

410 opnum = 6 

411 structure = ( 

412 ('path', WSTR), 

413 ('flags', DWORD), 

414 ('startIndex', DWORD), 

415 ('cRequested', DWORD), 

416 ) 

417 

418class 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) 

427class SchRpcEnumTasks(NDRCALL): 

428 opnum = 7 

429 structure = ( 

430 ('path', WSTR), 

431 ('flags', DWORD), 

432 ('startIndex', DWORD), 

433 ('cRequested', DWORD), 

434 ) 

435 

436class 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) 

445class SchRpcEnumInstances(NDRCALL): 

446 opnum = 8 

447 structure = ( 

448 ('path', LPWSTR), 

449 ('flags', DWORD), 

450 ) 

451 

452class 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) 

460class SchRpcGetInstanceInfo(NDRCALL): 

461 opnum = 9 

462 structure = ( 

463 ('guid', GUID), 

464 ) 

465 

466class 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) 

479class SchRpcStopInstance(NDRCALL): 

480 opnum = 10 

481 structure = ( 

482 ('guid', GUID), 

483 ('flags', DWORD), 

484 ) 

485 

486class SchRpcStopInstanceResponse(NDRCALL): 

487 structure = ( 

488 ('ErrorCode',ULONG), 

489 ) 

490 

491# 3.2.5.4.12 SchRpcStop (Opnum 11) 

492class SchRpcStop(NDRCALL): 

493 opnum = 11 

494 structure = ( 

495 ('path', LPWSTR), 

496 ('flags', DWORD), 

497 ) 

498 

499class SchRpcStopResponse(NDRCALL): 

500 structure = ( 

501 ('ErrorCode',ULONG), 

502 ) 

503 

504# 3.2.5.4.13 SchRpcRun (Opnum 12) 

505class 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 

516class SchRpcRunResponse(NDRCALL): 

517 structure = ( 

518 ('pGuid', GUID), 

519 ('ErrorCode',ULONG), 

520 ) 

521 

522# 3.2.5.4.14 SchRpcDelete (Opnum 13) 

523class SchRpcDelete(NDRCALL): 

524 opnum = 13 

525 structure = ( 

526 ('path', WSTR), 

527 ('flags', DWORD), 

528 ) 

529 

530class SchRpcDeleteResponse(NDRCALL): 

531 structure = ( 

532 ('ErrorCode',ULONG), 

533 ) 

534 

535# 3.2.5.4.15 SchRpcRename (Opnum 14) 

536class SchRpcRename(NDRCALL): 

537 opnum = 14 

538 structure = ( 

539 ('path', WSTR), 

540 ('newName', WSTR), 

541 ('flags', DWORD), 

542 ) 

543 

544class SchRpcRenameResponse(NDRCALL): 

545 structure = ( 

546 ('ErrorCode',ULONG), 

547 ) 

548 

549# 3.2.5.4.16 SchRpcScheduledRuntimes (Opnum 15) 

550class SchRpcScheduledRuntimes(NDRCALL): 

551 opnum = 15 

552 structure = ( 

553 ('path', WSTR), 

554 ('start', PSYSTEMTIME), 

555 ('end', PSYSTEMTIME), 

556 ('flags', DWORD), 

557 ('cRequested', DWORD), 

558 ) 

559 

560class 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) 

568class SchRpcGetLastRunInfo(NDRCALL): 

569 opnum = 16 

570 structure = ( 

571 ('path', WSTR), 

572 ) 

573 

574class SchRpcGetLastRunInfoResponse(NDRCALL): 

575 structure = ( 

576 ('pLastRuntime',SYSTEMTIME), 

577 ('pLastReturnCode',DWORD), 

578 ('ErrorCode',ULONG), 

579 ) 

580 

581# 3.2.5.4.18 SchRpcGetTaskInfo (Opnum 17) 

582class SchRpcGetTaskInfo(NDRCALL): 

583 opnum = 17 

584 structure = ( 

585 ('path', WSTR), 

586 ('flags', DWORD), 

587 ) 

588 

589class SchRpcGetTaskInfoResponse(NDRCALL): 

590 structure = ( 

591 ('pEnabled',DWORD), 

592 ('pState',DWORD), 

593 ('ErrorCode',ULONG), 

594 ) 

595 

596# 3.2.5.4.19 SchRpcGetNumberOfMissedRuns (Opnum 18) 

597class SchRpcGetNumberOfMissedRuns(NDRCALL): 

598 opnum = 18 

599 structure = ( 

600 ('path', WSTR), 

601 ) 

602 

603class SchRpcGetNumberOfMissedRunsResponse(NDRCALL): 

604 structure = ( 

605 ('pNumberOfMissedRuns',DWORD), 

606 ('ErrorCode',ULONG), 

607 ) 

608 

609# 3.2.5.4.20 SchRpcEnableTask (Opnum 19) 

610class SchRpcEnableTask(NDRCALL): 

611 opnum = 19 

612 structure = ( 

613 ('path', WSTR), 

614 ('enabled', DWORD), 

615 ) 

616 

617class SchRpcEnableTaskResponse(NDRCALL): 

618 structure = ( 

619 ('ErrorCode',ULONG), 

620 ) 

621 

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

623# OPNUMs and their corresponding structures 

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

625OPNUMS = { 

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################################################################################ 

651def 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 

660def hSchRpcHighestVersion(dce): 

661 return dce.request(SchRpcHighestVersion()) 

662 

663def 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 

678def 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 

685def 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 

692def 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 

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

700 schRpcGetSecurity = SchRpcGetSecurity() 

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

702 schRpcGetSecurity['securityInformation'] = securityInformation 

703 return dce.request(schRpcGetSecurity) 

704 

705def 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 

713def 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 

721def 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 

727def hSchRpcGetInstanceInfo(dce, guid): 

728 schRpcGetInstanceInfo = SchRpcGetInstanceInfo() 

729 schRpcGetInstanceInfo['guid'] = guid 

730 return dce.request(schRpcGetInstanceInfo) 

731 

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

733 schRpcStopInstance = SchRpcStopInstance() 

734 schRpcStopInstance['guid'] = guid 

735 schRpcStopInstance['flags'] = flags 

736 return dce.request(schRpcStopInstance) 

737 

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

739 schRpcStop= SchRpcStop() 

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

741 schRpcStop['flags'] = flags 

742 return dce.request(schRpcStop) 

743 

744def 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 

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

758 schRpcDelete = SchRpcDelete() 

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

760 schRpcDelete['flags'] = flags 

761 return dce.request(schRpcDelete) 

762 

763def 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 

770def 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 

779def hSchRpcGetLastRunInfo(dce, path): 

780 schRpcGetLastRunInfo = SchRpcGetLastRunInfo() 

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

782 return dce.request(schRpcGetLastRunInfo) 

783 

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

785 schRpcGetTaskInfo = SchRpcGetTaskInfo() 

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

787 schRpcGetTaskInfo['flags'] = flags 

788 return dce.request(schRpcGetTaskInfo) 

789 

790def hSchRpcGetNumberOfMissedRuns(dce, path): 

791 schRpcGetNumberOfMissedRuns = SchRpcGetNumberOfMissedRuns() 

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

793 return dce.request(schRpcGetNumberOfMissedRuns) 

794 

795def 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)