2017/12/13 - [SYSTEM HACKING/정리자료] - [ROP 문제]2013 Pico ctf rop-1
2017/12/13 - [SYSTEM HACKING/정리자료] - [ROP 문제]2013 Pico ctf rop-2
2017/12/18 - [SYSTEM HACKING/정리자료] - [ROP 문제]2013 Pico ctf rop-3
저번에 이어서 rop-4를 풀어보겠다.
이번 문제는 저번문제에 비해서 쉽다고 느껴졌다.
일단 소스코드를 봐보자.
#include <stdio.h> #include <unistd.h> #include <string.h> char exec_string[20]; void exec_the_string() { execlp(exec_string, exec_string, NULL); } void call_me_with_cafebabe(int cafebabe) { if (cafebabe == 0xcafebabe) { strcpy(exec_string, "/sh"); } } void call_me_with_two_args(int deadbeef, int cafebabe) { if (cafebabe == 0xcafebabe && deadbeef == 0xdeadbeef) { strcpy(exec_string, "/bin"); } } void vulnerable_function() { char buf[128]; read(STDIN_FILENO, buf, 512); } void be_nice_to_people() { // /bin/sh is usually symlinked to bash, which usually drops privs. Make // sure we don't drop privs if we exec bash, (ie if we call system()). gid_t gid = getegid(); setresgid(gid, gid, gid); } int main(int argc, char** argv) { exec_string[0] = '\0'; be_nice_to_people(); vulnerable_function(); }
코드를 보면 main함수에서 be_nice_to_people()함수 사용해 권한을 설정해준 후
vulnerable_function()함수의 read함수로 값을 받는데 여기서 버퍼오버플로우가 발생한다.
그 외에도 다른 많은 함수들이 정의되어 있는 것을 볼 수 있다.
그 중에서 exec_the_string함수를 이용해서 익스플로잇 코드를 짜보았다.
위에 c코드를 보면 exec_the_string()함수에서 execlp를 exec_string이라는 변수를 인자로 사용하는 것을 볼 수 있다.
(execlp는 PATH에 등록이 되어있는 모든 디렉터리의 프로그램을 실행하므로 프로그램 이름만 입력해도 실행이 된다.)
그래서 nm을 이용해서 exec_string변수의 주소값을 구해준 후 read함수를 통해서 exec_string변수에 sh이라는 값을 넣어주었다.
그 후 exec_the_string()함수를 실행해서 execlp함수가 실행되어 sh을 실행하게 된다.
'SYSTEM HACKING > 문제 풀이' 카테고리의 다른 글
Plaid CTF 2018 - EBP (0) | 2018.01.05 |
---|---|
Backdoor CTF-2015 forgot문제 (0) | 2018.01.04 |
[ROP 문제]2013 Pico ctf rop-3 (0) | 2017.12.18 |
[ROP 문제]2013 Pico ctf rop-2 (0) | 2017.12.13 |
[ROP 문제]2013 Pico ctf rop-1 (0) | 2017.12.13 |