Skip to content

EPERM when deleting the stage2 file when launched with sudo #7

@vfsfitvnm

Description

@vfsfitvnm

For obvious reasons, the stage2*.bin file will be created as root when launching the script with sudo. In this case, the shellcode (that will run as non privileged user) won't be able to delete the stage2*.bin file (EPERM).

I guess that the file should be chowned so the owner becomes the non-root user.

A quick fix is adding this snippet as soon as the file is created.

if os.getuid() == 0:
    uid = int(os.environ.get("SUDO_UID"))
    guid = int(os.environ.get("SUDO_GID"))
    os.chown(stage2_path, uid, guid)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions