Wednesday, November 23, 2005

Porting PBPM from 9x to NT

This has been quite a nice project as i had to rewrite everything from scratch
and since BPM works (as we know) per thread i wanted it to handle all threads
seperated just like i had it done back then on 9x in icedump...

1. Problem there was no VMMCall _AllocateThreadDataSlot

which turned out to be quite a problem at first

later i found out that in the r0 TEB (which is located in PCR:0x124)

was a field that contains always 0 on all threads

mov eax,fs:[124h] ; -> TEB!
mov eax,[eax+4h]
or eax,eax
jnz memory_allocated

so i used that DWORD to store all snapshots...

2. after figuring that part out it also turned out that it wasn't as easy as i thought at first to hook
the necessary code deep enough.... hooking the point where the context gets restored (setthreadcontext)
was no problem at all, but finding a good point where i could hook the "snapshot" process was kinda tricky and this code changes heavily with each service pack and maybe even with security updates...

(i guess it was the main reason for me to never publish anything of it till today)

so i had 2 parts

the more "generic one" // where i hooked zwsetthreadcontext using the keservicedescriptortable

; SEH! stuff

mov ebx,keservicedescriptortable ; grab the fucking table
mov ebx,[ebx] ; pointer to real table
add ebx,020h*4h ; point to our really interesting
; context entry!
; service number 0x20
; -> setthreadcontext | SEH!
mov eax,[ebx] ; -> grab handler rva!
mov pOldCTXHandlerSEH,eax ; store the rva!
mov pOldCTXHandlerSEHP,ebx

mov [ebx],offset myXXsetcontextthreadseh ; install my handler!


and second the part where i hooked the snapshot process:

(therefore i disabled the supervisor bit for a short amount of time and written my hook directly into ntoskernel's code section... afterwards reenable the supervisor bit and exit)

mov ecx,cr0
mov edi,ecx
and ecx,0fffeffffh
mov cr0,ecx

pushad
mov esi,ntosbase
add esi,HARDC0DED
cmp word ptr [esi],0a5f3h
jne failed_at_signature

mov pOldKiUserHandlerP,esi

; save orig_byte_sequence
pushad
mov ecx,08h
lea edi,offset orig_bytes_buffer
db 0f3h, 0a4h ;repz movsb
mov al,068h
stosb ;store push
xchg esi,eax
stosd
mov al,0c3h
stosb
popad

lea eax,offset orig_bytes_buffer
mov my_fucking_destination,eax

xchg esi,edi
mov al,068h
stosb
lea eax,offset myXXkiuser
stosd
mov al,0c3h
stosb
popad

mov ecx,edi
mov cr0,ecx

failed_e:
popad
ret

failed_at_signature:
popad

mov ecx,edi
mov cr0,ecx

popad
ret

3. the hook itself

("kiuser" (snapshot) hook)

;Ä[MY HOOK]ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
myXXkiuser equ $
pushfd
pushad
mov eax,fs:[124h]
mov eax,[eax+4h]
or eax,eax
jz dont_fill_the_context

lea edi,dword ptr [esi+4]
mov esi,eax
mov ecx,06h
db 0f3h,0a5h ; repz movsd

Invoke DbgPrint, OFFSET life_sux

dont_fill_the_context:
popad
popfd

db 068h ; push
my_fucking_destination dd ?
ret
myXXkiuserend equ $
;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ

and the way bigger zwsetcontextthread hook
(btw. i find it pretty confusing to name the ring3 part setthreadcontext and the ring0 part zwsetCONTEXTthread, must be one of a naming genius ;) or someone just noticed bit too late like "doh, we mixed it, damn!")

;Ä[MY HOOK]ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
myXXsetcontextthreadseh equ $
pushfd
pushad

mov eax,[esp+028h] ; -> ctx storage buffer
cmp eax,010000000h
jae i_dont_trust_the_kernel

cmp dword ptr [eax+018h],0155h ; most of the time used!
je reset_now

cmp dword ptr [eax+018h],024FFh ; ... :> the evil one
jne i_dont_trust_the_kernel

reset_now:
; and dword ptr [eax+018h],0 ; reset -> dr7


mov eax,fs:[124h] ; -> TEB!
mov eax,[eax+4h]
or eax,eax
jnz memory_allocated

pushad
push 018h
push 4 ; NonPagedPool
iWin32 ExAllocatePool ; allocate buffer
; eax == pointer to allocated
; memory

or eax,eax
jnz proceed_
popad
jmp i_dont_trust_the_kernel

proceed_: mov dword ptr [esp+01ch],eax ; store it!
popad

memory_allocated: mov ebx,fs:[124h]
mov [ebx+4h],eax ; install buffer!

mov edi,eax
mov esi,[esp+028h] ; -> ctx storage!
add esi,04h
mov ecx,06h
mov edx,offset mdr0

grab_regs:
lodsd

push eax
push ecx
call convert
add edx,09h+4h
pop ecx
pop eax

and dword ptr [esi-4],0 ; -> kill it!
stosd ; save value in my buffer!
loop grab_regs

mov eax,fs:[124h] ; -> TEB!
push eax
mov edx,offset kteb_
call convert
pop eax

Invoke DbgPrint, OFFSET shit_happens

i_dont_trust_the_kernel:

popad
popfd
jmp dword ptr [pOldCTXHandlerSEH]
;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ

Comments:
[url=http://community.bsu.edu/members/buy+online+Viagra.aspx]discount Viagra overnight[/url]
[url=http://ceklansi.ru/index.php]знакомства литва[/url]
[url=http://ceklansi.ru/tegos-ru-znakomstva.php]тегос ру знакомства[/url]
[url=http://ceklansi.ru/olga-blyad.php]ольга блядь[/url]
[url=http://ceklansi.ru/odinokaya-zhenschina-zhelaet-poznakomitsya-onlayn.php]одинокая женщина желает познакомиться онлайн[/url]
[url=http://ceklansi.ru/blyadi-luganska.php]бляди луганска[/url]
[url=http://celuyou.ru/gde-snyat-molodye-prostitutku.php]где снять молодые проститутку[/url]
[url=http://celuyou.ru/chat-intimnyh-znakomstv.php]чат интимных знакомств[/url]
[url=http://celuyou.ru/avtozavodskaya-intim.php]автозаводская интим[/url]
[url=http://celuyou.ru/serpuhovsko-timiryazevskaya-prostitutki.php]серпуховско-тимирязевская проститутки[/url]
[url=http://celuyou.ru/znakomstva-bez.php]знакомства без[/url]
[url=http://deperovero.ru/poznakomlus-s-armyankoy.php]познакомлюсь с армянкой[/url]
[url=http://deperovero.ru/botanicheskiy-sad-intim.php]ботанический сад интим[/url]
[url=http://mx.deperovero.ru/ischu-devushku-dlya-seksa-molodye-let-iz-yaroslavlya.php]ищу девушку для секса молодые лет из ярославля[/url]
[url=http://mx.deperovero.ru/saund-trek-k-teleserialu-seks-v-bolshom-gorode-mr3.php]саунд-трек к телесериалу секс в большом городе мр3[/url][url=http://rp.deperovero.ru/index.php]знакомства love planeta[/url]
[url=http://rp.deperovero.ru/intim-krasnogvardeyskaya.php]интим красногвардейская[/url][url=http://ss.deperovero.ru/index.php]секс чаты знакомств москвы[/url]
[url=http://ss.deperovero.ru/serpuhovsko-timiryazevskaya-intim.php]серпуховско-тимирязевская интим[/url]
[url=http://tt.deperovero.ru/seks-znakomstvo-g-kazan.php]секс знакомство г казань[/url]
[url=http://tt.deperovero.ru/dosug-i-seks.php]досуг и секс[/url]
 
Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?