Skip to content

Commit

Permalink
Disable progress output from PowerShell, and ignore unicode decode er…
Browse files Browse the repository at this point in the history
…rors
  • Loading branch information
sodle-splunk committed Dec 6, 2023
1 parent 2b6f219 commit e0fed49
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
8 changes: 5 additions & 3 deletions winrm_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def _run_ps(self, action_result, script, parse_callback=pc.basic, additional_dat
if len(resp.std_err):
resp.std_err = self._session._clean_error_msg(resp.std_err)
if isinstance(resp.std_err, bytes):
resp.std_err = resp.std_err.decode('UTF-8')
resp.std_err = resp.std_err.decode('UTF-8', errors='ignore')
elif async_:
encoded_ps = b64encode(script.encode('utf_16_le')).decode('ascii')
shell_id = self._protocol.open_shell()
Expand Down Expand Up @@ -850,6 +850,8 @@ def _handle_create_applocker_policy(self, param):
self._sanitize_string(file_path), new_policy_str, set_policy_str
))

self.debug_print(ps_script)

ret_val = self._run_ps(action_result, ps_script, parse_callback=pc.check_exit_no_data2)
if phantom.is_fail(ret_val):
return ret_val
Expand Down Expand Up @@ -971,7 +973,7 @@ def _handle_copy_file(self, param):
path_from = self._handle_py_ver_compat_for_input_str(param['from'])
path_to = self._handle_py_ver_compat_for_input_str(param['to'])

ps_script = "& copy {0} {1}".format(
ps_script = "$ProgressPreference = 'SilentlyContinue'; & copy {0} {1}".format(
self._sanitize_string(path_from),
self._sanitize_string(path_to)
)
Expand All @@ -990,7 +992,7 @@ def _handle_delete_file(self, param):
file_path = self._handle_py_ver_compat_for_input_str(param['file_path'])
force_delete = '-Force ' if param.get('force') else ''

ps_script = "& del {0}{1}".format(
ps_script = "$ProgressPreference = 'SilentlyContinue'; & del {0}{1}".format(
force_delete,
self._sanitize_string(file_path)
)
Expand Down
1 change: 1 addition & 0 deletions winrm_consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# either express or implied. See the License for the specific language governing permissions
# and limitations under the License.
APPLOCKER_BASE_SCRIPT = """
$ProgressPreference = 'SilentlyContinue'
Import-Module AppLocker
"""

Expand Down

0 comments on commit e0fed49

Please sign in to comment.