Nytro Posted October 31, 2011 Report Posted October 31, 2011 Understanding the Low Fragmentation HeaBlackhat USA 2010Chris ValasekX-Force Researchercvalasek . gmail.com@nudehaberdasherTable of ContentsIntroduction................................................................................................................................................ 4Overview................................................................................................................................................. 4Prior Works ............................................................................................................................................. 5Prerequisites ........................................................................................................................................... 6Terminology............................................................................................................................................ 6Notes ...................................................................................................................................................... 7Data Structures ........................................................................................................................................... 7_HEAP ..................................................................................................................................................... 7_HEAP_LIST_LOOKUP.............................................................................................................................. 9_LFH_HEAP ........................................................................................................................................... 10_LFH_BLOCK_ZONE............................................................................................................................... 11_HEAP_LOCAL_DATA ............................................................................................................................ 11_HEAP_LOCAL_SEGMENT_INFO ........................................................................................................... 12_HEAP_SUBSEGMENT........................................................................................................................... 12_HEAP_USERDATA_HEADER ................................................................................................................. 13_INTERLOCK_SEQ.................................................................................................................................. 14_HEAP_ENTRY....................................................................................................................................... 15Overview............................................................................................................................................... 16Architecture.............................................................................................................................................. 17FreeLists ................................................................................................................................................ 17Algorithms ................................................................................................................................................ 20Allocation.............................................................................................................................................. 20Back-end Allocation .............................................................................................................................. 21RtlpAllocateHeap .............................................................................................................................. 21Overview........................................................................................................................................... 27Front-end Allocation ............................................................................................................................. 28RtlpLowFragHeapAllocFromContext ................................................................................................. 28Overview........................................................................................................................................... 363Example ............................................................................................................................................ 37Freeing .................................................................................................................................................. 40Back-end Freeing .............................................................................................................................. 41RtlpFreeHeap .................................................................................................................................... 41Overview........................................................................................................................................... 47Front-end Freeing ................................................................................................................................. 48RtlpLowFragHeapFree....................................................................................................................... 48Overview........................................................................................................................................... 51Example ............................................................................................................................................ 52Security Mechanisms ................................................................................................................................ 55Heap Randomization............................................................................................................................. 55Comments......................................................................................................................................... 56Header Encoding/Decoding .................................................................................................................. 56Comments......................................................................................................................................... 57Death of bitmap flipping ....................................................................................................................... 58Safe Linking........................................................................................................................................... 59Comments......................................................................................................................................... 59Tactics ....................................................................................................................................................... 60Heap Determinism................................................................................................................................ 60Activating the LFH ............................................................................................................................. 60Defragmentation............................................................................................................................... 61Adjacent Data ................................................................................................................................... 62Seeding Data ..................................................................................................................................... 63Exploitation........................................................................................................................................... 67Ben Hawkes #1.................................................................................................................................. 67FreeEntryOffset Overwrite................................................................................................................ 71Observations......................................................................................................................................... 79SubSegment Overwrite ..................................................................................................................... 79Example ............................................................................................................................................ 83Issues ................................................................................................................................................ 83Conclusion ................................................................................................................................................ 85Bibliography.............................................................................................................................................. 86IntroductionOver the years, Windows heap exploitation has continued to increase in difficulty due to the addition of exploitation counter measures along with the implementation of more complex algorithms and data structures. Due to these trends and the scarcity of comprehensive heap knowledge within the community, reliable exploitation has severely declined. Maintaining a complete understanding of the inner workings of a heap manager can be the difference between unpredictable failure and precise exploitation. The Low Fragmentation heap has become the default front-end heap manager for the Windows operating system since the introduction of Windows Vista. This new front-end manager brought with it a different set of data structures and algorithms that replaced the Lookaside List. Thesystem has also changed the way back-end memory management works as well. All of this material must be reviewed to understand the repercussions of allocating and freeing memorywithin an application on Windows 7.The main goal of this paper is to familiarize the reader with the newly created logic and data structures associated with the Low Fragmentation heap. First, a clear and concise foundation will be provided by explaining the new data structures and their coupled purpose within the heap manager. Then detailed explanations concerning the underlying algorithms that manipulate those data structures will be discussed. Finally, some newly devised exploitation techniques will be unveiled providing practical applications from this new found knowledge. Download:http://illmatics.com/Understanding_the_LFH.pdf Quote