diff --git a/contents/winrm-exec.py b/contents/winrm-exec.py index 38602f1..f96650e 100644 --- a/contents/winrm-exec.py +++ b/contents/winrm-exec.py @@ -226,6 +226,7 @@ winrm.Session.run_cmd = winrm_session.run_cmd winrm.Session.run_ps = winrm_session.run_ps winrm.Session._clean_error_msg = winrm_session._clean_error_msg +winrm.Session._strip_namespace = winrm_session._strip_namespace tsk = winrm_session.RunCommand(session, shell, exec_command) t = threading.Thread(target=tsk.get_response) diff --git a/contents/winrm_session.py b/contents/winrm_session.py index 0af3a7e..e0e8d7d 100644 --- a/contents/winrm_session.py +++ b/contents/winrm_session.py @@ -18,6 +18,7 @@ import base64 import sys import types +import re PY2 = sys.version_info[0] == 2 PY3 = sys.version_info[0] == 3 @@ -101,6 +102,14 @@ def _clean_error_msg(self, msg): return msg +def _strip_namespace(self, xml): + """strips any namespaces from an xml string""" + value = to_bytes(xml) + p = re.compile(b"xmlns=*[\"\"][^\"\"]*[\"\"]") + allmatches = p.finditer(value) + for match in allmatches: + value = value.replace(match.group(), b"") + return value class Response(object): """Response from a remote command execution""" @@ -158,4 +167,5 @@ def to_bytes(obj, encoding='utf-8', errors="ignore"): # Try this first as it's the fastest return obj.encode(encoding, errors) except UnicodeEncodeError: - raise \ No newline at end of file + raise +