#!/usr/bin/perl system "/bin/echo", "hello"; # or # system "/bin/echo hello"; # or # my $out = `/bin/echo hello`; #### /* fakesys.c */ #include /* for execvp */ #include /* for dlsym */ #include static int (*real_execvp)(const char *file, char *const argv[]); int execvp(const char *file, char *const argv[]) { char *msg; /* lookup original shared lib function */ real_execvp = dlsym(RTLD_NEXT, "execvp"); /* see dlsym(3) */ if ( (msg = dlerror() ) != NULL ) { fprintf(stderr, "dlopen of execvp() failed : %s\n", msg); } fprintf(stderr, "calling execvp(\"%s\", ...)\n", file); /* execute original lib function */ return real_execvp(file, argv); } #### $ gcc -D_GNU_SOURCE -fPIC -shared fakesys.c -o libfakesys.so #### $ LD_PRELOAD=./libfakesys.so perl ./685699.pl #### calling execvp("/bin/echo", ...) hello