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 |
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 |