in cortado/rtas/linux_persistence_dpkg_netcon.py [0:0]
def main() -> None:
# Ensure the /var/lib/dpkg/info/ directory exists
dpkg_info_dir = "/var/lib/dpkg/info/"
if not Path(dpkg_info_dir).exists():
log.info(f"Creating directory {dpkg_info_dir}")
Path(dpkg_info_dir).mkdir(parents=True, exist_ok=True)
# Path for the fake DPKG package executable
masquerade = str(Path(dpkg_info_dir) / "rta")
source = _common.get_resource_path("bin/netcon_exec_chain.elf")
log.info("Creating a fake DPKG package..")
_common.copy_file(source, masquerade)
log.info("Granting execute permissions...")
_ = _common.execute_command(["chmod", "+x", masquerade])
# Execute the fake DPKG package
log.info("Executing the fake DPKG package..")
commands = [
masquerade,
"chain",
"-h",
"8.8.8.8",
"-p",
"53",
"-c",
"/var/lib/dpkg/info/rta netcon -h 8.8.8.8 -p 53",
]
_ = _common.execute_command(commands, timeout_secs=5)
# Cleanup
_common.remove_file(masquerade)