SHARE
TWEET

defcon 2014 byhd hook

tunz May 19th, 2014 242 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top