/etc/ld.so.preload
Milan Pikula - WWW
www na fornax.elf.stuba.sk
Pondělí Září 13 13:23:51 CEST 1999
On Mon, 13 Sep 1999, Marek Antozi wrote:
W>Chcel by som sa opýtať, ako sa používa %subject%, prípadne postačí aj
W>použitie pomocu nastavenia premennej prostredia.
1. spravi sa library, ktora definuje niektore symboly, ktore chceme
prekryt v originali.
2. cez LD_PRELOAD v enve alebo cez zmieneny subor sa povie dynamickemu
linkeru, ze sa ma pouzit.
Prave dnes som niekomu naprogramoval tento priklad:
www na fornax[78, 578]: ~$ cat test.c
#include <stdio.h>
#include <dlfcn.h>
#include <sys/types.h>
#include <sys/socket.h>
/*
NOTE from my man page:
The third argument of connect is in reality an int (and this is what BSD
4.* and libc4 and libc5 have). Some POSIX confusion resulted in the present
socklen_t. The draft standard has not been adopted yet, but glibc2
already follows it and also has socklen_t. See also accept(2).
*/
#define socklen_t int
static int (*real_connect)(int, const struct sockaddr *, socklen_t);
void _init()
{
real_connect = (int (*)(int, const struct sockaddr *, socklen_t))
(dlsym(RTLD_NEXT, "connect"));
}
void _fini()
{
}
int connect(int i1, const struct sockaddr * p1, socklen_t i2)
{
puts("connect ;)");
return real_connect(i1, p1, i2);
}
www na fornax[79, 579]: ~$ gcc -Wall -nostdlib -shared -o test.so test.c -ldl
www na fornax[85, 585]: ~$ LD_PRELOAD=./test.so telnet 0 2345
Trying 0.0.0.0...
connect
telnet: Unable to connect to remote host: Connection refused
www na fornax[86, 586]: ~$
Milan Pikula
--
Milan Pikula, WWW. Finger me for Geek Code.
http://fornax.elf.stuba.sk/~www, www na fornax.elf.stuba.sk
.. dajte mi pevnu linku a pohnem zemegulou ..
Další informace o konferenci Linux