Lista procesos de forma nativa con NtQuerySystemInformation

Iniciado por Juan, Mayo 29, 2013, 05:35:07 PM

Tema anterior - Siguiente tema

0 Miembros y 1 Visitante están viendo este tema.

Código: asm
; // Lista Procesos de forma nativa con la API  NtQuerySystemInformation
; // Escrito por Juan fary (mDrinky)
; // [email protected]
; // Ensamblador: Flat Assembler

include 'win32ax.inc'
entry start

.data
        Buffer                  dd 0
        len                     dd 0
        nBytes                  dd ?

.code
start:
        add [len],0x1000

        cinvoke realloc,[Buffer],[len]
        mov [Buffer],eax

        invoke NtQuerySystemInformation,5,[Buffer],[len],addr nBytes

        cmp eax,0xC0000004
        je start

        ListarProcesos:

        mov eax,[Buffer]
        mov eax,[eax+0x3C] ; Nombre del proceso
        ;mov eax,[eax+0x44]   ; ID del proceso

        test eax,eax
        je SiguienteProceso

        push eax
        invoke MessageBoxW,0,eax,0,0
        pop eax

        mov eax,[Buffer]   ; puntero a estructura
        mov eax,[eax]      ; Distancia que habria que recorrer hasta la siguiente estructura

        cmp eax,0          ; Si es 0 no hay mas estructuras
        je salir

        SiguienteProceso:

        mov eax,[Buffer]

        mov edx,eax    ; Puntero a estructura en EDX
        mov eax,[eax]  ; EAX =  NextEntryDelta
        add edx,eax    ; Sumamos la distancia de la siguiente estructura

        mov [Buffer],edx ; Siguiente Estructura

        jmp ListarProcesos

        salir:

        ret

section '.idata' data readable import

        library msvcrt,'msvcrt.dll',\
                NTDLL,'NTDLL.DLL',\
                USER32,'USER32.DLL'

        import msvcrt,\
               realloc,'realloc'

        import NTDLL,\
               NtQuerySystemInformation,'NtQuerySystemInformation'

        import USER32,\
               MessageBoxW,'MessageBoxW' 


Me costo crear el código ya que hay poca documentación y mucha de la que hay es erronea, asique tuve que debuguear la API en un proceso externo y ver finalmente como eran las estructuras y en que posición estaba el ID del proceso y el nombre.

un saludo!


Dejo la estructura Correcta, en C (El código de las estructuras no es mio lo saque de por ahí.)

Código: C
    typedef struct {
    USHORT Length;
    USHORT MaxLen;
    USHORT *Buffer;
    }UNICODE_STRING;

    struct process_info {
    ULONG NextEntryDelta;
    ULONG ThreadCount;
    ULONG Reserved1[6];
    LARGE_INTEGER CreateTime;
    LARGE_INTEGER UserTime;
    LARGE_INTEGER KernelTime;
    UNICODE_STRING ProcessName;
    ULONG BasePriority;
    ULONG ProcessId;
    };


un saludo!

HOLA!!!

Felicitaciones Lo LOGRASTE!

GRACIAS POR LEER!!!
"Algunos creen que soy un bot, puede que tengan razon"
"Como no se puede igualar a Dios, ya he decidido que hacer, ¡SUPERARLO!"
"La peor de las ignorancias es no saber corregirlas"

*Shadow Scouts Team*                                                No tienes permitido ver los links. Registrarse o Entrar a mi cuenta

Aquí está el código en VB6 por si a alguien le interesa ;D
No tienes permitido ver los links. Registrarse o Entrar a mi cuenta
I code for $$$.

(PGP ID 0xCC050E77)
ASM, C, C++, VB6... skilled [malware] developer

Gracias  mDrinky muy bonito código a estudiar un ratito  ;D