Skip to content

Instantly share code, notes, and snippets.

@0xef967c36
0xef967c36 / solibs-test
Last active Apr 11, 2020
solibs with DT_RUNPATH example
View solibs-test
mkdir -p b a
echo 'void b(){ puts("b"); }' > b.c
cc -include stdio.h -shared b.c -o b/libb.so
echo 'int main(){ extern void b(); b(); }' > m.c
cc m.c -o m -Wl,-rpath=./b -L ./b -lb
./m
# => b
@0xef967c36
0xef967c36 / herestring.c
Last active Mar 26, 2019
simple wrapper which will execute a command with its stdin redirected from a string
View herestring.c
#define _GNU_SOURCE
#include <unistd.h>
#include <sys/syscall.h>
#include <string.h>
#include <err.h>
int main(int ac, char **av){
int fd; size_t len;
if(ac < 3) errx(1, "usage %s string cmd [args ...]", av[0]);
if((fd = syscall(SYS_memfd_create, av[0], 0)) == -1)
err(1, "memfd_create");
@0xef967c36
0xef967c36 / pexec.c
Last active Jan 6, 2019
exec binary or shebanged script from a pipe in Linux by using memfd_create
View pexec.c
#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");
You can’t perform that action at this time.