완료됨
ROPgadget 실행질문입니다

ROPgadget을 이용하여

// Compile: gcc -o rtl rtl.c -fno-PIE -no-pie
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

const char* binsh = "/bin/sh";

int main() {
char buf[0x30];
setvbuf(stdin, 0, _IONBF, 0);
setvbuf(stdout, 0, _IONBF, 0);

// Add system function to plt's entry
system("echo 'system@plt'");

// Leak canary
printf("[1] Leak Canary\n");
printf("Buf: ");
read(0, buf, 0x100);
printf("Buf: %s\n", buf);

// Overwrite return address
printf("[2] Overwrite return address\n");
printf("Buf: ");
read(0, buf, 0x100);
return 0;
}

위와 같은 코드의 pop rdi 가젯을 얻기 위하여 아래와 같은 명령어를 쳤으나 답이 이상합니다.

ROPgadget --binary ./rtl --re "pop rdi
Gadgets information========================================

Unique gadgets found: 0
Unique gadgets found: 0

아무것도 안 나오니 코드가 잡히긴하나 싶어서 --re 옵션 빼고 동작.

ROPgadget --binary ./rtl
ROPgadget --binary ./rtl
Gadgets information=========================================
============================================================t
0x000000000040111c : add byte ptr [rax], al ; add byte ptr [rax], al ; endbr64 ; ret
0x0000000000401036 : add byte ptr [rax], al ; add dl, dh ; jmp 0x401020
0x00000000004011ba : add byte ptr [rax], al ; add dword ptr [rbp - 0x3d], ebx ; nop ; ret
0x000000000040111e : add byte ptr [rax], al ; endbr64 ; ret
0x000000000040100d : add byte ptr [rax], al ; test rax, rax ; je 0x401016 ; call rax
0x00000000004011bb : add byte ptr [rcx], al ; pop rbp ; ret
0x00000000004011b9 : add byte ptr cs:[rax], al ; add dword ptr [rbp - 0x3d], ebx ; nop ; ret
0x000000000040114a : add dil, dil ; loopne 0x4011b5 ; nop ; ret
0x0000000000401038 : add dl, dh ; jmp 0x401020
0x00000000004011bc : add dword ptr [rbp - 0x3d], ebx ; nop ; ret
0x00000000004011b7 : add eax, 0x2ebb ; add dword ptr [rbp - 0x3d], ebx ; nop ; ret
0x0000000000401085 : add eax, 0xf2000000 ; jmp 0x401020
0x00000000004012be : add eax, 0xfffddce8 ; dec ecx ; ret
0x0000000000401017 : add esp, 8 ; ret
0x0000000000401016 : add rsp, 8 ; ret
0x000000000040103e : call qword ptr [rax - 0x5e1f00d]
0x0000000000401014 : call rax
0x00000000004011d3 : cli ; jmp 0x401160
0x0000000000401123 : cli ; ret
0x00000000004012cb : cli ; sub rsp, 8 ; add rsp, 8 ; ret
0x00000000004012c3 : dec ecx ; ret
0x00000000004011d0 : endbr64 ; jmp 0x401160
0x0000000000401120 : endbr64 ; ret
0x0000000000401012 : je 0x401016 ; call rax
0x0000000000401145 : je 0x401150 ; mov edi, 0x404060 ; jmp rax
0x0000000000401187 : je 0x401190 ; mov edi, 0x404060 ; jmp rax
0x000000000040103a : jmp 0x401020
0x00000000004011d4 : jmp 0x401160
0x000000000040100b : jmp 0x4840103f
0x000000000040114c : jmp rax
0x00000000004012c4 : leave ; ret
0x000000000040114d : loopne 0x4011b5 ; nop ; ret
0x00000000004011b6 : mov byte ptr [rip + 0x2ebb], 1 ; pop rbp ; ret
0x00000000004011b8 : mov ebx, 0x100002e ; pop rbp ; ret
0x0000000000401147 : mov edi, 0x404060 ; jmp rax
0x000000000040114f : nop ; ret
0x00000000004011cc : nop dword ptr [rax] ; endbr64 ; jmp 0x401160
0x0000000000401146 : or dword ptr [rdi + 0x404060], edi ; jmp rax
0x00000000004011bd : pop rbp ; ret
0x000000000040101a : ret
0x0000000000401011 : sal byte ptr [rdx + rax - 1], 0xd0 ; add rsp, 8 ; ret
0x000000000040105b : sar edi, 0xff ; call qword ptr [rax - 0x5e1f00d]
0x00000000004012cd : sub esp, 8 ; add rsp, 8 ; ret
0x00000000004012cc : sub rsp, 8 ; add rsp, 8 ; ret
0x0000000000401010 : test eax, eax ; je 0x401016 ; call rax
0x0000000000401143 : test eax, eax ; je 0x401150 ; mov edi, 0x404060 ; jmp rax
0x0000000000401185 : test eax, eax ; je 0x401190 ; mov edi, 0x404060 ; jmp rax
0x000000000040100f : test rax, rax ; je 0x401016 ; call rax

코드도 잘 지켜서 한 것 같은데 ROP 가젯이 왜 안 되는지 모르겠습니다.
작성했고 컴파일도 그대로 했는데 pop rdi가 나오질 않습니다.

하다못해 파이썬 폰툴로 exploit을 하려고 find_gadget(['pip rdi'])[0] 으로해도 None type이 나옵니다.

#시스템_해킹 #공격기법 #rtl #return_to_library
작성자 정보
더 깊이 있는 답변이 필요할 때
드림핵 팀과 멘토에게 직접 문의해 보세요!
답변 1
avatar
wyv3rn
무플 방지 위원회장

없을 수가 없는 가젯인데...
종종 그런 분들이 보이네요.

다른 환경에서 다시 컴파일 해보시겠어요

2023.04.02. 09:12