1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | # # Makefile # all: libs setresgid-tester # # Make a shared Library # libs: libfuncs.c gcc -shared -Wl,-soname,libfuncs.so.1 -o libfuncs.so.1.0 libfuncs.c ln -s libfuncs.so.1.0 libfuncs.so.1 ln -s libfuncs.so.1 libfuncs.so # # Here is a program that calls setresgid() for testing # setresgid-tester: setresgid-tester.c gcc -o setresgid-tester setresgid-tester.c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | /* Put all the functions you want to override here */ #include #include #include int errno; int setresgid(rgid, egid, sgid) gid_t rgid,egid,sgid; { errno=1; printf("It me the shim, Hi there!\n"); return(0); } |
1 2 3 4 5 6 7 8 | /* setresgid() system/library call tester */ #include #include main(){ setresgid(0,0,0); } |
1 2 3 4 | export LD_PRELOAD=libfuncs.so export LD_LIBRARY_PATH=.LD_LIBRARY_PATH ./setresgid-tester It's me the shim, Hi there! |
1 2 3 4 | [jay@prion ld_preload]$ ldd setresgid-tester libfuncs.so => libfuncs.so (0x40018000) libc.so.6 => /lib/libc.so.6 (0x40022000) /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000) |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |