Guest User

Untitled

a guest
Oct 5th, 2014
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.11 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. target="target \"test\""
  4. c_target=$(echo "$target" | sed 's/\"/\\\"/g')
  5.  
  6. rm -rf "$target" 2>/dev/null
  7. rm -f cd1.iso cd2.iso hook.so dummy 2>/dev/null
  8.  
  9. mkdir "$target"
  10. dd if=/dev/urandom of="$target/bigfile" bs=1M count=5 2>/dev/null
  11. for((i=0;i<10;i++)); do
  12.   mkdir -p "$target/$i"
  13.   dd if=/dev/urandom of="$target/$i/file" bs=1K count=1 2>/dev/null
  14. done
  15.  
  16. function src() {
  17.   cat <<EOF
  18. #define _GNU_SOURCE
  19. #include <dlfcn.h>
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22.  
  23. static const char target[] = "$c_target";
  24.  
  25. EOF
  26.   fopen ""
  27.   fopen "64"
  28. }
  29. function fopen() {
  30.   cat <<EOF
  31. FILE* fopen$1( const char * filename, const char * mode )
  32. {
  33.   typedef FILE* (*t_fopen$1)(const char *, const char *);
  34.   static t_fopen$1 r_fopen$1 = 0;
  35.   if(!r_fopen$1) r_fopen$1 = (t_fopen$1)dlsym(RTLD_NEXT, "fopen$1");
  36.  
  37.   if(memcmp(target, filename, sizeof(target)-1)==0)
  38.     return NULL;
  39.  
  40.   return r_fopen$1(filename, mode);
  41. }
  42. EOF
  43. }
  44.  
  45. src >hook.c
  46. src | gcc -shared -fPIC -o hook.so -xc - -l dl
  47.  
  48. genisoimage -r -J -o cd1.iso "$target"
  49.  
  50. export LD_PRELOAD=$PWD/hook.so
  51. genisoimage -r -J -o cd2.iso "$target"
Advertisement
Add Comment
Please, Sign In to add comment