UAF 문제를 풀어보자
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | #include <fcntl.h> #include <iostream> #include <cstring> #include <cstdlib> #include <unistd.h> using namespace std; class Human{ private: virtual void give_shell(){ system("/bin/sh"); } protected: int age; string name; public: virtual void introduce(){ cout << "My name is " << name << endl; cout << "I am " << age << " years old" << endl; } }; class Man: public Human{ public: Man(string name, int age){ this->name = name; this->age = age; } virtual void introduce(){ Human::introduce(); cout << "I am a nice guy!" << endl; } }; class Woman: public Human{ public: Woman(string name, int age){ this->name = name; this->age = age; } virtual void introduce(){ Human::introduce(); cout << "I am a cute girl!" << endl; } }; int main(int argc, char* argv[]){ Human* m = new Man("Jack", 25); Human* w = new Woman("Jill", 21); size_t len; char* data; unsigned int op; while(1){ cout << "1. use\n2. after\n3. free\n"; cin >> op; switch(op){ case 1: m->introduce(); w->introduce(); break; case 2: len = atoi(argv[1]); data = new char[len]; read(open(argv[2], O_RDONLY), data, len); cout << "your data is allocated" << endl; break; case 3: delete m; delete w; break; default: break; } } return 0; } | cs |
man 클래스와 woman 클래스안에는
human 클래스를 상속받아 give_shell이 존재한다
여기서 UAF 취약점을 이용해 m,w를 지우고
입력을 받을 때 give_shell 주소를 넣고 1번을 눌러서 호출한다
먼저 give_shell을 주소는
ㅇㅇ 이렇다
case 1:
m->introduce();
w->introduce();
break;
여기 부분을 IDA로 보면
Add 8을 한다 add 8을 해주니깐 -8을 해주면 된다
0x401570에서 -8 하면 0x401568이다
끝 힘드네
'WARGAME > Pwnable.kr' 카테고리의 다른 글
pwnable.kr passcode (0) | 2016.03.29 |
---|---|
PWNABLE KR ascii_easy (0) | 2016.03.28 |
PWNABLE KR CMD1 (0) | 2016.02.09 |
PWNABLE KR lotto (0) | 2016.02.09 |
pwnable kr flag (0) | 2016.01.08 |