From dc9ac3603eeb33ea49b08f239a26c306a4ee4415 Mon Sep 17 00:00:00 2001 From: Nicole Valenzuela Date: Mon, 21 Dec 2020 10:03:07 -0300 Subject: [PATCH] FIX: added a new function to replace the simple quotes when execute CMD command #68 --- contents/common.py | 8 ++++++++ contents/winrm-exec.py | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/contents/common.py b/contents/common.py index ae69859..b0e7d7e 100644 --- a/contents/common.py +++ b/contents/common.py @@ -25,3 +25,11 @@ def get_file(destination): return filename + +def replace_single_quotes_format(command): + command = command + " " + command = re.sub(r'\s(\')',' \"', command) + command = re.sub(r'(\')\s','\" ', command) + command = re.sub(r'\'("\'")\'', "\'", command) + + return command diff --git a/contents/winrm-exec.py b/contents/winrm-exec.py index 480767c..f871894 100644 --- a/contents/winrm-exec.py +++ b/contents/winrm-exec.py @@ -10,6 +10,7 @@ import logging import colored_formatter import kerberosauth +import common from colored_formatter import ColoredFormatter @@ -157,7 +158,10 @@ def filter(self, record): if "RD_CONFIG_OPERATIONTIMEOUT" in os.environ: operationtimeout = os.getenv("RD_CONFIG_OPERATIONTIMEOUT") -exec_command = os.getenv("RD_EXEC_COMMAND") +exec_command = os.getenv("RD_EXEC_COMMAND") + +if "cmd" in shell: + exec_command = common.replace_single_quotes_format(exec_command) endpoint=transport+'://'+args.hostname+':'+port