hacking/pwnable

One-gadgets

2023. 5. 27. 21:56
목차
  1. One-gadgets of libc(/lib/x86_64-linux-gnu/libc-2.23.so)
  2. Find One Gadgets

One Gadget이란 해당 Gadget 하나만을 이용하여 Shell을 획득할 수 있는 Gadget이다.

  • One Gadget은 라이브러리 파일 내에서 "/bin/sh"를 실행하는 Gadget이다.
  • One Gadget을 사용하기 위해서 일부 조건이 만족해야 되는 경우도 있다.
  • ROP, RTL 기법을 사용할 때 해당 Gadget을 많이 사용한다.

One-gadgets of libc(/lib/x86_64-linux-gnu/libc-2.23.so)

다음과 같은 코드들이 One gadgets으로 사용될 수 있다.

  • do_system() 함수 내에서 __execve() 함수를 이용해 shell을 호출한다.
...
#endif
  if (pid == (pid_t) 0)
    {
      /* Child side.  */
      const char *new_argv[4];
      new_argv[0] = SHELL_NAME;
      new_argv[1] = "-c";
      new_argv[2] = line;
      new_argv[3] = NULL;
  
      /* Restore the signals.  */
      (void) __sigaction (SIGINT, &intr, (struct sigaction *) NULL);
      (void) __sigaction (SIGQUIT, &quit, (struct sigaction *) NULL);
      (void) __sigprocmask (SIG_SETMASK, &omask, (sigset_t *) NULL);
      INIT_LOCK ();
  
      /* Exec the shell.  */
      (void) __execve (SHELL_PATH, (char *const *) new_argv, __environ);
      _exit (127);
    }
  else if (pid < (pid_t) 0)
    /* The fork failed.  */
    status = -1;
  else
...
  • 다음 코드는 libc 라이브러리의 exec_comm_child() 함수 내에서 __execve() 함수를 이용하여 shell을 호출한다.
/* Function called by child process in exec_comm() */
static inline void
__attribute__ ((always_inline))
exec_comm_child (char *comm, int *fildes, int showerr, int noexec)
{
  const char *args[4] = { _PATH_BSHELL, "-c", comm, NULL };
  
  /* Execute the command, or just check syntax? */
  if (noexec)
    args[1] = "-nc";
  
...
 
  __close (fildes[0]);
  __execve (_PATH_BSHELL, (char *const *) args, __environ);
 
  /* Bad.  What now?  */
  abort ();
}

Find One Gadgets

다음과 같이 one_gadget 스크립트를 이용해 One Gadgets을 찾을 수 있다.

  • 다만 각각의 One Gadget은 제약조건이 있어, 해당 조건을 만족해야 shell을 획득할 수 있다.
lazenca0x0@ubuntu:~/Exploit/OneGadgets$ one_gadget /lib/x86_64-linux-gnu/libc-2.23.so
0x45216 execve("/bin/sh", rsp+0x30, environ)
constraints:
  rax == NULL
 
0x4526a execve("/bin/sh", rsp+0x30, environ)
constraints:
  [rsp+0x30] == NULL
 
0xf02a4 execve("/bin/sh", rsp+0x50, environ)
constraints:
  [rsp+0x50] == NULL
 
0xf1147 execve("/bin/sh", rsp+0x70, environ)
constraints:
  [rsp+0x70] == NULL
lazenca0x0@ubuntu:~/Exploit/OneGadgets$

'hacking > pwnable' 카테고리의 다른 글

Frame Pointer Overwrite(One-byte Overflow)  (0) 2023.05.28
Frame faking(Fake ebp)  (0) 2023.05.28
ROP(Return Oriented Programming)  (0) 2023.05.27
RTL(Return to Libc)  (0) 2023.05.27
Return to Shellcode  (0) 2023.05.27
  1. One-gadgets of libc(/lib/x86_64-linux-gnu/libc-2.23.so)
  2. Find One Gadgets
'hacking/pwnable' 카테고리의 다른 글
  • Frame Pointer Overwrite(One-byte Overflow)
  • Frame faking(Fake ebp)
  • ROP(Return Oriented Programming)
  • RTL(Return to Libc)
hogbal
hogbal
hogbal
hogbal
hogbal
  • 분류 전체보기 (53)
    • hacking (31)
      • pwnable (22)
      • web (7)
      • reversing (0)
      • 암호학 (1)
      • tools (1)
    • Wargame (14)
      • pwnable (7)
      • web (4)
      • reversing (3)
    • Deep learning (7)
      • 논문 (6)
      • RUP (1)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

  • 알림

인기 글

태그

  • RTL
  • base64
  • Stack
  • TOOL
  • deep learning
  • pwnable
  • rop
  • Web Hacking
  • CSP
  • YOLO

최근 댓글

최근 글

hELLO · Designed By 정상우.
hogbal
One-gadgets
상단으로

티스토리툴바

단축키

내 블로그

내 블로그 - 관리자 홈 전환
Q
Q
새 글 쓰기
W
W

블로그 게시글

글 수정 (권한 있는 경우)
E
E
댓글 영역으로 이동
C
C

모든 영역

이 페이지의 URL 복사
S
S
맨 위로 이동
T
T
티스토리 홈 이동
H
H
단축키 안내
Shift + /
⇧ + /

* 단축키는 한글/영문 대소문자로 이용 가능하며, 티스토리 기본 도메인에서만 동작합니다.