(self, data, shell_type='cmd')
| 277 | os.unlink(SMBSERVER_DIR + '/' + OUTPUT_FILENAME) |
| 278 | |
| 279 | def execute_remote(self, data, shell_type='cmd'): |
| 280 | if shell_type == 'powershell': |
| 281 | data = '$ProgressPreference="SilentlyContinue";' + data |
| 282 | data = self.__pwsh + b64encode(data.encode('utf-16le')).decode() |
| 283 | |
| 284 | batchFile = '%SYSTEMROOT%\\' + ''.join([random.choice(string.ascii_letters) for _ in range(8)]) + '.bat' |
| 285 | |
| 286 | command = self.__shell + 'echo ' + data + ' ^> ' + self.__output + ' 2^>^&1 > ' + batchFile + ' & ' + \ |
| 287 | self.__shell + batchFile |
| 288 | |
| 289 | if self.__mode == 'SERVER': |
| 290 | command += ' & ' + self.__copyBack |
| 291 | command += ' & ' + 'del ' + batchFile |
| 292 | |
| 293 | logging.debug('Executing %s' % command) |
| 294 | resp = scmr.hRCreateServiceW(self.__scmr, self.__scHandle, self.__serviceName, self.__serviceName, |
| 295 | lpBinaryPathName=command, dwStartType=scmr.SERVICE_DEMAND_START) |
| 296 | service = resp['lpServiceHandle'] |
| 297 | |
| 298 | try: |
| 299 | scmr.hRStartServiceW(self.__scmr, service) |
| 300 | except: |
| 301 | pass |
| 302 | scmr.hRDeleteService(self.__scmr, service) |
| 303 | scmr.hRCloseServiceHandle(self.__scmr, service) |
| 304 | self.get_output() |
| 305 | |
| 306 | def send_data(self, data): |
| 307 | self.execute_remote(data, self.__shell_type) |
no test coverage detected