Xhack
Vuoi reagire a questo messaggio? Crea un account in pochi click o accedi per continuare.
Xhack

Un forum dedicato all'hacking
 
IndiceIndice  PortalePortale  CercaCerca  Ultime immaginiUltime immagini  RegistratiRegistrati  Accedi  

 

 [C] Problemi con request_irq

Andare in basso 
AutoreMessaggio
BlackLight
Moderatore
Moderatore
BlackLight


Numero di messaggi : 277
Età : 37
Data d'iscrizione : 22.08.07

[C] Problemi con request_irq Empty
MessaggioTitolo: [C] Problemi con request_irq   [C] Problemi con request_irq EmptyDom Nov 11, 2007 12:39 pm

Sto scrivendo un piccolo keylogger in ambiente Unix che sfrutta le primitive a basso livello del kernel. In sostanza installo nell'applicazione un gestore di interrupt abbinato alla tastiera. La funzione che viene richiamata in caso di interrupt prende il contenuto del registro di dati della tastiera all'indirizzo 0x60 e me lo stampa su stdout, per ora. In pratica così dovrei avere un codice che ogni volta che la tastiera richiede un interrupt al sistema operativo richiama la funzione in questione e stampa il carattere letto. Il codice è il seguente:

Codice:
#include <stdio.h>
#include <unistd.h>
#include <asm/io.h>
#include <asm/irq.h>
#include <linux/sched.h>

#define KBD_DATA_REG    0x60
#define KBD_STATUS_REG  0x64

main()  {
        if (ioperm(KBD_DATA_REG,4,1)<0)
                exit(1);

        request_irq (1,irq_handle,0,"my_kbd",NULL);
}

void irq_handle()  {
        int n;

        n=inb(KBD_DATA_REG);
        printf ("%c",n);
}

Il problema arriva quando provo a compilare:

Codice:
In file included from /usr/include/linux/sched.h:14,
                from key.c:5:
/usr/include/linux/timex.h:174: error: field `time' has incomplete type
In file included from /usr/include/linux/sched.h:21,
                from key.c:5:
/usr/include/asm/mmu.h:12: error: field `sem' has incomplete type
In file included from /usr/include/linux/signal.h:5,
                from /usr/include/linux/sched.h:26,
                from key.c:5:
/usr/include/asm/siginfo.h:26: error: syntax error before "pid_t"
/usr/include/asm/siginfo.h:38: error: syntax error before "pid_t"
/usr/include/asm/siginfo.h:41: error: syntax error before '}' token
/usr/include/asm/siginfo.h:45: error: syntax error before "pid_t"
/usr/include/asm/siginfo.h:50: error: syntax error before '}' token
/usr/include/asm/siginfo.h:62: error: syntax error before '}' token
/usr/include/asm/siginfo.h:63: error: syntax error before '}' token
In file included from /usr/include/linux/sched.h:80,
                from key.c:5:
/usr/include/linux/time.h:9: error: redefinition of `struct timespec'
/usr/include/linux/time.h:90: error: syntax error before "suseconds_t"
/usr/include/linux/time.h:119: error: redefinition of `struct itimerspec'
/usr/include/linux/time.h:125: error: field `it_interval' has incomplete type
/usr/include/linux/time.h:126: error: field `it_value' has incomplete type
In file included from /usr/include/linux/sched.h:82,
                from key.c:5:
/usr/include/linux/resource.h:22: error: field `ru_utime' has incomplete type
/usr/include/linux/resource.h:23: error: field `ru_stime' has incomplete type
key.c: In function `main':
key.c:14: error: `irq_handle' undeclared (first use in this function)
key.c:14: error: (Each undeclared identifier is reported only once
key.c:14: error: for each function it appears in.)

Pare che il file di header in linux/sched.h abbia qualcosa che non gli sta molto simpatico...ho provato su due sistemi diversi con due kernel diversi e ottengo lo stesso errore, e in rete non ho trovato molto (anzi nemmeno sulla newsletter di Linux mi hanno saputo rispondere, e altra gente che ha postato questo stesso problema in rete non ha avuto grosse risposte). Qualcuno sa come rimediare?
Torna in alto Andare in basso
http://blacklight.gotdns.org
BlackLight
Moderatore
Moderatore
BlackLight


Numero di messaggi : 277
Età : 37
Data d'iscrizione : 22.08.07

[C] Problemi con request_irq Empty
MessaggioTitolo: Re: [C] Problemi con request_irq   [C] Problemi con request_irq EmptyMar Nov 13, 2007 1:26 am

Credo di avere praticamente risolto...ho postato questo problema su vari forum e perfino sulla newsletter ufficiale di linux.org ma nessuna risposta. Ho allora scritto a Linus Torvalds, dato che la problematica riguardava gli header del kernel. Posto qui la sua risposta:

Linus Torvalds ha scritto:
The kernel isn't a library. You can't call any kernel functions directly,
since there are security walls in place both in hardware and software to
make sure you cannot do that.

In fact, what you are trying to do with an interrupt handler can
fundamentally not work, since interrupt handlers need to be always
accessible, which means that they cannot be in a user process.

So to use kernel functions, you need to use the system calls, or load a
real kernel module.

If you can make do with *just* the IO port accesses, those work with the
ioperm() system call and the x86 support for doing controlled IO accesses
in user space. But that's a specific hardware feature, and is an example
of the kernel exposing some system calls to make that hardware feature
available.

Linus

In pratica, non posso usare funzioni come request_irq() al di fuori del kernel space come se il kernel fosse una normale libreria, per motivi di sicurezza implementati nel kernel stesso. La soluzione che sto provando a implementare ora è quella di scrivermi da me una funzione come request_irq(), che fa richieste in polling al pic 8259 e controlla se l'IRQ ivi presente è quello della tastiera (0x01). In quel caso vado a leggere tramite inb() il valore presente all'interno del registro dati della tastiera, all'indirizzo di I/O 0x60 per sistemi Linux, valore che rappresenterà proprio il codice ASCII del tasto premuto. In pratica emulo la richiesta asincrona del meccanismo a interrupt tramite delle richieste in polling a basso livello, bypassando i limiti di sicurezza imposti dal kernel nello user space. Vi farò sapere come andrà a finire. Intanto, in parallelo provo a sviluppare questo keylogger come modulo del kernel. Nel kernel space, ovviamente, potrò usare quegli header senza problemi Very Happy
Torna in alto Andare in basso
http://blacklight.gotdns.org
 
[C] Problemi con request_irq
Torna in alto 
Pagina 1 di 1

Permessi in questa sezione del forum:Non puoi rispondere agli argomenti in questo forum.
Xhack :: Programmazione :: C/C++-
Vai verso: