Pointer Redirecting
Tip
AWS हैकिंग सीखें और अभ्यास करें:
HackTricks Training AWS Red Team Expert (ARTE)
GCP हैकिंग सीखें और अभ्यास करें:HackTricks Training GCP Red Team Expert (GRTE)
Azure हैकिंग सीखें और अभ्यास करें:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks का समर्थन करें
- सदस्यता योजनाओं की जांच करें!
- हमारे 💬 Discord समूह या टेलीग्राम समूह में शामिल हों या हमें Twitter 🐦 @hacktricks_live** पर फॉलो करें।**
- हैकिंग ट्रिक्स साझा करें और HackTricks और HackTricks Cloud गिटहब रिपोजिटरी में PRs सबमिट करें।
String pointers
यदि किसी function call में stack पर स्थित किसी string के address का उपयोग होने वाला है, तो buffer overflow का दुरुपयोग करके इस address को overwrite कर के binary के अंदर किसी दूसरे string के address को रखना संभव है।
उदाहरण के लिए, अगर एक system function call किसी string के address का उपयोग करके command execute करने वाला है, तो attacker stack में किसी अलग string का address रख सकता है, export PATH=.:$PATH चला सकता है और current directory में एक script बना सकता है जिसका नाम नए string के पहले अक्षर के जैसा होगा — क्योंकि यह binary द्वारा execute हो जाएगा।
In real targets, repointing a stack string pointer is usually more interesting than just changing the printed text:
- Redirect a later
system/popen/execl*argument to an existing"/bin/sh"or attacker-controlled command string already present in memory. - Redirect a later read sink such as
puts("%s", ptr)orwrite(fd, ptr, len)to leak stack, heap or binary data. - Redirect a later write sink such as
strcpy(dst, ...),memcpy(dst, src, len), or a structure field assignment throughptr->field = valueto turn the stack overflow into a second-stage arbitrary write.
Audit करते समय, उन stack locals को प्राथमिकता दें जैसे char *cmd, char *path, char *buf, FILE *fp, या pointers inside temporary request/response structs जो overflow के बाद परंतु function के return करने से पहले उपयोग किए जाते हैं। यह विशेष रूप से तब उपयोगी है जब overflow सुरक्षित रूप से saved return address तक नहीं पहुँच सकता — जैसे canary होने के कारण या क्योंकि निकट के किसी pointer का भ्रष्ट होना ही काफी हो।
यदि corruption एक partial overwrite तक सीमित है (उदाहरण के लिए क्योंकि बग एक 0x00 जोड़ देता है), तो pointer को redirect करने का प्रयास करें:
- उसी stack frame में मौजूद नज़दीकी string
- किसी दूसरे object को उसी module / non-PIE image में
- एक controlled region जिसकी high bytes अपरिवर्तित रहें
For the related ASLR-oriented case where a trailing NUL modifies an existing stack pointer instead of a dedicated local variable, check Ret2ret & Reo2pop.
You can find an example of this in:
- https://github.com/florianhofhammer/stack-buffer-overflow-internship/blob/master/ASLR%20Smack%20and%20Laugh%20reference%20-%20Tilo%20Mueller/strptr.c
- https://guyinatuxedo.github.io/04-bof_variable/tw17_justdoit/index.html
- 32bit, stack में flags string के address को बदलें ताकि यह
putsद्वारा printed हो
Function pointers
Same as string pointer but applying to functions, if the stack contains the address of a function that will be called, it’s possible to change it (e.g. to call system).
उपयोगी targets केवल explicit callback variables जैसे void (*fp)() ही नहीं होते। व्यवहार में, तलाशें:
- बाद में helper functions को पास किए जाने वाले local structs में store किए गए Callbacks
- error paths पर invoke होने वाले Destructor / cleanup handlers
- stack में copy किए गए Parser dispatch tables या state-machine handlers
- बाद में indirect call के माध्यम से dispatch करने वाले Local structs / objects
In modern exploitation, pointer redirection is often the last primitive available before touching the canary. एक 2024 की exploitation writeup (CVE-2024-20017) सामान्य पैटर्न दिखाती है: overflow stack canary से पहले कई local variables तक पहुँचता है, attacker एक stack pointer plus its associated length/value को corrupt करता है, और उस pointer के माध्यम से बाद में होने वाला assignment बिना corrupted frame से return किए एक arbitrary write बन जाता है।
Pointer corruption to second-stage primitives
- एक local buffer को overflow करें और किसी pointer के साथ उससे जुड़ा कोई length / integer / index corrupt करें।
- फ़ंक्शन के post-overflow dereference करने का इंतज़ार करें, जैसे
ptr->len = x,memcpy(ptr, src, n)या*ptr = value। - इसके परिणामस्वरूप प्राप्त write-what-where का उपयोग करके GOT slot, callback, config pointer या किसी अन्य indirect callsite को overwrite करें।
यह विकल्प तब अच्छा है जब:
- बग canary पर रुक जाता है
- function pointer स्वयं सीधे पहुँच योग्य न हो
- एक 4‑byte या 8‑byte data write तुरंत control-flow hijack के मुकाबले प्राप्त करना आसान हो
यदि corrupted pointer बाद में logging, printing, या network send helpers को पास किया जाता है, तो यही विचार read primitives के लिए भी काम करता है।
Modern AArch64 note: PAC / BTI
वर्तमान AArch64 targets पर, एक क्लासिक saved return address overwrite असफल हो सकता है क्योंकि epilogue x30 को PAC के साथ authenticate करता है। ऐसे मामलों में, corrupted local function pointers या callback pointers जैसे non-return hijacks अधिक आकर्षक हो जाते हैं।
हालाँकि, यदि BTI enabled है, तो overwritten indirect-call target को अभी भी एक valid landing pad पर पहुँचना चाहिए (आम तौर पर एक function entry जिसमें bti c हो, या PAC-enabled code में prologue जो paciasp/pacibsp से शुरू हो)। इसलिए, AArch64 पर stack function pointer redirect करते समय प्राथमिकता दें:
- mid-function gadgets के बजाय वास्तविक function entries
- उन targets को जिनका prologue पहले से BTI को satisfy करता हो
- उन targets को जहाँ indirect-call pointer का उपयोग से पहले अतिरिक्त रूप से authenticate न किया जाता हो
For a related AArch64 stack-overflow context, check ret2win-arm64.
You can find an example in:
References
- https://github.com/florianhofhammer/stack-buffer-overflow-internship/blob/master/NOTES.md#pointer-redirecting
- https://blog.coffinsec.com/0day/2024/08/30/exploiting-CVE-2024-20017-four-different-ways.html
- https://developer.arm.com/community/arm-community-blogs/b/architectures-and-processors-blog/posts/enabling-pac-and-bti-on-aarch64
Tip
AWS हैकिंग सीखें और अभ्यास करें:
HackTricks Training AWS Red Team Expert (ARTE)
GCP हैकिंग सीखें और अभ्यास करें:HackTricks Training GCP Red Team Expert (GRTE)
Azure हैकिंग सीखें और अभ्यास करें:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks का समर्थन करें
- सदस्यता योजनाओं की जांच करें!
- हमारे 💬 Discord समूह या टेलीग्राम समूह में शामिल हों या हमें Twitter 🐦 @hacktricks_live** पर फॉलो करें।**
- हैकिंग ट्रिक्स साझा करें और HackTricks और HackTricks Cloud गिटहब रिपोजिटरी में PRs सबमिट करें।


