|
1 | 1 | import os |
2 | 2 | from time import sleep |
3 | | -from datetime import datetime |
| 3 | +from datetime import datetime, timedelta |
4 | 4 | from impacket.dcerpc.v5.dtypes import NULL |
5 | 5 | from impacket.dcerpc.v5 import tsch, transport |
6 | 6 | from nxc.helpers.misc import gen_random_string |
@@ -92,6 +92,8 @@ def on_admin_login(self, context, connection): |
92 | 92 | if "SCHED_S_TASK_HAS_NOT_RUN" in str(e): |
93 | 93 | self.logger.fail("Task was not run, seems like the specified user has no active session on the target") |
94 | 94 | exec_method.deleteartifact() |
| 95 | + else: |
| 96 | + self.logger.fail(f"Failed to execute command: {e}") |
95 | 97 |
|
96 | 98 | class TSCH_EXEC: |
97 | 99 | def __init__(self, target, share_name, username, password, domain, user, cmd, file, task, location, doKerberos=False, aesKey=None, remoteHost=None, kdcHost=None, hashes=None, logger=None, tries=None, share=None): |
@@ -163,24 +165,20 @@ def execute(self, command, output=False): |
163 | 165 | def output_callback(self, data): |
164 | 166 | self.__outputBuffer = data |
165 | 167 |
|
166 | | - def get_current_date(self): |
| 168 | + def get_end_boundary(self): |
167 | 169 | # Get current date and time |
168 | | - now = datetime.now() |
| 170 | + end_boundary = datetime.now() + timedelta(minutes=5) |
169 | 171 |
|
170 | 172 | # Format it to match the format in the XML: "YYYY-MM-DDTHH:MM:SS.ssssss" |
171 | | - return now.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3] |
| 173 | + return end_boundary.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3] |
172 | 174 |
|
173 | 175 | def gen_xml(self, command, fileless=False): |
174 | 176 | xml = f"""<?xml version="1.0" encoding="UTF-16"?> |
175 | 177 | <Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task"> |
176 | 178 | <Triggers> |
177 | | - <CalendarTrigger> |
178 | | - <StartBoundary>{self.get_current_date()}</StartBoundary> |
179 | | - <Enabled>true</Enabled> |
180 | | - <ScheduleByDay> |
181 | | - <DaysInterval>1</DaysInterval> |
182 | | - </ScheduleByDay> |
183 | | - </CalendarTrigger> |
| 179 | + <RegistrationTrigger> |
| 180 | + <EndBoundary>{self.get_end_boundary()}</EndBoundary> |
| 181 | + </RegistrationTrigger> |
184 | 182 | </Triggers> |
185 | 183 | <Principals> |
186 | 184 | <Principal id="LocalSystem"> |
|
0 commit comments