3 ms·
Here's how you'd exec: execv("/path/to/binary", (char *[]){"binary", NULL}); And here's a way to do that without exec: (((int (*)(int, char **))dlsym(dlo
by saagarjha 7y ago
Here's how you'd exec:
execv("/path/to/binary", (char *[]){"binary", NULL});
And here's a way to do that without exec:
(((int (*)(int, char **))dlsym(dlopen("/path/to/binary", RTLD_LAZY), "main")))(1, (char *[]){"binary", NULL});
A bit uglier, but not all that much harder.
- Rapzid 7y ago> dlopen Doesn't that just end up calling open() and mmap()? Might not have access to the args passed through at that point, but that's going to leave a trail and of course anything interesting the mapped program does will end up going through syscalls(opening other "files").
- saagarjha 7y agoTrying to get stuff into your memory that wasn't there before is going to require at least one syscall.
- cyphar 7y agoThough it should be noted that's not quite the same thing as execve. Execve does a lot of things in addition to running the main function (privilege transitions like setuid being just one example).
- saagarjha 7y agoOf course; in addition to kernel setup this will also skip over initializers in the binary and other things that the C runtime does before main. Needless to say, this is mostly only useful as a fun side effect of PIE executables.