예제 #1
0
    def push(cmd_args):
        opts, args = getopt.getopt(
            cmd_args, "l:r:n:m",
            ["local-file=", "remote-path=", "remote-name=", "no-bak", "mod="])
        log.info("opts %s args:%s" % (opts, args))
        local_file, remote_path, remote_name = "", "", ""
        bak_file, chmod = True, "777"
        for op, value in opts:
            if op == "-l" or op == "--local-file":
                local_file = value
            elif op == "-r" or op == "--remote-path":
                remote_path = value
            elif op == "-n" or op == "--remote-name":
                remote_name = value
            elif op == "-n" or op == "--mod":
                chmod = value
            elif op == "--no-bak":
                bak_file = False
            else:
                log.error("unkown opt:%s value:%s" % (op, value))
                return False
        if len(opts) == 0:
            local_file = args[0] if len(args) >= 1 else ""
            remote_path = args[1] if len(args) >= 2 else ""
            remote_name = args[2] if len(args) >= 3 else ""

        if remote_path == "":
            remote_path = "/data/local/tmp"
        if os.path.isdir(local_file):
            # push 目录
            remote_file = remote_path + "/"
            util.mkdir(remote_file)
        elif os.path.isfile(os.path.join(os.getcwd(), local_file)):
            # push 文件
            # local_path = os.path.dirname(local_file)
            local_fname = os.path.basename(local_file)
            if remote_name == "":
                remote_name = local_fname
            remote_file = remote_path + "/" + remote_name
        else:
            log.error("local file:%s %s not exist" %
                      (local_file, os.path.join(os.getcwd(), local_file)))
            return False
        if bak_file:
            shell_cmd = util.getshell('mv "%s" "%s.bak"' %
                                      (remote_file, remote_file))
            util.execute_cmd(shell_cmd)
        log.info("local:%s remote:%s" % (local_file, remote_file))
        shell_cmd = util.getcmd('push "%s" "%s"' % (local_file, remote_file))
        ret, res_str = util.execute_cmd_with_stdout(shell_cmd)
        if not ret:
            return False
        if chmod != "":
            shell_cmd = util.getshell('chmod %s "%s"' % (chmod, remote_file))
            if not util.execute_cmd(shell_cmd): return False
            # shell_cmd = util.getshell('".%s"' % remote_file)
            # return util.execute_cmd(shell_cmd)
        return True
예제 #2
0
    def module(cmd_args):
        opts, args = getopt.getopt(cmd_args, "p:m:", ["process=", "module="])
        log.info("opts %s args:%s" % (opts, args))
        process_name, module_name = "", ""
        for op, value in opts:
            if op == "-p" or op == "--process":
                process_name = value
            elif op == "-m" or op == "--module":
                module_name = value
            else:
                log.error("unkown opt:%s value:%s" % (op, value))
                return False
        if len(opts) == 0:
            process_name = args[0] if len(args) >= 1 else ""
            module_name = args[1] if len(args) >= 2 else ""

        # 获取进程id
        process_id = util.get_process_id(process_name)
        if "" == process_id:
            log.error("get process:%s id fail" % process_name)
            return False
        # 获取模块信息
        if module_name != "":
            module_name = " | grep %s" % module_name
        shell_cmd = util.getshell("cat /proc/%s/maps%s" %
                                  (process_id, module_name))
        ret, res_str = util.execute_cmd_with_stdout(shell_cmd)
        if not ret:
            return False
        return True
예제 #3
0
 def upload_tools(abi, x86_arm):
     remote_path = Command.__remote_path + abi + "/"
     if not util.check_dir(remote_path):
         util.mkdir(remote_path)
     # 上传loader
     local_loader = os.path.join(Command.__tool_local_path, abi,
                                 Command.__loader_name)
     shell_cmd = util.getcmd('push "%s" "%s"' % (local_loader, remote_path))
     if not util.execute_cmd(shell_cmd):
         return False
     if x86_arm:
         # 上传 loader.so
         local_inject_so = os.path.join(Command.__tool_local_path, abi,
                                        Command.__client_fake_name)
         shell_cmd = util.getcmd('push "%s" "%s"' %
                                 (local_inject_so, remote_path))
         if not util.execute_cmd(shell_cmd):
             return False
         shell_cmd = util.getshell('chmod 777  "%s"/*' % remote_path)
         if not util.execute_cmd(shell_cmd):
             return False
         # 创建目录
         remote_path = Command.__remote_path + "armeabi-v7a" + "/"
         if not util.check_dir(remote_path):
             util.mkdir(remote_path)
         # 上传client
         local_client = os.path.join(Command.__tool_local_path,
                                     "armeabi-v7a",
                                     Command.__client_mod_name)
         shell_cmd = util.getcmd('push "%s" "%s"' %
                                 (local_client, remote_path))
         if not util.execute_cmd(shell_cmd):
             return False
     else:
         # 上传client
         local_client = os.path.join(Command.__tool_local_path, abi,
                                     Command.__client_mod_name)
         shell_cmd = util.getcmd('push "%s" "%s"' %
                                 (local_client, remote_path))
         if not util.execute_cmd(shell_cmd):
             return False
     shell_cmd = util.getshell('chmod 777  "%s"/*' % remote_path)
     if not util.execute_cmd(shell_cmd):
         return False
     return True
예제 #4
0
    def uninject_internal(pid, abi, x86_arm):
        remote_loader = Command.__remote_path + abi + "/" + Command.__loader_name
        remote_inject_so = Command.__remote_path + abi + "/" + Command.__client_mod_name
        if x86_arm:
            remote_inject_so = Command.__remote_path + abi + "/" + Command.__client_fake_name

        if not util.check_exist(remote_loader):
            log.error("check loader not exist")
            return False

        shell_cmd = '"%s" uninject --pid=%s --so="%s"' % (remote_loader, pid,
                                                          remote_inject_so)
        shell_cmd = util.getshell(shell_cmd)
        if not util.execute_cmd(shell_cmd):
            return False
        return True
예제 #5
0
    def inject_internal(pid, abi, init_script, need_push=False, x86_arm=False):
        remote_loader = Command.__remote_path + abi + "/" + Command.__loader_name
        remote_inject_so = Command.__remote_path + abi + "/" + Command.__client_mod_name
        if x86_arm:
            remote_inject_so = Command.__remote_path + abi + "/" + Command.__client_fake_name

        # 上传 初始化 script,检验脚本存不存在
        remote_script = Command.upload_script(init_script)

        # 上传各个模块
        if not util.check_exist(remote_loader) or need_push:
            Command.upload_tools(abi, x86_arm)

        shell_cmd = '"%s" inject --pid=%s --so="%s" --script=%s ' % (
            remote_loader, pid, remote_inject_so,
            '"%s"' % remote_script if "" != remote_script else "")
        shell_cmd = util.getshell(shell_cmd)
        if not util.execute_cmd(shell_cmd):
            return False
        return True
예제 #6
0
    def process(cmd_args):
        opts, args = getopt.getopt(cmd_args, "p:", ["process="])
        log.info("opts %s args:%s" % (opts, args))
        process_name = ""
        for op, value in opts:
            if op == "-p" or op == "--process":
                process_name = value
            else:
                log.error("unkown op:%s value:%s" % (op, value))
                return False
        if len(opts) == 0:
            process_name = args[0] if len(args) >= 1 else ""

        # 获取进程id
        process_id = util.get_process_id(process_name)
        if "" == process_id:
            log.error("get process:%s id fail" % process_name)
            return False
        # 查看 status
        shell_cmd = util.getshell("cat /proc/%s/status" % process_id)
        ret, res_str = util.execute_cmd_with_stdout(shell_cmd)
        if not ret:
            return False
        # 查看 cmdline
        shell_cmd = util.getshell("cat /proc/%s/cmdline" % process_id)
        ret, res_str = util.execute_cmd_with_stdout(shell_cmd)
        if not ret:
            return False
        # 查看 cmdline
        shell_cmd = util.getshell("cat /proc/%s/stat" % process_id)
        ret, res_str = util.execute_cmd_with_stdout(shell_cmd)
        if not ret:
            return False
        # 查看进程文件信息
        shell_cmd = util.getshell("ls -l /proc/%s/fd/" % process_id)
        ret, res_str = util.execute_cmd_with_stdout(shell_cmd)
        if not ret:
            return False
        # 查看进程的内存信息
        shell_cmd = util.getshell("cat /proc/%s/statm" % process_id)
        ret, res_str = util.execute_cmd_with_stdout(shell_cmd)
        if not ret:
            return False
        # 查看环境变量
        shell_cmd = util.getshell("cat /proc/%s/environ" % process_id)
        ret, res_str = util.execute_cmd_with_stdout(shell_cmd)
        if not ret:
            return False
        return True
예제 #7
0
    def dolua(cmd_args):
        opts, args = getopt.getopt(
            cmd_args, "p:s:f:",
            ["process=", "script=", "func=", "abi=", "x86-arm", "update"])
        log.info("opts %s args:%s" % (opts, args))
        process_name, abi, lua_script, func_name = "", "x86", "", ""
        need_upate, x86_arm, zygote = False, False, False
        for op, value in opts:
            if op == "-s" or op == "--script":
                lua_script = value
            elif op == "-f" or op == "--func":
                func_name = value
            elif op == "-p" or op == "--process":
                process_name = value
            elif op == "--abi":
                abi = value
            elif op == "--x86-arm":
                x86_arm = True
            elif op == "--update":
                need_upate = True
            else:
                log.error("unkown opt:%s value:%s" % (op, value))
                return False
        if len(opts) == 0:
            process_name = args[0] if len(args) >= 1 else ""
            lua_script = args[1] if len(args) >= 2 else ""
            func_name = args[2] if len(args) >= 3 else ""
            abi = args[3] if len(args) >= 4 else ""

        ret, process_id, remote_script, remote_loader, remote_inject_so = Command.lua_check(
            process_name, lua_script, zygote, abi, x86_arm, need_upate)
        if not ret:
            return False
        shell_cmd = '"%s" luacall --pid="%s" --so="%s" --script="%s" --func="%s" ' % \
            (remote_loader, process_id, remote_inject_so, remote_script, func_name)
        shell_cmd = util.getshell(shell_cmd)
        if not util.execute_cmd(shell_cmd):
            return False
        return True
예제 #8
0
 def shell(args):
     shell_cmd = util.getshell(args)
     log.info(shell_cmd)
     return util.execute_cmd(shell_cmd)