Skip to content

Instantly share code, notes, and snippets.

@0xef967c36 0xef967c36/pexec.c
Last active Jan 6, 2019

Embed
What would you like to do?
exec binary or shebanged script from a pipe in Linux by using memfd_create
#define _GNU_SOURCE
#include <unistd.h>
#include <fcntl.h>
#include <sys/syscall.h>
#include <err.h>
int main(int ac, char **av){
int fd; ssize_t l; char *dav[] = { "pexec", "run-by-pexec", 0 };
if(ac < 2) av = dav;
if((fd = syscall(SYS_memfd_create, av[0], 0)) == -1)
err(1, "memfd_create");
while((l = splice(0, 0, fd, 0, 65536, 0)) > 0);
if(l < 0) err(1, "splice");
fexecve(fd, av + 1, environ);
err(1, "fexecve");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.