Created
August 14, 2023 09:20
-
-
Save s0me0ne-unkn0wn/867613e55bce2db2f12c90c53ae904e5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define _GNU_SOURCE | |
#include <unistd.h> | |
#include <stdlib.h> | |
#include <sys/mman.h> | |
#include <fcntl.h> | |
int main(int argc, char **argv) { | |
int fd; | |
if((fd = open("/bin/ls", O_RDONLY)) == -1) exit(1); | |
off_t len = lseek(fd, 0, SEEK_END); | |
lseek(fd, 0, SEEK_SET); | |
unsigned char *buf = malloc(len); | |
read(fd, buf, len); | |
close(fd); | |
int memfd; | |
if((memfd = memfd_create("memls", MFD_CLOEXEC)) == -1) exit(2); | |
write(memfd, buf, len); | |
char *args[] = {"ls", "/", NULL}; | |
char *env[] = {NULL}; | |
fexecve(memfd, args, env); | |
exit(3); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment