コード例 #1
0
    def test_install_searchsploit(self, test_input):
        tool = "searchsploit"
        tools_copy = tools.copy()

        home_path = f"{self.shell.tools_dir}/home"
        Path(home_path).mkdir(parents=True, exist_ok=True)

        copied_searchsploit_rc = f"{home_path}/.searchsploit_rc"

        dependency_path = f"{self.shell.tools_dir}/exploitdb"
        searchsploit_rc_path = f"{dependency_path}/.searchsploit_rc"
        tool_path = f"{dependency_path}/{tool}"

        sed_cmd = f"s#/opt#{self.shell.tools_dir}#g"

        if test_input == "update":
            subprocess.run(
                f"git clone https://github.com/offensive-security/exploitdb.git {dependency_path}"
                .split())

        tools_copy.get(tool)["path"] = tool_path

        first_cmd = "bash -c 'if [ -d /usr/share/exploitdb ]; then ln -fs "
        first_cmd += f"/usr/share/exploitdb {dependency_path} && ln -fs $(which searchsploit) {tool_path}"
        first_cmd += f"; elif [ -d {dependency_path} ]; then cd {dependency_path} && git fetch --all && git pull; else "
        first_cmd += f"git clone https://github.com/offensive-security/exploitdb.git {dependency_path}; fi'"

        tools_copy.get(tool).get("install_commands")[0] = first_cmd

        tools_copy.get(tool).get("install_commands")[
            1] = f"bash -c 'if [ -f {searchsploit_rc_path} ]; "
        tools_copy.get(tool).get("install_commands")[
            1] += f"then cp -n {searchsploit_rc_path} {home_path} ; fi'"

        tools_copy.get(tool).get("install_commands")[
            2] = f"bash -c 'if [ -f {copied_searchsploit_rc} ]; "
        tools_copy.get(tool).get("install_commands")[
            2] += f"then sed -i {sed_cmd} {copied_searchsploit_rc}; fi'"

        tools_copy.get(tool).get(
            "uninstall_commands")[0] = f"sudo rm -r {dependency_path}"

        pickle.dump(tools_copy,
                    Path(self.shell.tools_dir / ".tool-dict.pkl").open("wb"))

        if test_input == "install":
            assert not Path(tool_path).exists()
            assert not Path(copied_searchsploit_rc).exists()
            assert not Path(dependency_path).exists()

        utils.run_cmd(self.shell, f"tools install {tool}")
        assert subprocess.run(
            f"grep {self.shell.tools_dir} {copied_searchsploit_rc}".split(
            )).returncode == 0
        assert Path(copied_searchsploit_rc).exists()
        assert Path(dependency_path).exists()

        utils.run_cmd(self.shell, f"tools uninstall {tool}")
        assert Path(dependency_path).exists() is False
コード例 #2
0
    def perform_install(self, tools_dict, tool_name, exists=False):
        pickle.dump(tools_dict,
                    Path(self.shell.tools_dir / ".tool-dict.pkl").open("wb"))

        tool = Path(tools_dict.get(tool_name).get("path"))

        if exists is False:
            assert tool.exists() is False

        utils.run_cmd(self.shell, f"install {tool_name}")

        assert tool.exists() is True
コード例 #3
0
    def test_install_luigi_service(self):
        luigi_service = Path("/lib/systemd/system/luigid.service")

        self.pause_luigi()

        if luigi_service.exists():
            subprocess.run(f"sudo rm {luigi_service}".split())

        tools_copy = tools.copy()
        pickle.dump(tools_copy,
                    Path(self.shell.tools_dir / ".tool-dict.pkl").open("wb"))

        if Path("/usr/local/bin/luigid").exists():
            subprocess.run("sudo rm /usr/local/bin/luigid".split())

        assert (subprocess.run("systemctl is-enabled luigid.service".split(),
                               stdout=subprocess.PIPE).stdout.decode().strip()
                != "enabled")

        assert (subprocess.run("systemctl is-active luigid.service".split(),
                               stdout=subprocess.PIPE).stdout.decode().strip()
                != "active")

        assert not Path("/usr/local/bin/luigid").exists()

        utils.run_cmd(self.shell, "tools install luigi-service")

        assert Path("/lib/systemd/system/luigid.service").exists()

        proc = subprocess.run("systemctl is-enabled luigid.service".split(),
                              stdout=subprocess.PIPE)
        assert proc.stdout.decode().strip() == "enabled"

        proc = subprocess.run("systemctl is-active luigid.service".split(),
                              stdout=subprocess.PIPE)
        assert proc.stdout.decode().strip() == "active"

        assert Path("/usr/local/bin/luigid").exists()

        utils.run_cmd(self.shell, "tools uninstall luigi-service")

        proc = subprocess.run("systemctl is-enabled luigid.service".split(),
                              stdout=subprocess.PIPE)
        assert proc.stdout.decode().strip() != "enabled"

        proc = subprocess.run("systemctl is-active luigid.service".split(),
                              stdout=subprocess.PIPE)
        assert proc.stdout.decode().strip() != "active"

        assert luigi_service.exists() is False
コード例 #4
0
    def perform_add_remove(self, tools_dict, tool_name, install, exists):
        if install:
            pickle.dump(
                tools_dict,
                Path(self.shell.tools_dir / ".tool-dict.pkl").open("wb"))

        tool = Path(tools_dict.get(tool_name).get("path"))

        if install and exists is False:
            assert tool.exists() is False
        elif not install and exists is True:
            assert tool.exists() is True

        if install:
            utils.run_cmd(self.shell, f"tools install {tool_name}")
            assert tool.exists() is True
        else:
            utils.run_cmd(self.shell, f"tools uninstall {tool_name}")
            assert tool.exists() is False
コード例 #5
0
 def test_obs_scm_include(self):
     self.tar_scm_std('--include', self.fixtures.subdir, '--use-obs-scm', 'True')
     cpio    = os.path.join(self.outdir, self.basename()+'.obscpio')
     cmd = "cpio -it < "+cpio
     (stdout, stderr, ret) = run_cmd(cmd)
     got = stdout.decode().split("\n")
     got.pop()
     expected = [self.basename() + '/subdir',
                 self.basename() + '/subdir/b']
     self.assertTrue(got == expected)