Likes Likes:  0
Resultaten 1 tot 2 van de 2
Geen
  1. #1
    Peter Huang
    Code Red Revisited and Stack-Based Exception Handler Frame Bug
    Gast
    n/a Berichten
    Berichten zijn liked



    Thread Starter

    Code Red Revisited and Stack-Based Exception Handler Frame Bug

    As I followed the trail described by Mr. Szor and Mr. Chien’s article
    (http://www.peterszor.com/blended.pdf), it became clear to me the following
    was the transfer point to the abused exception handler like Code Red. For a
    normal C/C++ function, it was OK to assume that sub-functions will not
    depend on the values of EBX, EDI, and ESI and will not abuse them. However,
    that assumption was proved wrong with the Code Red exploitation and should
    be corrected. One simple way is to save EBX and xor EBX out before it
    transfers the rein. A more panicky way is to save and xor out all the unused
    registers like EBX, EDI, and ESI for this function before it calls ECX as
    follows:

    NTDLL Sub_77F9250D called by KiUserExceptionDispatcher

    ..text:77F9250D mov edx, offset loc_77F8A896
    ..text:77F92512
    ..text:77F92512 loc_77F92512: ; CODE XREF:
    sub_77F8A88A+7j
    ..text:77F92512 push ebp
    ..text:77F92513 mov ebp, esp
    ..text:77F92515 push [ebp+arg_8]
    ..text:77F92518 push edx
    ..text:77F92519 push large dword ptr fs:0
    push ebx
    push edi
    push esi
    xor esi, esi
    xor edi, edi
    xor ebx, ebx
    ..text:77F92520 mov large fs:0, esp
    ..text:77F92527 push [ebp+arg_10]
    ..text:77F9252A push [ebp+arg_C]
    ..text:77F9252D push [ebp+arg_8]
    ..text:77F92530 push [ebp+arg_4]
    ..text:77F92533 mov ecx, [ebp+arg_14]
    ..text:77F92536 call ecx
    ..text:77F92538 mov esp, large fs:0
    pop esi
    pop edi
    pop ebx
    ..text:77F9253F pop large dword ptr fs:0
    ..text:77F92546 mov esp, ebp
    ..text:77F92548 pop ebp
    ..text:77F92549 retn 14h

    That is it. Two cracks (one boundary check bug and another normal (sometimes
    incomplete) assumption about C/C++ call) made the Code Red exploitation
    possible in real life.

    Peter Huang
    For more articles written by Peter Huang, please visit
    http://members.rogers.com/yinrong/articlelist.html



  2. #2
    Roland Postle
    Code Red Revisited and Stack-Based Exception Handler Frame Bug
    Gast
    n/a Berichten
    Berichten zijn liked



    Thread Starter

    Re: Code Red Revisited and Stack-Based Exception Handler Frame Bug

    On=20Tue,=2011=20Feb=202003=2016:11:15=20-0500,=20Peter=20Huang=20wrote:

    >As=20I=20followed=20the=20trail=20described=20by= 20Mr.=20Szor=20and=20Mr.=

    =20Chien=92s=20article
    >(http://www.peterszor.com/blended.pdf),=20it=20became=20clear=20to=20me=20=

    the=20following
    >was=20the=20transfer=20point=20to=20the=20abused= 20exception=20handler=20=

    like=20Code=20Red.=20For=20a
    >normal=20C/C++=20function,=20it=20was=20OK=20to=20assume=20th at=20sub-fun=

    ctions=20will=20not
    >depend=20on=20the=20values=20of=20EBX,=20EDI,=20a nd=20ESI=20and=20will=20=

    not=20abuse=20them.=20However,
    >that=20assumption=20was=20proved=20wrong=20with=2 0the=20Code=20Red=20expl=

    oitation=20and=20should
    >be=20corrected.=20One=20simple=20way=20is=20to=20 save=20EBX=20and=20xor=20=

    EBX=20out=20before=20it
    >transfers=20the=20rein.=20A=20more=20panicky=20wa y=20is=20to=20save=20and=

    =20xor=20out=20all=20the=20unused
    >registers=20like=20EBX,=20EDI,=20and=20ESI=20for= 20this=20function=20befo=

    re=20it=20calls=20ECX

    Apparently=20this=20is=20exactly=20what=20happens= 20now,=20except=20Micros=
    oft=20chose=20to
    nuke=20eax=20as=20well=20(see=20below).=20But=20it 's=20a=20bit=20misleadin=
    g=20to=20say=20this
    made=20the=20Code=20Red=20exploitation=20possible. =20There=20are=20a=20num=
    erous=20other
    ways=20to=20find=20your=20shellcode=20in=20memory= 20without=20relying=20on=
    =20having=20a
    register=20pointing=20directly=20at=20it,=20albeit =20some=20are=20more=20r=
    eliable=20than
    others.=20In=20this=20case=20I=20believe=20the=20s hellcode=20is=20some=20w=
    ay=20down=20the=20stack
    (?)=20in=20which=20case=20pointing=20the=20call=20 ecx=20at=20some=20code=20=
    like:

    retn=2010h

    and=20arranging=20for=20the=20retn=20to=20pop=20a= 20pointer=20to=20a=20

    mov=20eax,=20esp
    call=20eax

    would=20probably=20do=20the=20trick.

    You=20could=20run=20around=20all=20day=20making=20 sure=20registers=20didn'=
    t=20have=20values
    that=20were=20useful=20to=20attackers,=20but=20all =20you'd=20end=20up=20do=
    ing=20is
    introducing=20masses=20of=20overhead=20and=20makin g=20exploitation=20a=20b=
    it=20more
    challenging=20(and=20more=20satisfying).=20I=20hop e=20you're=20not=20reall=
    y=20suggesting
    that=20*every*=20function=20call=20should=20begin= 20with=20fresh=20registe=
    rs?=20It's=20just
    about=20justified=20in=20this=20case=20because=20e xception=20handlers=20ar=
    e=20one=20of=20the
    more=20common=20things=20that=20get=20overwritten.

    -=20Blazde

    From=20XP=20SP1=20ntdll.dll:

    ..text:77F79B4D=20_RtlpExecuteHandlerForUnwind@20= 20proc=20near=20;=20CODE=20=
    XREF:
    RtlUnwind(x,x,x,x)+BD=18p
    ..text:77F79B4D=20
    ..text:77F79B4D=20arg_0=20=20=20=20=20=20=20=20=20 =20=20=3D=20dword=20ptr=20=
    =204
    ..text:77F79B4D=20arg_4=20=20=20=20=20=20=20=20=20 =20=20=3D=20dword=20ptr=20=
    =208
    ..text:77F79B4D=20arg_8=20=20=20=20=20=20=20=20=20 =20=20=3D=20dword=20ptr=20=
    =200Ch
    ..text:77F79B4D=20arg_C=20=20=20=20=20=20=20=20=20 =20=20=3D=20dword=20ptr=20=
    =2010h
    ..text:77F79B4D=20arg_10=20=20=20=20=20=20=20=20=2 0=20=3D=20dword=20ptr=20=20=
    14h
    ..text:77F79B4D=20
    ..text:77F79B4D=20=20=20=20=20=20=20=20=20=20=20=2 0=20=20=20=20=20mov=20=20=
    =20=20=20edx,=20offset=20loc_77F79BDF
    ..text:77F79B52=20=20=20=20=20=20=20=20=20=20=20=2 0=20=20=20=20=20lea=20=20=
    =20=20=20ecx,=20[ecx]
    ..text:77F79B54=20
    ..text:77F79B54=20ExecuteHandler@20:=20=20=20=20=2 0=20=20=20=20=20=20=20=20=
    =20=20=20=20=20=20=20=20=20;=20CODE=20XREF:
    RtlpExecuteHandlerForException(x,x,x,x,x)+5=18j
    ..text:77F79B54=20=20=20=20=20=20=20=20=20=20=20=2 0=20=20=20=20=20push=20=20=
    =20=20ebx
    ..text:77F79B55=20=20=20=20=20=20=20=20=20=20=20=2 0=20=20=20=20=20push=20=20=
    =20=20esi
    ..text:77F79B56=20=20=20=20=20=20=20=20=20=20=20=2 0=20=20=20=20=20push=20=20=
    =20=20edi
    ..text:77F79B57=20=20=20=20=20=20=20=20=20=20=20=2 0=20=20=20=20=20xor=20=20=
    =20=20=20eax,=20eax
    ..text:77F79B59=20=20=20=20=20=20=20=20=20=20=20=2 0=20=20=20=20=20xor=20=20=
    =20=20=20ebx,=20ebx
    ..text:77F79B5B=20=20=20=20=20=20=20=20=20=20=20=2 0=20=20=20=20=20xor=20=20=
    =20=20=20esi,=20esi
    ..text:77F79B5D=20=20=20=20=20=20=20=20=20=20=20=2 0=20=20=20=20=20xor=20=20=
    =20=20=20edi,=20edi
    ..text:77F79B5F=20=20=20=20=20=20=20=20=20=20=20=2 0=20=20=20=20=20push=20=20=
    =20=20[esp+0Ch+arg_10]
    ..text:77F79B63=20=20=20=20=20=20=20=20=20=20=20=2 0=20=20=20=20=20push=20=20=
    =20=20[esp+10h+arg_C]
    ..text:77F79B67=20=20=20=20=20=20=20=20=20=20=20=2 0=20=20=20=20=20push=20=20=
    =20=20[esp+14h+arg_8]
    ..text:77F79B6B=20=20=20=20=20=20=20=20=20=20=20=2 0=20=20=20=20=20push=20=20=
    =20=20[esp+18h+arg_4]
    ..text:77F79B6F=20=20=20=20=20=20=20=20=20=20=20=2 0=20=20=20=20=20push=20=20=
    =20=20[esp+1Ch+arg_0]
    ..text:77F79B73=20=20=20=20=20=20=20=20=20=20=20=2 0=20=20=20=20=20call=20=20=
    =20=20ExecuteHandler2@20
    ..text:77F79B78=20=20=20=20=20=20=20=20=20=20=20=2 0=20=20=20=20=20pop=20=20=
    =20=20=20edi
    ..text:77F79B79=20=20=20=20=20=20=20=20=20=20=20=2 0=20=20=20=20=20pop=20=20=
    =20=20=20esi
    ..text:77F79B7A=20=20=20=20=20=20=20=20=20=20=20=2 0=20=20=20=20=20pop=20=20=
    =20=20=20ebx
    ..text:77F79B7B=20=20=20=20=20=20=20=20=20=20=20=2 0=20=20=20=20=20retn=20=20=
    =20=2014h
    ..text:77F79B7B=20_RtlpExecuteHandlerForUnwind@20= 20endp



Webhostingtalk.nl

Contact

  • Rokin 113-115
  • 1012 KP, Amsterdam
  • Nederland
  • Contact
© Copyright 2001-2026 Webhostingtalk.nl.
Web Statistics