diff --git a/provision.py b/provision.py index fa52359..e815758 100644 --- a/provision.py +++ b/provision.py @@ -58,6 +58,11 @@ def source_files() -> list[Path]: return files +def chmod_lines(target: str, spec: str, indent: str = "") -> list[str]: + # Grey Hack File.chmod accepts one class per call, e.g. "u+rwx", not "u+rwx,g+rx". + return [f'{indent}{target}.chmod("{part}")' for part in spec.split(",")] + + def install_binary_lines(var: str, bin_name: str) -> list[str]: return install_file_lines(var, f"/bin/{bin_name}", bin_name) @@ -68,7 +73,7 @@ def install_file_lines(var: str, path: str, name: str) -> list[str]: f'if not {var}_bin then exit("Failed to install {name}")', f'{var}_bin.set_group("root")', f'{var}_bin.set_owner("root")', - f'{var}_bin.chmod("u+rwx,g+rx,o+rx")', + *chmod_lines(f"{var}_bin", "u+rwx,g+rx,o+rx"), "", ] @@ -87,7 +92,7 @@ def downloaded_program_lines(name: str, destination: str) -> list[str]: f'\telse', f'\t\t{var}_bin.set_group("root")', f'\t\t{var}_bin.set_owner("root")', - f'\t\t{var}_bin.chmod("u+rwx,g+rx,o+rx")', + *chmod_lines(f"{var}_bin", "u+rwx,g+rx,o+rx", indent="\t\t"), f'\tend if', f'end if', "", @@ -105,9 +110,9 @@ def metaxploit_lines() -> list[str]: "\tif not metaxploit_guest then", '\t\tprint("Failed to copy metaxploit.so to guest")', "\telse", + *chmod_lines("metaxploit_guest", "u+rwx,g+rx,o+rx", indent="\t\t"), '\t\tmetaxploit_guest.set_group("guest")', '\t\tmetaxploit_guest.set_owner("guest")', - '\t\tmetaxploit_guest.chmod("u+rwx,g+rx,o+rx")', "\tend if", '\tmetaxploit_lib.move("/lib", "metaxploit.so")', '\tmetaxploit_lib = cp.File("/lib/metaxploit.so")', @@ -116,7 +121,7 @@ def metaxploit_lines() -> list[str]: "\telse", '\t\tmetaxploit_lib.set_group("root")', '\t\tmetaxploit_lib.set_owner("root")', - '\t\tmetaxploit_lib.chmod("u+rw,g+rw,o+rw")', + *chmod_lines("metaxploit_lib", "u+rw,g+rw,o+rw", indent="\t\t"), "\tend if", "end if", "", diff --git a/source/bbuild.src b/source/bbuild.src index ffca4f4..0189582 100644 --- a/source/bbuild.src +++ b/source/bbuild.src @@ -31,6 +31,8 @@ else guest_file = cp.File(current_path + "/" + bin_name) end if guest_file.move "/home/" + active_user + "/guest/", bin_name -guest_file.chmod "u+rwx,g+rwx,o+rwx" +guest_file.chmod "u+rwx" +guest_file.chmod "g+rwx" +guest_file.chmod "o+rwx" guest_file.set_group "guest" guest_file.set_owner "guest"