mirror of
https://github.com/HackTricks-wiki/hacktricks.git
synced 2025-10-10 18:36:50 +00:00
Translated ['src/binary-exploitation/libc-heap/use-after-free/first-fit.
This commit is contained in:
parent
c4809e1786
commit
471b6b8050
@ -44,7 +44,7 @@ d = malloc(20); // a
|
||||
---
|
||||
### 🔥 आधुनिक glibc विचार (tcache ≥ 2.26)
|
||||
|
||||
glibc 2.26 से हर थ्रेड अपनी **tcache** रखता है जिसे *unsorted bin* से *पहले* क्वेरी किया जाता है। इसलिए एक first-fit परिदृश्य **तब ही प्राप्त होगा यदि**:
|
||||
glibc 2.26 से हर थ्रेड अपनी **tcache** रखता है जिसे *unsorted bin* से *पहले* क्वेरी किया जाता है। इसलिए एक first-fit परिदृश्य **केवल तब** प्राप्त होगा यदि:
|
||||
|
||||
1. अनुरोधित आकार **`tcache_max`** (डिफ़ॉल्ट रूप से 64-बिट पर 0x420) से **बड़ा है**, *या*
|
||||
2. संबंधित tcache बिन **पहले से ही भरा हुआ है या मैन्युअल रूप से खाली किया गया है** (7 तत्वों को आवंटित करके और उन्हें उपयोग में रखकर)।
|
||||
@ -92,38 +92,36 @@ fwrite(C2, 1, 0x10, stdout); // prints Xs
|
||||
```
|
||||
Exploitation recipe (common in recent CTFs):
|
||||
|
||||
1. **Drain** the tcache for the target size.
|
||||
2. **Free** a chunk so it lands in the unsorted bin.
|
||||
3. **Allocate** a slightly smaller size – the allocator splits the unsorted chunk.
|
||||
4. **Allocate** again – the leftover part overlaps with an existing in-use chunk → UAF.
|
||||
5. Overwrite sensitive fields (function pointers, FILE vtable, etc.)
|
||||
1. **टारगेट आकार** के लिए tcache को **ड्रेन** करें।
|
||||
2. एक **चंक** को **फ्री** करें ताकि यह अनसॉर्टेड बिन में जाए।
|
||||
3. एक थोड़ा छोटा आकार **अलॉट** करें - अल्लोकेटर अनसॉर्टेड चंक को विभाजित करता है।
|
||||
4. फिर से **अलॉट** करें - बचे हुए भाग का एक मौजूदा उपयोग में चंक के साथ ओवरलैप होता है → UAF।
|
||||
5. संवेदनशील फ़ील्ड्स (फंक्शन पॉइंटर्स, FILE vtable, आदि) को ओवरराइट करें।
|
||||
|
||||
A practical application can be found in the 2024 HITCON Quals *Setjmp* challenge where this exact primitive is used to pivot from a UAF to full control of `__free_hook`.{{#ref}}
|
||||
../../../../references/2024_setjmp_firstfit.md
|
||||
{{#endref}}
|
||||
एक व्यावहारिक अनुप्रयोग 2024 HITCON Quals *Setjmp* चुनौती में पाया जा सकता है जहाँ इस सटीक प्राइमिटिव का उपयोग UAF से `__free_hook` के पूर्ण नियंत्रण में जाने के लिए किया जाता है।
|
||||
|
||||
---
|
||||
### 🛡️ Mitigations & Hardening
|
||||
|
||||
* **Safe-linking (glibc ≥ 2.32)** केवल singly-linked *tcache*/**fastbin** सूचियों की सुरक्षा करता है। असंरचित/छोटे/बड़े बिन अभी भी कच्चे पॉइंटर्स को संग्रहीत करते हैं, इसलिए पहले-फिट आधारित ओवरलैप तब भी संभव हैं यदि आप heap leak प्राप्त कर सकते हैं।
|
||||
* **Heap pointer encryption & MTE** (ARM64) अभी तक x86-64 glibc को प्रभावित नहीं करते हैं, लेकिन वितरण हार्डनिंग फ्लैग जैसे `GLIBC_TUNABLES=glibc.malloc.check=3` असंगत मेटाडेटा पर abort करेंगे और naïve PoCs को तोड़ सकते हैं।
|
||||
* **Filling tcache on free** (2024 में glibc 2.41 के लिए प्रस्तावित) असंरचित उपयोग को और कम करेगा; सामान्य exploits विकसित करते समय भविष्य के रिलीज़ की निगरानी करें।
|
||||
* **सेफ-लिंकिंग (glibc ≥ 2.32)** केवल सिंगली-लिंक्ड *tcache*/**fastbin** सूचियों की रक्षा करता है। अनसॉर्टेड/छोटे/बड़े बिन अभी भी कच्चे पॉइंटर्स को स्टोर करते हैं, इसलिए पहले-फिट आधारित ओवरलैप तब भी संभव हैं यदि आप एक हीप लीक प्राप्त कर सकते हैं।
|
||||
* **हीप पॉइंटर एन्क्रिप्शन & MTE** (ARM64) अभी तक x86-64 glibc को प्रभावित नहीं करते हैं, लेकिन वितरण हार्डनिंग फ्लैग जैसे `GLIBC_TUNABLES=glibc.malloc.check=3` असंगत मेटाडेटा पर abort करेंगे और सरल PoCs को तोड़ सकते हैं।
|
||||
* **फ्री पर tcache भरना** (2024 में glibc 2.41 के लिए प्रस्तावित) अनसॉर्टेड उपयोग को और कम करेगा; सामान्य एक्सप्लॉइट विकसित करते समय भविष्य के रिलीज़ की निगरानी करें।
|
||||
|
||||
---
|
||||
## Other References & Examples
|
||||
|
||||
- [**https://heap-exploitation.dhavalkapil.com/attacks/first_fit**](https://heap-exploitation.dhavalkapil.com/attacks/first_fit)
|
||||
- [**https://8ksec.io/arm64-reversing-and-exploitation-part-2-use-after-free/**](https://8ksec.io/arm64-reversing-and-exploitation-part-2-use-after-free/)
|
||||
- ARM64. Use after free: Generate an user object, free it, generate an object that gets the freed chunk and allow to write to it, **overwriting the position of user->password** from the previous one. Reuse the user to **bypass the password check**
|
||||
- ARM64. Use after free: एक उपयोगकर्ता ऑब्जेक्ट उत्पन्न करें, इसे फ्री करें, एक ऑब्जेक्ट उत्पन्न करें जो फ्री किए गए चंक को प्राप्त करता है और इसे लिखने की अनुमति देता है, **पिछले वाले से user->password की स्थिति को ओवरराइट करना**। उपयोगकर्ता को फिर से उपयोग करें ताकि **पासवर्ड चेक को बायपास** किया जा सके।
|
||||
- [**https://ctf-wiki.mahaloz.re/pwn/linux/glibc-heap/use_after_free/#example**](https://ctf-wiki.mahaloz.re/pwn/linux/glibc-heap/use_after_free/#example)
|
||||
- The program allows to create notes. A note will have the note info in a malloc(8) (with a pointer to a function that could be called) and a pointer to another malloc(<size>) with the contents of the note.
|
||||
- The attack would be to create 2 notes (note0 and note1) with bigger malloc contents than the note info size and then free them so they get into the fast bin (or tcache).
|
||||
- Then, create another note (note2) with content size 8. The content is going to be in note1 as the chunk is going to be reused, were we could modify the function pointer to point to the win function and then Use-After-Free the note1 to call the new function pointer.
|
||||
- प्रोग्राम नोट्स बनाने की अनुमति देता है। एक नोट में नोट की जानकारी एक malloc(8) में होगी (जिसमें एक फ़ंक्शन का पॉइंटर होगा जिसे कॉल किया जा सकता है) और एक अन्य malloc(<size>) का पॉइंटर होगा जिसमें नोट की सामग्री होगी।
|
||||
- हमला 2 नोट्स (note0 और note1) बनाने का होगा जिनकी malloc सामग्री नोट की जानकारी के आकार से बड़ी होगी और फिर उन्हें फ्री करें ताकि वे फास्ट बिन (या tcache) में जाएं।
|
||||
- फिर, एक और नोट (note2) बनाएं जिसकी सामग्री का आकार 8 हो। सामग्री note1 में होगी क्योंकि चंक को फिर से उपयोग किया जाएगा, जहाँ हम फ़ंक्शन पॉइंटर को win फ़ंक्शन की ओर इंगित करने के लिए संशोधित कर सकते हैं और फिर नोट1 को Use-After-Free करके नए फ़ंक्शन पॉइंटर को कॉल कर सकते हैं।
|
||||
- [**https://guyinatuxedo.github.io/26-heap_grooming/pico_areyouroot/index.html**](https://guyinatuxedo.github.io/26-heap_grooming/pico_areyouroot/index.html)
|
||||
- It's possible to alloc some memory, write the desired value, free it, realloc it and as the previous data is still there, it will treated according the new expected struct in the chunk making possible to set the value ot get the flag.
|
||||
- कुछ मेमोरी आवंटित करना, वांछित मान लिखना, इसे फ्री करना, फिर से आवंटित करना संभव है और चूंकि पिछले डेटा अभी भी वहां है, इसे चंक में नए अपेक्षित संरचना के अनुसार माना जाएगा जिससे मान सेट करना या फ्लैग प्राप्त करना संभव हो जाएगा।
|
||||
- [**https://guyinatuxedo.github.io/26-heap_grooming/swamp19_heapgolf/index.html**](https://guyinatuxedo.github.io/26-heap_grooming/swamp19_heapgolf/index.html)
|
||||
- In this case it's needed to write 4 inside an specific chunk which is the first one being allocated (even after force freeing all of them). On each new allocated chunk it's number in the array index is stored. Then, allocate 4 chunks (+ the initialy allocated), the last one will have 4 inside of it, free them and force the reallocation of the first one, which will use the last chunk freed which is the one with 4 inside of it.
|
||||
- 2024 HITCON Quals Setjmp write-up (Quarkslab) – practical first-fit / unsorted-split overlap attack: <https://ctftime.org/writeup/39355>
|
||||
- Angstrom CTF 2024 *heapify* write-up – abusing unsorted-bin splitting to leak libc and gain overlap: <https://hackmd.io/@aneii11/H1S2snV40>
|
||||
- इस मामले में एक विशिष्ट चंक के अंदर 4 लिखना आवश्यक है जो पहले आवंटित किया गया है (यहां तक कि सभी को बलपूर्वक फ्री करने के बाद भी)। प्रत्येक नए आवंटित चंक में इसका नंबर एरे इंडेक्स में स्टोर किया जाता है। फिर, 4 चंक्स (+ प्रारंभ में आवंटित) आवंटित करें, अंतिम में 4 होगा, उन्हें फ्री करें और पहले वाले के पुनः आवंटन को बल दें, जो अंतिम फ्री किए गए चंक का उपयोग करेगा जिसमें 4 होगा।
|
||||
- 2024 HITCON Quals Setjmp write-up (Quarkslab) – व्यावहारिक पहले-फिट / अनसॉर्टेड-स्प्लिट ओवरलैप हमला: <https://ctftime.org/writeup/39355>
|
||||
- Angstrom CTF 2024 *heapify* write-up – अनसॉर्टेड-बिन विभाजन का दुरुपयोग करके libc लीक करना और ओवरलैप प्राप्त करना: <https://hackmd.io/@aneii11/H1S2snV40>
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user