|
2 | 2 | from traceback import format_exc |
3 | 3 | from nxc.protocols.smb.atexec import TSCH_EXEC |
4 | 4 |
|
5 | | - |
6 | 5 | class NXCModule: |
7 | 6 | """ |
8 | 7 | Execute a scheduled task remotely as a already connected user by @Defte_ |
@@ -69,17 +68,16 @@ def on_admin_login(self, context, connection): |
69 | 68 | return 1 |
70 | 69 | else: |
71 | 70 | self.logger.display(f"Uploading {self.binary_to_upload}") |
| 71 | + binary_file_location = self.tmp_share if self.output_file_location is None else self.output_file_location |
72 | 72 | with open(self.binary_to_upload, "rb") as binary_to_upload: |
73 | 73 | try: |
74 | 74 | self.binary_to_upload_name = os.path.basename(self.binary_to_upload) |
75 | | - connection.conn.putFile(self.share, f"{self.tmp_share}{self.binary_to_upload_name}", binary_to_upload.read) |
76 | | - self.logger.success(f"Binary {self.binary_to_upload_name} successfully uploaded in {self.tmp_share}{self.binary_to_upload_name}") |
| 75 | + connection.conn.putFile(self.share, f"{binary_file_location}{self.binary_to_upload_name}", binary_to_upload.read) |
| 76 | + self.logger.success(f"Binary {self.binary_to_upload_name} successfully uploaded in {binary_file_location}{self.binary_to_upload_name}") |
77 | 77 | except Exception as e: |
78 | | - self.logger.fail(f"Error writing file to share {self.tmp_share}: {e}") |
| 78 | + self.logger.fail(f"Error writing file to share {binary_file_location}: {e}") |
79 | 79 | return 1 |
80 | 80 |
|
81 | | - # Returnes self.command_to_run or \Windows\temp\BinToExecute.exe depending if BINARY=BinToExecute.exe |
82 | | - self.command_to_run = self.command_to_run if not self.binary_to_upload else f"{self.tmp_share}{self.command_to_run}" |
83 | 81 | self.logger.display("Connecting to the remote Service control endpoint") |
84 | 82 | try: |
85 | 83 | exec_method = TSCH_EXEC( |
@@ -122,7 +120,9 @@ def on_admin_login(self, context, connection): |
122 | 120 | finally: |
123 | 121 | if self.binary_to_upload: |
124 | 122 | try: |
125 | | - connection.conn.deleteFile(self.share, f"{self.tmp_share}{self.binary_to_upload_name}") |
126 | | - context.log.success(f"Binary {self.binary_to_upload_name} successfully deleted") |
| 123 | + context.log.success("Sleeping for 10 seconds to let binary run") |
| 124 | + sleep(10) |
| 125 | + connection.conn.deleteFile(self.share, f"{binary_file_location}{self.binary_to_upload_name}") |
| 126 | + context.log.success(f"Binary {binary_file_location}{self.binary_to_upload_name} successfully deleted") |
127 | 127 | except Exception as e: |
128 | | - context.log.fail(f"Error deleting {self.binary_to_upload_name} on {self.share}: {e}") |
| 128 | + context.log.fail(f"Error deleting {binary_file_location}{self.binary_to_upload_name} on {self.share}: {e}") |
0 commit comments