Working Example

After knowing all you need to know, let’s give you a working example. This example is a framework payload:

my_payload/__init__.py:

"""
Add a payload to a user's home directory
"""
from snr.core.payload.payload import Context, Payload


class MyPayload(Payload):
    AUTHORS = ("GlobularOne",)
    TARGET_OS_LIST = ("GNU/Linux",)
    INPUT = (
        ("USERNAME", "", -1, "Username of the user to add the payload to their home directory"),
        Payload.supports_encrypted_access()
    )

    def generate(self, ctx: Context) -> int:
        variables = self.get_self_variables()
        self.format_payload_and_write(ctx, variables)
        self.add_autorun(ctx)
        return 0

payload = MyPayload()

my_payload/payload.py:

"""
My_payload Payload
"""
#!/usr/bin/python3
from snr.core.payload import entry_point, storage, context

USERNAME = "@USERNAME@"
PASSPHRASES = "@PASSPHRASES@"

@entry_point.entry_point
def main(block_info: list[storage.BlockInfo], root_ctx: contact.Context, our_device: str) -> None:
    for part in storage.query_all_partitions(block_info):
        with storage.mount_partition(part, PASSPHRASES) as mounted_part:
            if mounted_part.is_linux():
                mounted_part.copy("/root/payload.py", f"/home/{USERNAME}/payload.py")

See also

Partition Types

Read about how the partition type detection works and how you can use it.