Advertisement
tunz

defcon 2014 byhd hook

May 19th, 2014
440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.30 KB | None | 0 0
  1. // gcc -shared -ldl hook.c -o hook.so -fPIC -ldl
  2.  
  3. #define _GNU_SOURCE
  4. #include <stdio.h>
  5. #include<sys/types.h>
  6. #include <dlfcn.h>
  7.  
  8. void * memcpy ( void * destination, const void * source, size_t num ) {
  9.         static void (*memcpy_real)(void*, const void*, size_t) = NULL;
  10.         int i=0;
  11.  
  12.         if (__builtin_return_address(0) == 0x401c9e)
  13.         {
  14.                 //FILE *fp = fopen("scode", "w");
  15.                 fprintf(stdout, "Memcpy: ");
  16.  
  17.                 int length = num*2;
  18.  
  19.                 send(4, &length, 4, 0);
  20.  
  21.                 for (i=0; i<num; i++)
  22.                 {
  23.                         fprintf(stdout, "%02x ", *(char *)(source + i) & 0xFF);
  24.                         char buf[2];
  25.                         sprintf(buf, "%02x", *(char *)(source + i) & 0xFF);
  26.                         send(4, &buf, 2, 0);
  27.                 }
  28.                 //for (i=0; i<num; i++)
  29.                 //      fprintf(fp, "%c", *(char *)(source + i) & 0xFF);
  30.  
  31.                 //fclose(fp);
  32.  
  33.                 fprintf(stdout, "\n\n");
  34.                 //system("ndisasm scode");
  35.                 fprintf(stdout, "-------------------------------\n\n");
  36.         }
  37.  
  38.         if (!memcpy_real)
  39.                 memcpy_real = dlsym(RTLD_NEXT, "memcpy");
  40.  
  41.         memcpy_real(destination, source, num);
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement