diff --git a/pupy/modules/shell_exec.py b/pupy/modules/shell_exec.py index cb5d6480..569beb4d 100644 --- a/pupy/modules/shell_exec.py +++ b/pupy/modules/shell_exec.py @@ -10,11 +10,19 @@ class ShellExec(PupyModule): """ execute shell commands on a remote system """ def init_argparse(self): self.arg_parser = PupyArgumentParser(prog='shell_exec', description=self.__doc__) + self.arg_parser.add_argument('-s', '--shell', help="default to /bin/sh on linux or cmd.exe on windows") self.arg_parser.add_argument('argument') def run(self, args): res="" try: - res=self.client.conn.modules.subprocess.check_output(args.argument, stderr=subprocess.PIPE, stdin=subprocess.PIPE, shell=True, universal_newlines=True) + if self.client.is_android(): + if args.shell is None: + args.shell="/system/bin/sh" + if args.shell is None: + res=self.client.conn.modules.subprocess.check_output(args.argument, stderr=subprocess.PIPE, stdin=subprocess.PIPE, shell=True, universal_newlines=True) + else: + command=[args.shell, '-c'] + args.argument.split() + res=self.client.conn.modules.subprocess.check_output(command, stderr=subprocess.PIPE, stdin=subprocess.PIPE, universal_newlines=True) except Exception as e: if hasattr(e,'output') and e.output: res=e.output