Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- target="target \"test\""
- c_target=$(echo "$target" | sed 's/\"/\\\"/g')
- rm -rf "$target" 2>/dev/null
- rm -f cd1.iso cd2.iso hook.so dummy 2>/dev/null
- mkdir "$target"
- dd if=/dev/urandom of="$target/bigfile" bs=1M count=5 2>/dev/null
- for((i=0;i<10;i++)); do
- mkdir -p "$target/$i"
- dd if=/dev/urandom of="$target/$i/file" bs=1K count=1 2>/dev/null
- done
- function src() {
- cat <<EOF
- #define _GNU_SOURCE
- #include <dlfcn.h>
- #include <stdio.h>
- #include <stdlib.h>
- static const char target[] = "$c_target";
- EOF
- fopen ""
- fopen "64"
- }
- function fopen() {
- cat <<EOF
- FILE* fopen$1( const char * filename, const char * mode )
- {
- typedef FILE* (*t_fopen$1)(const char *, const char *);
- static t_fopen$1 r_fopen$1 = 0;
- if(!r_fopen$1) r_fopen$1 = (t_fopen$1)dlsym(RTLD_NEXT, "fopen$1");
- if(memcmp(target, filename, sizeof(target)-1)==0)
- return NULL;
- return r_fopen$1(filename, mode);
- }
- EOF
- }
- src >hook.c
- src | gcc -shared -fPIC -o hook.so -xc - -l dl
- genisoimage -r -J -o cd1.iso "$target"
- export LD_PRELOAD=$PWD/hook.so
- genisoimage -r -J -o cd2.iso "$target"
Advertisement
Add Comment
Please, Sign In to add comment